Repository: camel
Updated Branches:
  refs/heads/master bd350d89e -> 9694e5e2b


CAMEL-11471: Unable to update the cron details from Quartz scheduler MBean


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

Branch: refs/heads/master
Commit: 9694e5e2b28f3b877907ee7286af5baa0a99e75c
Parents: bd350d8
Author: Tadayoshi Sato <sato.tadayo...@gmail.com>
Authored: Wed Jun 28 18:12:56 2017 +0900
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Wed Jun 28 17:50:01 2017 +0200

----------------------------------------------------------------------
 .../features/src/main/resources/features.xml    |   2 +-
 tests/camel-itest-karaf/pom.xml                 |   4 +-
 tests/camel-itest-osgi/pom.xml                  |  29 ++++
 .../camel/itest/CamelQuartz2JmxUpdateTest.java  | 172 +++++++++++++++++++
 .../src/test/resources/log4j2.properties        |   2 +-
 .../camel/itest/CamelQuartz2JmxUpdateTest.xml   |  35 ++++
 6 files changed, 240 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9694e5e2/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml 
b/platforms/karaf/features/src/main/resources/features.xml
index b976d97..1b0a012 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -1568,7 +1568,7 @@
   <feature name='camel-quartz2' version='${project.version}' resolver='(obr)' 
start-level='50'>
     <bundle 
dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.c3p0/${c3p0-bundle-version}</bundle>
     <bundle 
dependency='true'>mvn:com.zaxxer/HikariCP-java6/${hikaricp-version}</bundle>
-    <bundle 
dependency='true'>mvn:org.quartz-scheduler/quartz/${quartz2-version}</bundle>
+    <bundle 
dependency='true'>wrap:mvn:org.quartz-scheduler/quartz/${quartz2-version}$overwrite=merge&amp;DynamicImport-Package=org.apache.camel.component.quartz2</bundle>
     <feature version='${project.version}'>camel-core</feature>
     <bundle>mvn:org.apache.camel/camel-quartz2/${project.version}</bundle>
   </feature>

http://git-wip-us.apache.org/repos/asf/camel/blob/9694e5e2/tests/camel-itest-karaf/pom.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/pom.xml b/tests/camel-itest-karaf/pom.xml
index 1920bc5..976744e 100644
--- a/tests/camel-itest-karaf/pom.xml
+++ b/tests/camel-itest-karaf/pom.xml
@@ -33,7 +33,7 @@
   <description>Performs Karaf compliance integration tests</description>
 
   <properties>
-    <karf-test-version>${karaf4-version}</karf-test-version>
+    <karaf-test-version>${karaf4-version}</karaf-test-version>
   </properties>
 
   <dependencies>
@@ -66,7 +66,7 @@
     <dependency>
       <groupId>org.apache.karaf</groupId>
       <artifactId>apache-karaf</artifactId>
-      <version>${karf-test-version}</version>
+      <version>${karaf-test-version}</version>
       <type>tar.gz</type>
       <scope>test</scope>
       <exclusions>

http://git-wip-us.apache.org/repos/asf/camel/blob/9694e5e2/tests/camel-itest-osgi/pom.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/pom.xml b/tests/camel-itest-osgi/pom.xml
index 2e66312..8fb522c 100644
--- a/tests/camel-itest-osgi/pom.xml
+++ b/tests/camel-itest-osgi/pom.xml
@@ -32,6 +32,10 @@
   <name>Camel :: Integration Tests :: OSGi</name>
   <description>Performs OSGi compliance integration tests</description>
 
+  <properties>
+    <karaf-test-version>${karaf4-version}</karaf-test-version>
+  </properties>
+
   <dependencies>
     <dependency>
       <groupId>org.apache.camel</groupId>
@@ -39,6 +43,31 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.apache.karaf</groupId>
+      <artifactId>apache-karaf</artifactId>
+      <version>${karaf-test-version}</version>
+      <type>tar.gz</type>
+      <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.karaf.shell</groupId>
+          <artifactId>org.apache.karaf.shell.dev</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.eclipse</groupId>
+          <artifactId>osgi</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.karaf</groupId>
+          <artifactId>org.apache.karaf.client</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.felix</groupId>
+          <artifactId>org.apache.felix.framework</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-blueprint</artifactId>
       <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/camel/blob/9694e5e2/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelQuartz2JmxUpdateTest.java
----------------------------------------------------------------------
diff --git 
a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelQuartz2JmxUpdateTest.java
 
b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelQuartz2JmxUpdateTest.java
new file mode 100644
index 0000000..2bb88cc
--- /dev/null
+++ 
b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelQuartz2JmxUpdateTest.java
@@ -0,0 +1,172 @@
+/**
+ * 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.itest;
+
+import java.lang.management.ManagementFactory;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.karaf.AbstractFeatureTest;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+
+/**
+ * CAMEL-11471: Unable to update the cron details from Quartz scheduler MBean
+ */
+@RunWith(PaxExam.class)
+public class CamelQuartz2JmxUpdateTest extends AbstractFeatureTest {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(CamelQuartz2JmxUpdateTest.class);
+
+    @Test
+    public void testUpdateCronDetails() throws Exception {
+        // install camel-quartz2 here as 'wrap:' is not available at boot time
+        installCamelFeature("camel-quartz2");
+
+        // install the camel blueprint xml file we use in this test
+        URL url = 
ObjectHelper.loadResourceAsURL("org/apache/camel/itest/CamelQuartz2JmxUpdateTest.xml",
+            CamelQuartz2JmxUpdateTest.class.getClassLoader());
+        installBlueprintAsBundle("CamelQuartz2JmxUpdateTest", url, true);
+
+        // lookup Camel from OSGi
+        CamelContext camel = getOsgiService(bundleContext, CamelContext.class);
+
+        // test camel
+        MockEndpoint mock = camel.getEndpoint("mock:result", 
MockEndpoint.class);
+        mock.expectedBodiesReceived("Hello World");
+        mock.assertIsSatisfied(5000);
+
+        doUpdateCronDetails();
+    }
+
+    private void doUpdateCronDetails() throws Exception {
+        String trigger = "myTimer";
+        String group = "myGroup";
+        String cronExpression = "0 * * * * ?";
+
+        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
+        Set<ObjectName> objectNames = mBeanServer.queryNames(
+            new 
ObjectName("quartz:type=QuartzScheduler,name=*,instance=NON_CLUSTERED"), null);
+        assertFalse("There should be a quartz scheduler MBean", 
objectNames.isEmpty());
+
+        ObjectName oName = objectNames.stream().findFirst().get();
+        LOGGER.info("Scheduler MBean: {}", oName);
+
+        CompositeData triggerData = (CompositeData) mBeanServer.invoke(oName, 
"getTrigger",
+            new Object[]{trigger, group},
+            new String[]{"java.lang.String", "java.lang.String"});
+        String jobName = (String) triggerData.get("jobName");
+        String jobGroup = (String) triggerData.get("jobGroup");
+        CompositeData jobData = (CompositeData) mBeanServer.invoke(oName, 
"getJobDetail",
+            new Object[]{jobName, jobGroup},
+            new String[]{"java.lang.String", "java.lang.String"});
+
+        String original = getCronExpression(jobData);
+        assertNotEquals("make sure original cron is different", 
cronExpression, original);
+
+        Map<String, Object> jobInfo = createJobInfo(jobName, jobGroup, 
cronExpression, jobData);
+        Map<String, Object> triggerInfo = createTriggerInfo(trigger, group, 
cronExpression, jobName, jobGroup);
+
+        // update trigger
+        mBeanServer.invoke(oName, "scheduleBasicJob",
+            new Object[]{jobInfo, triggerInfo},
+            new String[]{"java.util.Map", "java.util.Map"});
+
+        // assert job details updated
+        CompositeData jobData2 = (CompositeData) mBeanServer.invoke(oName, 
"getJobDetail",
+            new Object[]{jobName, jobGroup},
+            new String[]{"java.lang.String", "java.lang.String"});
+        String updated = getCronExpression(jobData2);
+        assertEquals("cron should be updated", cronExpression, updated);
+    }
+
+    private String getCronExpression(CompositeData jobData) {
+        TabularData jobDataMap = (TabularData) jobData.get("jobDataMap");
+        CompositeData cron = jobDataMap.get(new 
String[]{"CamelQuartzTriggerCronExpression"});
+        Iterator it = cron.values().iterator();
+        it.next();
+        return (String) it.next();
+    }
+
+    private Map<String, Object> createJobInfo(String jobName, String jobGroup, 
String cronExpression,
+                                              CompositeData jobData) {
+        Map<String, Object> jobInfo = new HashMap<>();
+        jobInfo.put("name", jobName);
+        jobInfo.put("group", jobGroup);
+        if (jobData.get("description") != null) {
+            jobInfo.put("description", jobData.get("description"));
+        }
+        jobInfo.put("jobClass", jobData.get("jobClass"));
+        jobInfo.put("durability", jobData.get("durability"));
+        jobInfo.put("shouldRecover", jobData.get("shouldRecover"));
+
+        Map<String, Object> jobDataMap = new HashMap<>();
+        TabularData tJobDataMap = (TabularData) jobData.get("jobDataMap");
+        for (Object cKey : tJobDataMap.keySet()) {
+            Object key = ((List) cKey).get(0);
+            CompositeData cd = tJobDataMap.get(new Object[]{key});
+            if (cd != null) {
+                Iterator it = cd.values().iterator();
+                String tKey = (String) it.next();
+                Object tValue = it.next();
+                jobDataMap.put(tKey, tValue);
+            }
+        }
+        jobDataMap.put("CamelQuartzTriggerType", "cron");
+        jobDataMap.put("CamelQuartzTriggerCronExpression", cronExpression);
+        jobInfo.put("jobDataMap", jobDataMap);
+        return jobInfo;
+    }
+
+    private Map<String, Object> createTriggerInfo(String trigger, String 
group, String cronExpression,
+                                                  String jobName, String 
jobGroup) {
+        Map<String, Object> triggerInfo = new HashMap<>();
+        triggerInfo.put("cronExpression", cronExpression);
+        triggerInfo.put("name", trigger);
+        triggerInfo.put("group", group);
+        triggerInfo.put("jobName", jobName);
+        triggerInfo.put("jobGroup", jobGroup);
+        triggerInfo.put("misfireInstruction", 1);
+        return triggerInfo;
+    }
+
+    @Configuration
+    public Option[] configure() {
+        return configure("camel-test-karaf");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/9694e5e2/tests/camel-itest-osgi/src/test/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/resources/log4j2.properties 
b/tests/camel-itest-osgi/src/test/resources/log4j2.properties
index 2f2e68b..d406a9f 100644
--- a/tests/camel-itest-osgi/src/test/resources/log4j2.properties
+++ b/tests/camel-itest-osgi/src/test/resources/log4j2.properties
@@ -6,7 +6,7 @@
 ## (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
+##      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,

http://git-wip-us.apache.org/repos/asf/camel/blob/9694e5e2/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelQuartz2JmxUpdateTest.xml
----------------------------------------------------------------------
diff --git 
a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelQuartz2JmxUpdateTest.xml
 
b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelQuartz2JmxUpdateTest.xml
new file mode 100644
index 0000000..920b2cc
--- /dev/null
+++ 
b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelQuartz2JmxUpdateTest.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+           xsi:schemaLocation="
+             http://www.osgi.org/xmlns/blueprint/v1.0.0 
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd";>
+
+  <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/blueprint";>
+    <route>
+      <from uri="quartz2://myGroup/myTimer?cron=0/1 * * * * ?" />
+      <transform>
+        <constant>Hello World</constant>
+      </transform>
+      <to uri="mock:result" />
+    </route>
+  </camelContext>
+
+</blueprint>

Reply via email to