You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/03/09 08:33:09 UTC

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

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/daf74154
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/daf74154
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/daf74154

Branch: refs/heads/camel-2.12.x
Commit: daf74154561f0ee23f94d8ab6b7480375f37f11a
Parents: c3668a3
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Mar 9 08:34:51 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Mar 9 08:35:27 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/daf74154/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 64979bc..6acb18f 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
@@ -506,7 +506,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/daf74154/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/daf74154/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 dd61898..8eb0e9e 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
@@ -49,7 +49,7 @@ public class QuartzPropertiesTest extends CamelTestSupport {
 
         quartz.start();
 
-        assertEquals("MyScheduler", quartz.getScheduler().getSchedulerName());
+        assertEquals("MyScheduler-" + context.getName(), quartz.getScheduler().getSchedulerName());
         assertEquals("2", quartz.getScheduler().getSchedulerInstanceId());
     }
 
@@ -78,7 +78,7 @@ public class QuartzPropertiesTest extends CamelTestSupport {
 
         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/daf74154/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 db078f9..b12f69d 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
@@ -161,7 +161,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/daf74154/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/daf74154/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 15b309c..948cb8c 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
@@ -47,7 +47,7 @@ public class QuartzPropertiesTest extends CamelTestSupport {
 
         quartz.start();
 
-        assertEquals("MyScheduler", quartz.getScheduler().getSchedulerName());
+        assertEquals("MyScheduler-" + context.getName(), quartz.getScheduler().getSchedulerName());
         assertEquals("2", quartz.getScheduler().getSchedulerInstanceId());
     }
 
@@ -76,7 +76,7 @@ public class QuartzPropertiesTest extends CamelTestSupport {
 
         quartz.start();
 
-        assertEquals("MyScheduler", quartz.getScheduler().getSchedulerName());
+        assertEquals("MyScheduler-" + context.getName(), quartz.getScheduler().getSchedulerName());
         assertEquals("2", quartz.getScheduler().getSchedulerInstanceId());
     }