CAMEL-6441: ServiceSupport when exception during starting, then ensure clear flags to being stopped state.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0f1fc14f Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0f1fc14f Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0f1fc14f Branch: refs/heads/camel-2.10.x Commit: 0f1fc14fb0aee3c91d214217eb4673b66b1cf728 Parents: 224b675 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Jul 23 11:22:12 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Jul 23 11:25:00 2013 +0200 ---------------------------------------------------------------------- .../java/org/apache/camel/support/ServiceSupport.java | 10 ++++++++++ .../java/org/apache/camel/support/ServiceSupportTest.java | 7 +++++++ 2 files changed, 17 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/0f1fc14f/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java b/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java index fac814a..490ee00 100644 --- a/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java +++ b/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java @@ -72,6 +72,16 @@ public abstract class ServiceSupport implements StatefulService { stop(); } catch (Exception e2) { // Ignore exceptions as we want to show the original exception + } finally { + // ensure flags get reset to stopped as we failed during starting + stopping.set(false); + stopped.set(true); + starting.set(false); + started.set(false); + suspending.set(false); + suspended.set(false); + shutdown.set(false); + shuttingdown.set(false); } throw e; } http://git-wip-us.apache.org/repos/asf/camel/blob/0f1fc14f/camel-core/src/test/java/org/apache/camel/support/ServiceSupportTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/support/ServiceSupportTest.java b/camel-core/src/test/java/org/apache/camel/support/ServiceSupportTest.java index 2485bc5..a739f9c 100644 --- a/camel-core/src/test/java/org/apache/camel/support/ServiceSupportTest.java +++ b/camel-core/src/test/java/org/apache/camel/support/ServiceSupportTest.java @@ -93,6 +93,8 @@ public class ServiceSupportTest extends TestSupport { public void testExceptionOnStart() throws Exception { ServiceSupportTestExOnStart service = new ServiceSupportTestExOnStart(); + // forced not being stopped at start + assertEquals(false, service.isStopped()); try { service.start(); fail("RuntimeException expected"); @@ -106,6 +108,11 @@ public class ServiceSupportTest extends TestSupport { public static class ServiceSupportTestExOnStart extends ServiceSupport { + public ServiceSupportTestExOnStart() { + // just for testing force it to not be stopped + stopped.set(false); + } + @Override protected void doStart() throws Exception { throw new RuntimeException("This service throws an exception when starting");