From ac5ba4082924fca214cf6f261d887fe3ebdffe23 Mon Sep 17 00:00:00 2001 From: Claus Ibsen Date: Thu, 3 Oct 2013 16:49:45 +0200 Subject: [PATCH] Fixed karaf itest. Testing by hot deploying by copying a .xml file into deploy folder need to be done differently. --- .../karaf/itest/AbstractJmsFeatureTest.java | 24 +++++++++++++++++++ ...iveMQBrokerNdExternalCamelFeatureTest.java | 14 +++++++++-- .../org/apache/activemq/karaf/itest/camel.xml | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/AbstractJmsFeatureTest.java b/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/AbstractJmsFeatureTest.java index 54482ce7b8..609fb37cc7 100644 --- a/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/AbstractJmsFeatureTest.java +++ b/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/AbstractJmsFeatureTest.java @@ -16,6 +16,11 @@ */ package org.apache.activemq.karaf.itest; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; import javax.jms.Connection; import javax.jms.MessageConsumer; import javax.jms.Session; @@ -24,6 +29,25 @@ import org.apache.activemq.ActiveMQConnectionFactory; public abstract class AbstractJmsFeatureTest extends AbstractFeatureTest { + public static void copyFile(File from, File to) throws IOException { + FileChannel in = new FileInputStream(from).getChannel(); + FileChannel out = new FileOutputStream(to).getChannel(); + try { + long size = in.size(); + long position = 0; + while (position < size) { + position += in.transferTo(position, 8192, out); + } + } finally { + try { + in.close(); + out.close(); + } catch (Exception e) { + // ignore + } + } + } + protected String consumeMessage(String nameAndPayload) throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(); Connection connection = factory.createConnection(AbstractFeatureTest.USER, AbstractFeatureTest.PASSWORD); diff --git a/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerNdExternalCamelFeatureTest.java b/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerNdExternalCamelFeatureTest.java index 7b913db753..35bea63139 100644 --- a/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerNdExternalCamelFeatureTest.java +++ b/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerNdExternalCamelFeatureTest.java @@ -18,6 +18,7 @@ package org.apache.activemq.karaf.itest; import java.io.File; import java.util.concurrent.Callable; + import org.junit.Test; import org.junit.runner.RunWith; import org.ops4j.pax.exam.MavenUtils; @@ -35,8 +36,9 @@ public class ActiveMQBrokerNdExternalCamelFeatureTest extends AbstractJmsFeature @Configuration public static Option[] configure() { + // copy camel.xml into a temporary directory in karaf, so we later can hot-deploy it Option[] baseOptions = append( - replaceConfigurationFile("deploy/camel.xml", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/camel.xml")), + replaceConfigurationFile("data/tmp/camel.xml", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/camel.xml")), configure("activemq")); return configureBrokerStart(append(scanFeatures(getCamelFeatureUrl( MavenUtils.getArtifactVersion("org.apache.camel.karaf", "apache-camel") @@ -45,8 +47,8 @@ public class ActiveMQBrokerNdExternalCamelFeatureTest extends AbstractJmsFeature @Test public void test() throws Throwable { + System.err.println(executeCommand("features:list").trim()); - System.err.println(executeCommand("osgi:ls").trim()); System.err.println(executeCommand("osgi:list").trim()); withinReason(new Callable() { @@ -68,6 +70,14 @@ public class ActiveMQBrokerNdExternalCamelFeatureTest extends AbstractJmsFeature System.err.println(executeCommand("activemq:bstat").trim()); + // hot deploy the camel.xml file by copying it to the deploy directory + System.err.println("Karaf is running in dir: " + System.getProperty("karaf.base")); + String karafDir = System.getProperty("karaf.base"); + System.err.println("Hot deploying Camel application"); + copyFile(new File(karafDir + "/data/tmp/camel.xml"), new File(karafDir + "/deploy/camel.xml")); + Thread.sleep(3 * 1000); + System.err.println("Continuing..."); + // produce and consume final String nameAndPayload = String.valueOf(System.currentTimeMillis()); produceMessage("camel_in"); diff --git a/activemq-karaf-itest/src/test/resources/org/apache/activemq/karaf/itest/camel.xml b/activemq-karaf-itest/src/test/resources/org/apache/activemq/karaf/itest/camel.xml index ba7aa9c644..641c46a102 100644 --- a/activemq-karaf-itest/src/test/resources/org/apache/activemq/karaf/itest/camel.xml +++ b/activemq-karaf-itest/src/test/resources/org/apache/activemq/karaf/itest/camel.xml @@ -20,7 +20,7 @@