Repository: camel Updated Branches: refs/heads/master b7eb85123 -> fec3c24e6
isRunAllowed should return false if the service has not been initialized/startet at all. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/76c83526 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/76c83526 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/76c83526 Branch: refs/heads/master Commit: 76c83526135b539c295ad358dc13d5653ad69e9f Parents: b7eb851 Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Nov 30 14:54:40 2014 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Nov 30 14:54:40 2014 +0100 ---------------------------------------------------------------------- .../apache/camel/support/ServiceSupport.java | 5 +++++ .../camel/support/ServiceSupportTest.java | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/76c83526/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 afba302..a1cf081 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 @@ -234,6 +234,11 @@ public abstract class ServiceSupport implements StatefulService { @Override public boolean isRunAllowed() { + // if we have not yet initialized, then all options is false + if (!started.get() && !starting.get() && !stopping.get() && !stopped.get() + && !suspending.get() && !suspended.get() && !shutdown.get() && !shuttingdown.get()) { + return false; + } return !isStoppingOrStopped(); } http://git-wip-us.apache.org/repos/asf/camel/blob/76c83526/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 efe8a04..5d924b9 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 @@ -49,6 +49,26 @@ public class ServiceSupportTest extends TestSupport { assertEquals(false, service.isStarting()); } + public void testServiceSupportIsRunAllowed() throws Exception { + MyService service = new MyService(); + assertEquals(false, service.isRunAllowed()); + + service.start(); + assertEquals(true, service.isRunAllowed()); + + // we are allowed to run while suspending/suspended + service.suspend(); + assertEquals(true, service.isRunAllowed()); + service.resume(); + assertEquals(true, service.isRunAllowed()); + + // but if we are stopped then we are not + service.stop(); + assertEquals(false, service.isRunAllowed()); + service.shutdown(); + assertEquals(false, service.isRunAllowed()); + } + private static class MyShutdownService extends ServiceSupport { private boolean shutdown;