You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2017/08/30 08:25:39 UTC
karaf git commit: Add a full JMS + JDBC XA test with camel
Repository: karaf
Updated Branches:
refs/heads/master 8c5682890 -> d40d0074a
Add a full JMS + JDBC XA test with camel
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/d40d0074
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/d40d0074
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/d40d0074
Branch: refs/heads/master
Commit: d40d0074a3968b004d479afefcb5147e945460e9
Parents: 8c56828
Author: Guillaume Nodet <gn...@apache.org>
Authored: Wed Aug 30 10:09:14 2017 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Wed Aug 30 10:09:14 2017 +0200
----------------------------------------------------------------------
.../apache/karaf/itests/features/XATest.java | 102 +++++++++++++++++++
.../org.ops4j.connectionfactory-artemis.cfg | 24 +++++
.../features/org.ops4j.datasource-derby.cfg | 26 +++++
.../karaf/itests/features/xa-test-camel.xml | 44 ++++++++
4 files changed, 196 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/d40d0074/itests/src/test/java/org/apache/karaf/itests/features/XATest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/features/XATest.java b/itests/src/test/java/org/apache/karaf/itests/features/XATest.java
new file mode 100644
index 0000000..72a8399
--- /dev/null
+++ b/itests/src/test/java/org/apache/karaf/itests/features/XATest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed 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.karaf.itests.features;
+
+import org.apache.karaf.features.FeaturesService;
+import org.apache.karaf.itests.KarafTestSupport;
+import org.apache.karaf.itests.util.RunIfRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.MavenUtils;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.osgi.framework.Bundle;
+
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class XATest extends KarafTestSupport {
+
+ private static final EnumSet<FeaturesService.Option> NO_AUTO_REFRESH = EnumSet.of(FeaturesService.Option.NoAutoRefreshBundles);
+
+ @Rule
+ public RunIfRule rule = new RunIfRule();
+
+ @Configuration
+ public Option[] config() {
+ String version = MavenUtils.getArtifactVersion("org.apache.karaf", "apache-karaf");
+ List<Option> result = new LinkedList<>(Arrays.asList(super.config()));
+ result.add(editConfigurationFilePut("etc/org.apache.karaf.features.cfg", "featuresRepositories",
+ "mvn:org.apache.karaf.features/framework/" + version + "/xml/features, " +
+ "mvn:org.apache.karaf.features/enterprise/" + version + "/xml/features, " +
+ "mvn:org.apache.karaf.features/spring/" + version + "/xml/features, " +
+ "mvn:org.apache.karaf.features/standard/" + version + "/xml/features, " +
+ "mvn:org.apache.activemq/artemis-features/2.2.0/xml/features, " +
+ "mvn:org.apache.camel.karaf/apache-camel/2.19.2/xml/features"
+ ));
+ result.add(replaceConfigurationFile("etc/org.ops4j.connectionfactory-artemis.cfg", getConfigFile("/org/apache/karaf/itests/features/org.ops4j.connectionfactory-artemis.cfg")));
+ result.add(replaceConfigurationFile("etc/org.ops4j.datasource-derby.cfg", getConfigFile("/org/apache/karaf/itests/features/org.ops4j.datasource-derby.cfg")));
+ result.add(replaceConfigurationFile("etc/xa-test-camel.xml", getConfigFile("/org/apache/karaf/itests/features/xa-test-camel.xml")));
+ return result.toArray(new Option[result.size()]);
+ }
+
+ @Test
+ public void installFeature() throws Exception {
+ featureService.installFeatures(asSet(
+ "transaction",
+ "transaction-manager-narayana",
+ "artemis",
+ "pax-jms-pool",
+ "jms",
+ "pax-jdbc-derby",
+ "pax-jdbc-pool-transx",
+ "jdbc",
+ "camel-blueprint",
+ "camel-spring",
+ "camel-sql",
+ "camel-jms"), NO_AUTO_REFRESH);
+
+ Bundle bundle = bundleContext.installBundle("blueprint:file:etc/xa-test-camel.xml");
+ bundle.start();
+
+ executeCommand("jdbc:execute derby CREATE TABLE messages (id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY, message VARCHAR(1024) NOT NULL, CONSTRAINT primary_key PRIMARY KEY (id))");
+ executeCommand("jms:send artemis MyQueue 'the-message'");
+
+ Thread.sleep(1000);
+
+ String output = executeCommand("jdbc:query derby select * from messages");
+ System.err.println(output);
+
+ assertContains("the-message", output);
+
+ }
+
+ private static Set<String> asSet(String... strings) {
+ return new HashSet<>(Arrays.asList(strings));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d40d0074/itests/src/test/resources/org/apache/karaf/itests/features/org.ops4j.connectionfactory-artemis.cfg
----------------------------------------------------------------------
diff --git a/itests/src/test/resources/org/apache/karaf/itests/features/org.ops4j.connectionfactory-artemis.cfg b/itests/src/test/resources/org/apache/karaf/itests/features/org.ops4j.connectionfactory-artemis.cfg
new file mode 100644
index 0000000..c5a9dcc
--- /dev/null
+++ b/itests/src/test/resources/org/apache/karaf/itests/features/org.ops4j.connectionfactory-artemis.cfg
@@ -0,0 +1,24 @@
+################################################################################
+#
+# 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.
+#
+################################################################################
+
+name = artemis
+type = artemis
+url = tcp://0.0.0.0:61616?producerWindowSize=-1
+user = karaf
+password = karaf
http://git-wip-us.apache.org/repos/asf/karaf/blob/d40d0074/itests/src/test/resources/org/apache/karaf/itests/features/org.ops4j.datasource-derby.cfg
----------------------------------------------------------------------
diff --git a/itests/src/test/resources/org/apache/karaf/itests/features/org.ops4j.datasource-derby.cfg b/itests/src/test/resources/org/apache/karaf/itests/features/org.ops4j.datasource-derby.cfg
new file mode 100644
index 0000000..3dfe2c8
--- /dev/null
+++ b/itests/src/test/resources/org/apache/karaf/itests/features/org.ops4j.datasource-derby.cfg
@@ -0,0 +1,26 @@
+################################################################################
+#
+# 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.
+#
+################################################################################
+
+osgi.jdbc.driver.name = derby
+osgi.jndi.service.name = derby
+url = jdbc:derby:data/derby/test;create=true
+pool = transx
+xa = true
+user = sa
+password =
http://git-wip-us.apache.org/repos/asf/karaf/blob/d40d0074/itests/src/test/resources/org/apache/karaf/itests/features/xa-test-camel.xml
----------------------------------------------------------------------
diff --git a/itests/src/test/resources/org/apache/karaf/itests/features/xa-test-camel.xml b/itests/src/test/resources/org/apache/karaf/itests/features/xa-test-camel.xml
new file mode 100644
index 0000000..ec5d4ef
--- /dev/null
+++ b/itests/src/test/resources/org/apache/karaf/itests/features/xa-test-camel.xml
@@ -0,0 +1,44 @@
+<?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">
+
+ <reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/>
+
+ <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
+ <property name="connectionFactory">
+ <reference interface="javax.jms.ConnectionFactory" />
+ </property>
+ <property name="transactionManager" ref="transactionManager"/>
+ </bean>
+
+ <bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
+ <property name="dataSource">
+ <reference interface="javax.sql.DataSource" />
+ </property>
+ </bean>
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+ <route id="demo-route">
+ <from uri="jms:queue:MyQueue?transacted=true"/>
+ <to uri="log:out" />
+ <to uri="sql:insert into messages (message) values (:#${body})?transacted=true" />
+ </route>
+ </camelContext>
+
+</blueprint>
\ No newline at end of file