Repository: camel
Updated Branches:
  refs/heads/camel-2.12.x c3668a305 -> daf741545
  refs/heads/master 7c21b39bf -> ecdbad6cc


CAMEL-7276: camel-quartz with JMX disabled should use per context quartz 
scheduler instance by default as it does when JMX is enabled.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ecdbad6c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ecdbad6c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ecdbad6c

Branch: refs/heads/master
Commit: ecdbad6cc8039d78bf39ca997121eca7e859857b
Parents: 7c21b39
Author: Claus Ibsen <[email protected]>
Authored: Sun Mar 9 08:34:51 2014 +0100
Committer: Claus Ibsen <[email protected]>
Committed: Sun Mar 9 08:34:51 2014 +0100

----------------------------------------------------------------------
 .../camel/component/quartz/QuartzComponent.java |  2 +-
 ...onentCamelContextSchedulerIsolationTest.java | 95 ++++++++++++++++++++
 .../component/quartz/QuartzPropertiesTest.java  |  4 +-
 .../component/quartz2/QuartzComponent.java      |  2 +-
 ...onentCamelContextSchedulerIsolationTest.java | 95 ++++++++++++++++++++
 .../component/quartz2/QuartzPropertiesTest.java |  4 +-
 6 files changed, 196 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ecdbad6c/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
 
b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
index d69ccfe..a9e83fb 100644
--- 
a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
+++ 
b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
@@ -527,7 +527,7 @@ public class QuartzComponent extends DefaultComponent 
implements StartupListener
         String instName = 
prop.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME);
 
         // camel context name will be a suffix to use one scheduler per context
-        String identity = getCamelContext().getManagementName();
+        String identity = QuartzHelper.getQuartzContextName(getCamelContext());
         if (identity != null) {
             if (instName == null) {
                 instName = "scheduler-" + identity;

http://git-wip-us.apache.org/repos/asf/camel/blob/ecdbad6c/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzComponentCamelContextSchedulerIsolationTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzComponentCamelContextSchedulerIsolationTest.java
 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzComponentCamelContextSchedulerIsolationTest.java
new file mode 100644
index 0000000..83bc3f1
--- /dev/null
+++ 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzComponentCamelContextSchedulerIsolationTest.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.quartz;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.management.JmxSystemPropertyKeys;
+import org.junit.AfterClass;
+import org.junit.Test;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotSame;
+
+public class QuartzComponentCamelContextSchedulerIsolationTest {
+
+    @AfterClass
+    public static void afterTests() {
+        System.clearProperty(JmxSystemPropertyKeys.DISABLED);
+    }
+
+    @Test
+    public void testSchedulerIsolationUnmanaged() throws Exception {
+        disableJMX();
+        testSchedulerIsolation();
+    }
+
+    @Test
+    public void testSchedulerIsolationManaged() throws Exception {
+        enableJMX();
+        testSchedulerIsolation();
+    }
+
+    private void testSchedulerIsolation() throws Exception {
+        CamelContext context = createCamelContext();
+        context.start();
+
+        CamelContext anotherContext = createCamelContext();
+        assertNotEquals(anotherContext.getName(), context.getName());
+        assertNotEquals(anotherContext, context);
+
+        assertNotSame(getDefaultScheduler(context), 
getDefaultScheduler(anotherContext));
+    }
+
+    /**
+     * Create a new camel context instance.
+     */
+    private DefaultCamelContext createCamelContext() {
+        return new DefaultCamelContext();
+    }
+
+    /**
+     * Get the quartz component for the provided camel context.
+     */
+    private QuartzComponent getQuartzComponent(CamelContext context) {
+        return context.getComponent("quartz", QuartzComponent.class);
+    }
+
+    /**
+     * Get the default scheduler for the provided camel context.
+     */
+    private Scheduler getDefaultScheduler(CamelContext context) throws 
SchedulerException {
+        return getQuartzComponent(context).getFactory().getScheduler();
+    }
+
+    /**
+     * Disables the JMX agent.
+     */
+    private void disableJMX() {
+        System.setProperty(JmxSystemPropertyKeys.DISABLED, "true");
+    }
+
+    /**
+     * Enables the JMX agent.
+     */
+    private void enableJMX() {
+        System.setProperty(JmxSystemPropertyKeys.DISABLED, "false");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ecdbad6c/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzPropertiesTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzPropertiesTest.java
 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzPropertiesTest.java
index 5f4ac2d..5929da9 100644
--- 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzPropertiesTest.java
+++ 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzPropertiesTest.java
@@ -48,7 +48,7 @@ public class QuartzPropertiesTest extends BaseQuartzTest {
 
         quartz.start();
 
-        assertEquals("MyScheduler", quartz.getScheduler().getSchedulerName());
+        assertEquals("MyScheduler-" + context.getName(), 
quartz.getScheduler().getSchedulerName());
         assertEquals("2", quartz.getScheduler().getSchedulerInstanceId());
     }
 
@@ -77,7 +77,7 @@ public class QuartzPropertiesTest extends BaseQuartzTest {
 
         quartz.start();
 
-        assertEquals("MyScheduler", quartz.getScheduler().getSchedulerName());
+        assertEquals("MyScheduler-" + context.getName(), 
quartz.getScheduler().getSchedulerName());
         assertEquals("2", quartz.getScheduler().getSchedulerInstanceId());
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/ecdbad6c/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzComponent.java
 
b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzComponent.java
index 082fe85..f24046d 100644
--- 
a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzComponent.java
+++ 
b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzComponent.java
@@ -189,7 +189,7 @@ public class QuartzComponent extends DefaultComponent 
implements StartupListener
         String instName = 
prop.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME);
 
         // camel context name will be a suffix to use one scheduler per context
-        String identity = getCamelContext().getManagementName();
+        String identity = QuartzHelper.getQuartzContextName(getCamelContext());
         if (identity != null) {
             if (instName == null) {
                 instName = "scheduler-" + identity;

http://git-wip-us.apache.org/repos/asf/camel/blob/ecdbad6c/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzComponentCamelContextSchedulerIsolationTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzComponentCamelContextSchedulerIsolationTest.java
 
b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzComponentCamelContextSchedulerIsolationTest.java
new file mode 100644
index 0000000..26b7aac
--- /dev/null
+++ 
b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzComponentCamelContextSchedulerIsolationTest.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.quartz2;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.management.JmxSystemPropertyKeys;
+import org.junit.AfterClass;
+import org.junit.Test;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotSame;
+
+public class QuartzComponentCamelContextSchedulerIsolationTest {
+
+    @AfterClass
+    public static void afterTests() {
+        System.clearProperty(JmxSystemPropertyKeys.DISABLED);
+    }
+
+    @Test
+    public void testSchedulerIsolationUnmanaged() throws Exception {
+        disableJMX();
+        testSchedulerIsolation();
+    }
+
+    @Test
+    public void testSchedulerIsolationManaged() throws Exception {
+        enableJMX();
+        testSchedulerIsolation();
+    }
+
+    private void testSchedulerIsolation() throws Exception {
+        CamelContext context = createCamelContext();
+        context.start();
+
+        CamelContext anotherContext = createCamelContext();
+        assertNotEquals(anotherContext.getName(), context.getName());
+        assertNotEquals(anotherContext, context);
+
+        assertNotSame(getDefaultScheduler(context), 
getDefaultScheduler(anotherContext));
+    }
+
+    /**
+     * Create a new camel context instance.
+     */
+    private DefaultCamelContext createCamelContext() {
+        return new DefaultCamelContext();
+    }
+
+    /**
+     * Get the quartz component for the provided camel context.
+     */
+    private QuartzComponent getQuartzComponent(CamelContext context) {
+        return context.getComponent("quartz2", QuartzComponent.class);
+    }
+
+    /**
+     * Get the default scheduler for the provided camel context.
+     */
+    private Scheduler getDefaultScheduler(CamelContext context) throws 
SchedulerException {
+        return getQuartzComponent(context).getScheduler();
+    }
+
+    /**
+     * Disables the JMX agent.
+     */
+    private void disableJMX() {
+        System.setProperty(JmxSystemPropertyKeys.DISABLED, "true");
+    }
+
+    /**
+     * Enables the JMX agent.
+     */
+    private void enableJMX() {
+        System.setProperty(JmxSystemPropertyKeys.DISABLED, "false");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ecdbad6c/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzPropertiesTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzPropertiesTest.java
 
b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzPropertiesTest.java
index b7aa99e..a75aac2 100644
--- 
a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzPropertiesTest.java
+++ 
b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzPropertiesTest.java
@@ -46,7 +46,7 @@ public class QuartzPropertiesTest extends BaseQuartzTest {
 
         quartz.start();
 
-        assertEquals("MyScheduler", quartz.getScheduler().getSchedulerName());
+        assertEquals("MyScheduler-" + context.getName(), 
quartz.getScheduler().getSchedulerName());
         assertEquals("2", quartz.getScheduler().getSchedulerInstanceId());
     }
 
@@ -75,7 +75,7 @@ public class QuartzPropertiesTest extends BaseQuartzTest {
 
         quartz.start();
 
-        assertEquals("MyScheduler", quartz.getScheduler().getSchedulerName());
+        assertEquals("MyScheduler-" + context.getName(), 
quartz.getScheduler().getSchedulerName());
         assertEquals("2", quartz.getScheduler().getSchedulerInstanceId());
     }
 

Reply via email to