[AMQ-6546] Big refactoring and cleanup of karaf itests

This commit is contained in:
Christian Schneider 2016-12-19 09:28:03 +01:00
parent 56917c07ec
commit 4dd3aa420e
12 changed files with 211 additions and 361 deletions

View File

@ -16,6 +16,27 @@
*/
package org.apache.activemq.karaf.itest;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.composite;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.security.PrivilegedAction;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.security.auth.Subject;
import org.apache.karaf.features.FeaturesService;
@ -25,11 +46,12 @@ import org.apache.karaf.shell.api.console.Session;
import org.apache.karaf.shell.api.console.SessionFactory;
import org.junit.After;
import org.junit.Before;
import org.ops4j.pax.exam.MavenUtils;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.TestProbeBuilder;
import org.ops4j.pax.exam.ProbeBuilder;
import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
import org.ops4j.pax.exam.TestProbeBuilder;
import org.ops4j.pax.exam.karaf.options.LogLevelOption;
import org.ops4j.pax.exam.options.MavenUrlReference;
import org.ops4j.pax.exam.options.UrlReference;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@ -37,49 +59,21 @@ import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import static org.ops4j.pax.exam.CoreOptions.*;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.*;
public abstract class AbstractFeatureTest {
private static final String KARAF_MAJOR_VERSION = "4.0.0";
public static final Logger LOG = LoggerFactory.getLogger(AbstractFeatureTest.class);
public static final long ASSERTION_TIMEOUT = 30000L;
public static final long COMMAND_TIMEOUT = 30000L;
public static final String USER = "karaf";
public static final String PASSWORD = "karaf";
static String basedir;
static {
try {
File location = new File(AbstractFeatureTest.class.getProtectionDomain().getCodeSource().getLocation().getFile());
basedir = new File(location, "../..").getCanonicalPath();
System.err.println("basedir=" + basedir);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static final String RESOURCE_BASE = "src/test/resources/org/apache/activemq/karaf/itest/";
@Inject
BundleContext bundleContext;
@Inject
FeaturesService featuresService;
@Inject
FeaturesService featuresService;
@Before
public void setUp() throws Exception {
@ -101,7 +95,7 @@ public abstract class AbstractFeatureTest {
ExecutorService executor = Executors.newCachedThreadPool();
protected String executeCommand(final String command, final Long timeout, final Boolean silent) {
private String executeCommand(final String command, final Long timeout, final Boolean silent) {
String response;
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final PrintStream printStream = new PrintStream(byteArrayOutputStream);
@ -151,19 +145,17 @@ public abstract class AbstractFeatureTest {
return executeCommand(command, COMMAND_TIMEOUT, false);
}
/**
* Installs a feature and asserts that feature is properly installed.
* @param feature
* @throws Exception
*/
public void installAndAssertFeature(final String feature) throws Throwable {
executeCommand("feature:list -i");
executeCommand("feature:install " + feature);
assertFeatureInstalled(feature);
}
/**
* Installs a feature and asserts that feature is properly installed.
*
* @param feature
* @throws Exception
*/
public void installAndAssertFeature(final String feature) throws Throwable {
featuresService.installFeature(feature);
}
public void assertFeatureInstalled(final String feature) throws Throwable {
executeCommand("feature:list -i");
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
@ -173,94 +165,48 @@ public abstract class AbstractFeatureTest {
});
}
public boolean verifyBundleInstalled(final String bundleName) throws Exception {
boolean found = false;
public Bundle getBundle(String symName) {
for (Bundle bundle: bundleContext.getBundles()) {
LOG.debug("Checking: " + bundle.getSymbolicName());
if (bundle.getSymbolicName().contains(bundleName)) {
found = true;
break;
if (bundle.getSymbolicName().contains(symName)) {
return bundle;
}
}
return found;
throw new RuntimeException("Bundle " + symName + " not found");
}
public static String karafVersion() {
return System.getProperty("karafVersion", "unknown-need-env-var");
public static Option configureBrokerStart(String xmlConfig) {
return composite(
replaceConfigurationFile("etc/activemq.xml", new File(RESOURCE_BASE + xmlConfig + ".xml")),
replaceConfigurationFile("etc/org.apache.activemq.server-default.cfg",
new File(RESOURCE_BASE + "org.apache.activemq.server-default.cfg"))
);
}
public static UrlReference getActiveMQKarafFeatureUrl() {
String type = "xml/features";
UrlReference urlReference = mavenBundle().groupId("org.apache.activemq").
artifactId("activemq-karaf").versionAsInProject().type(type);
System.err.println("FeatureURL: " + urlReference.getURL());
return urlReference;
public static Option configureBrokerStart() {
return configureBrokerStart("activemq");
}
// for use from a probe
public String getCamelFeatureUrl() {
return getCamelFeatureUrl(System.getProperty("camel.version", "unknown"));
public static Option configure(String... features) {
MavenUrlReference karafUrl = maven().groupId("org.apache.karaf").artifactId("apache-karaf")
.type("tar.gz").versionAsInProject();
UrlReference camelUrl = maven().groupId("org.apache.camel.karaf")
.artifactId("apache-camel").type("xml").classifier("features").versionAsInProject();
UrlReference activeMQUrl = maven().groupId("org.apache.activemq").
artifactId("activemq-karaf").versionAsInProject().type("xml").classifier("features").versionAsInProject();
return composite(
karafDistributionConfiguration().frameworkUrl(karafUrl).karafVersion(KARAF_MAJOR_VERSION)
.name("Apache Karaf").unpackDirectory(new File("target/paxexam/unpack/")),
keepRuntimeFolder(), //
logLevel(LogLevelOption.LogLevel.WARN), //
editConfigurationFilePut("etc/config.properties", "karaf.startlevel.bundle", "50"),
// debugConfiguration("5005", true),
features(activeMQUrl, features), //
features(camelUrl)
);
}
public static String getCamelFeatureUrl(String ver) {
return "mvn:org.apache.camel.karaf/apache-camel/"
+ ver
+ "/xml/features";
}
public static UrlReference getKarafFeatureUrl() {
LOG.info("*** The karaf version is " + karafVersion() + " ***");
String type = "xml/features";
return mavenBundle().groupId("org.apache.karaf.assemblies.features").
artifactId("standard").version(karafVersion()).type(type);
}
public static Option[] configureBrokerStart(Option[] existingOptions, String xmlConfig) {
existingOptions = append(
replaceConfigurationFile("etc/activemq.xml", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/" + xmlConfig + ".xml")),
existingOptions);
return append(
replaceConfigurationFile("etc/org.apache.activemq.server-default.cfg", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/org.apache.activemq.server-default.cfg")),
existingOptions);
}
public static Option[] configureBrokerStart(Option[] existingOptions) {
final String xmlConfig = "activemq";
return configureBrokerStart(existingOptions, xmlConfig);
}
public static Option[] append(Option toAdd, Option[] existingOptions) {
ArrayList<Option> newOptions = new ArrayList<Option>();
newOptions.addAll(Arrays.asList(existingOptions));
newOptions.add(toAdd);
return newOptions.toArray(new Option[]{});
}
public static Option[] configure(String ...features) {
ArrayList<String> f = new ArrayList<String>();
f.addAll(Arrays.asList(features));
Option[] options =
new Option[]{
karafDistributionConfiguration().frameworkUrl(
maven().groupId("org.apache.karaf").artifactId("apache-karaf").type("tar.gz").versionAsInProject())
.karafVersion(karafVersion()).name("Apache Karaf")
.unpackDirectory(new File("target/paxexam/unpack/")),
KarafDistributionOption.keepRuntimeFolder(),
logLevel(LogLevelOption.LogLevel.WARN),
editConfigurationFilePut("etc/config.properties", "karaf.startlevel.bundle", "50"),
//debugConfiguration("5005", true),
features(getActiveMQKarafFeatureUrl(), f.toArray(new String[f.size()]))};
if (f.contains("activemq-camel")) {
options = append(features(maven().groupId("org.apache.camel.karaf").artifactId("apache-camel")
.versionAsInProject()
.type("xml/features")), options);
}
return options;
protected static String camelVersion() {
return MavenUtils.getArtifactVersion("org.apache.camel.karaf", "apache-camel");
}
protected boolean withinReason(Callable<Boolean> callable) throws Throwable {
@ -278,4 +224,21 @@ public abstract class AbstractFeatureTest {
}
}
}
protected void withinReason(Runnable runable) throws Exception {
long max = System.currentTimeMillis() + ASSERTION_TIMEOUT;
while (true) {
try {
runable.run();
return;
} catch (Throwable t) {
if (System.currentTimeMillis() < max) {
TimeUnit.SECONDS.sleep(1);
continue;
} else {
throw t;
}
}
}
}
}

View File

@ -71,11 +71,10 @@ public abstract class AbstractJmsFeatureTest extends AbstractFeatureTest {
connection.close();
}
protected Connection getConnection() throws Throwable {
protected Connection getConnection() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
Connection connection = factory.createConnection(AbstractFeatureTest.USER, AbstractFeatureTest.PASSWORD);
connection.start();
return connection;
}
}

View File

@ -16,10 +16,6 @@
*/
package org.apache.activemq.karaf.itest;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.Callable;
import javax.jms.Connection;
import org.apache.qpid.jms.JmsConnectionFactory;
@ -29,37 +25,37 @@ 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.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class ActiveMQAMQPBrokerFeatureTest extends ActiveMQBrokerFeatureTest {
private static final Integer AMQP_PORT = 61636;
@Configuration
public static Option[] configure() {
Option[] configure = configure("activemq", "activemq-amqp-client");
Option[] configuredOptions = configureBrokerStart(configure);
return configuredOptions;
return new Option[] //
{
configure("activemq", "activemq-amqp-client"), //
configureBrokerStart()
};
}
@Override
protected Connection getConnection() throws Throwable {
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
assertTrue("qpid jms client bundle installed", verifyBundleInstalled("org.apache.qpid.jms.client"));
return true;
protected Connection getConnection() throws Exception {
withinReason(new Runnable() {
public void run() {
getBundle("org.apache.qpid.jms.client");
}
});
String amqpURI = "amqp://localhost:" + AMQP_PORT;
JmsConnectionFactory factory = new JmsConnectionFactory(amqpURI);
factory.setUsername(AbstractFeatureTest.USER);
factory.setPassword(AbstractFeatureTest.PASSWORD);
Connection connection = factory.createConnection();
connection.start();
return connection;
}

View File

@ -39,7 +39,7 @@ public class ActiveMQBrokerBlueprintTest extends AbstractJmsFeatureTest {
{
composite(super.configure("activemq", "activemq-blueprint")),
replaceConfigurationFile("deploy/activemq-blueprint.xml",
new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/activemq-blueprint.xml"))
new File("src/test/resources/org/apache/activemq/karaf/itest/activemq-blueprint.xml"))
};
}

View File

@ -16,12 +16,6 @@
*/
package org.apache.activemq.karaf.itest;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.Callable;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
@ -43,29 +37,11 @@ public class ActiveMQBrokerFeatureTest extends AbstractJmsFeatureTest {
@Configuration
public static Option[] configure() {
return configureBrokerStart(configure("activemq"));
}
protected final File file = new File("../../../classes/META-INF/maven/dependencies.properties");
public final String getArtifactVersion(final String groupId, final String artifactId) {
final Properties dependencies = new Properties();
try (FileInputStream fis = new FileInputStream(file)){
dependencies.load(fis);
final String version = dependencies
.getProperty(groupId + "/" + artifactId + "/version");
if (version == null) {
throw new RuntimeException(
"Could not resolve version. Do you have a dependency for " + groupId + "/"
+ artifactId + " in your maven project?");
}
return version;
}
catch (IOException e) {
throw new RuntimeException("Could not resolve version for groupId:" + groupId
+ " artifactId:" + artifactId
+ " by reading the dependency information generated by maven.", e);
}
return new Option[] //
{
configure("activemq"), //
configureBrokerStart()
};
}
protected String installWrappedBundle(WrappedUrlProvisionOption option) {
@ -75,20 +51,10 @@ public class ActiveMQBrokerFeatureTest extends AbstractJmsFeatureTest {
@Test(timeout=5 * 60 * 1000)
public void test() throws Throwable {
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
withinReason(new Runnable() {
public void run() {
assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim());
return true;
}
});
withinReason(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
assertTrue(executeCommand("activemq:bstat").trim().contains("BrokerName = amq-broker"));
return true;
}
});
@ -96,13 +62,11 @@ public class ActiveMQBrokerFeatureTest extends AbstractJmsFeatureTest {
final String nameAndPayload = String.valueOf(System.currentTimeMillis());
produceMessage(nameAndPayload);
executeCommand("activemq:bstat", COMMAND_TIMEOUT, false).trim();
executeCommand("activemq:bstat").trim();
withinReason(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
withinReason(new Runnable() {
public void run() {
assertEquals("JMS_BODY_FIELD:JMSText = " + nameAndPayload, executeCommand("activemq:browse --amqurl tcp://localhost:61616 --user karaf --password karaf -Vbody " + nameAndPayload).trim());
return true;
}
});

View File

@ -17,74 +17,44 @@
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;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.junit.PaxExam;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.composite;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
@RunWith(PaxExam.class)
public class ActiveMQBrokerNdCamelFeatureTest extends AbstractJmsFeatureTest {
@Configuration
public static Option[] configure() {
return append(
editConfigurationFilePut("etc/system.properties", "camel.version", MavenUtils.getArtifactVersion("org.apache.camel.karaf", "apache-camel")),
configure("activemq", "activemq-camel"));
return new Option[] //
{
composite(configure("activemq", "activemq-camel")),
editConfigurationFilePut("etc/system.properties", "camel.version", camelVersion()),
replaceConfigurationFile("etc/activemq.xml", new File(RESOURCE_BASE + "activemq-nd-camel.xml")),
replaceConfigurationFile("etc/org.apache.activemq.server-default.cfg", new File(RESOURCE_BASE + "org.apache.activemq.server-default.cfg"))
};
}
@Test(timeout = 2 * 60 * 1000)
public void test() throws Throwable {
System.err.println(executeCommand("feature:list").trim());
System.err.println(executeCommand("feature:list -i").trim());
assertFeatureInstalled("activemq");
assertTrue("activemq-camel bundle installed", verifyBundleInstalled("org.apache.activemq.activemq-camel"));
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
assertTrue("activemq-camel bundle installed", verifyBundleInstalled("org.apache.activemq.activemq-camel"));
return true;
}
});
// start broker with embedded camel route
String karafDir = System.getProperty("karaf.base");
File target = new File(karafDir + "/etc/activemq.xml");
copyFile(new File(basedir + "/../../../src/test/resources/org/apache/activemq/karaf/itest/activemq-nd-camel.xml"), target);
target = new File(karafDir + "/etc/org.apache.activemq.server-default.cfg");
copyFile(new File(basedir + "/../../../src/test/resources/org/apache/activemq/karaf/itest/org.apache.activemq.server-default.cfg"), target);
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
withinReason(new Runnable() {
public void run() {
getBundle("org.apache.activemq.activemq-camel");
assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim());
return true;
}
});
withinReason(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
assertTrue(executeCommand("activemq:bstat").trim().contains("BrokerName = amq-broker"));
return true;
}
});
withinReason(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
assertTrue("we have camel consumers", executeCommand("activemq:dstat").trim().contains("camel_in"));
return true;
}
});

View File

@ -16,74 +16,54 @@
*/
package org.apache.activemq.karaf.itest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
import java.io.File;
import java.util.concurrent.Callable;
import org.junit.Ignore;
import org.junit.Test;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.MavenUtils;
import org.ops4j.pax.exam.Option;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
//@RunWith(PaxExam.class)
@Ignore
public class ActiveMQBrokerNdExternalCamelFeatureTest extends AbstractJmsFeatureTest {
@Configuration
public static Option[] configure() {
Option[] baseOptions = configure("activemq");
// copy camel.xml into a temporary directory in karaf, so we later can hot-deploy it
baseOptions = append(replaceConfigurationFile("data/tmp/camel.xml", new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/camel.xml")), baseOptions);
baseOptions = append(editConfigurationFilePut("etc/system.properties", "camel.version", MavenUtils.getArtifactVersion("org.apache.camel.karaf", "apache-camel")), baseOptions);
return configureBrokerStart(baseOptions);
return new Option[] //
{
configure("activemq"),
// copy camel.xml into a temporary directory in karaf, so we later can hot-deploy it
replaceConfigurationFile("data/tmp/camel.xml", new File(RESOURCE_BASE + "camel.xml")),
editConfigurationFilePut("etc/system.properties", "camel.version", camelVersion())
};
}
@Ignore("camel.xml from auto deploy directory does not seem to get picked up, no idea why atm")
@Test(timeout = 2 * 60 * 1000)
public void test() throws Throwable {
assertFeatureInstalled("activemq");
executeCommand("feature:repo-add " + getCamelFeatureUrl());
installAndAssertFeature("camel");
installAndAssertFeature("activemq-camel");
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
withinReason(new Runnable() {
public void run() {
assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim());
return true;
}
});
withinReason(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
assertTrue(executeCommand("activemq:bstat").trim().contains("BrokerName = amq-broker"));
return true;
getBundle("org.apache.activemq.activemq-camel");
}
});
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
assertTrue("activemq-camel bundle installed", verifyBundleInstalled("org.apache.activemq.activemq-camel"));
return true;
}
});
assertFeatureInstalled("activemq-camel");
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("Karaf is running in dir: " + karafDir);
System.err.println("Hot deploying Camel application");
copyFile(new File(karafDir + "/data/tmp/camel.xml"), new File(karafDir + "/deploy/camel.xml"));

View File

@ -39,9 +39,12 @@ public class ActiveMQBrokerNdWebConsoleFeatureTest extends ActiveMQBrokerFeature
@Configuration
public static Option[] configure() {
return append(CoreOptions.mavenBundle("commons-codec", "commons-codec").versionAsInProject(),
append(CoreOptions.mavenBundle("commons-httpclient", "commons-httpclient").versionAsInProject(),
configure("activemq-broker")));
return new Option[] //
{
CoreOptions.mavenBundle("commons-codec", "commons-codec").versionAsInProject(),
CoreOptions.mavenBundle("commons-httpclient", "commons-httpclient").versionAsInProject(),
configure("activemq-broker")
};
}
@Override

View File

@ -16,50 +16,43 @@
*/
package org.apache.activemq.karaf.itest;
import java.io.File;
import java.util.Date;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.junit.PaxExam;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
import java.io.File;
import java.util.Date;
import java.util.concurrent.TimeUnit;
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;
@RunWith(PaxExam.class)
public class ActiveMQBrokerRuntimeConfigTest extends AbstractJmsFeatureTest {
@Configuration
public static Option[] configure() {
return append(editConfigurationFilePut("etc/org.apache.activemq.server-default.cfg", "config.check", "false"),
configureBrokerStart(
append(replaceConfigurationFile("data/tmp/modified-config.xml",
new File(basedir + "/src/test/resources/org/apache/activemq/karaf/itest/activemq-runtime-config-mod.xml")),
configure("activemq")), "activemq-runtime-config"));
return new Option[] //
{
configure("activemq"),
editConfigurationFilePut("etc/org.apache.activemq.server-default.cfg", "config.check", "false"),
replaceConfigurationFile("data/tmp/modified-config.xml",
new File(RESOURCE_BASE + "activemq-runtime-config-mod.xml")),
configureBrokerStart("activemq-runtime-config")
};
}
@Test(timeout = 2 * 60 * 1000)
public void test() throws Throwable {
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
withinReason(new Runnable() {
public void run() {
assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim());
return true;
}
});
withinReason(new Callable<Boolean>(){
@Override
public Boolean call() throws Exception {
assertTrue("3MB limit", executeCommand("activemq:query").trim().contains("MemoryLimit = 3145728"));
return true;
}
});
@ -73,11 +66,9 @@ public class ActiveMQBrokerRuntimeConfigTest extends AbstractJmsFeatureTest {
copyFile(new File(karafDir + "/data/tmp/modified-config.xml"), target);
System.err.println("new mod at: " + new Date(target.lastModified()));
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
withinReason(new Runnable() {
public void run() {
assertTrue("4MB limit", executeCommand("activemq:query").trim().contains("MemoryLimit = 4194304"));
return true;
}
});

View File

@ -19,8 +19,8 @@ package org.apache.activemq.karaf.itest;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
@RunWith(PaxExam.class)
@ -28,7 +28,10 @@ public class ActiveMQClientBundleTest extends AbstractFeatureTest {
@Configuration
public static Option[] configure() {
return configure("activemq-client");
return new Option[] //
{
configure("activemq-client")
};
}
@Test(timeout = 2 * 60 * 1000)

View File

@ -22,103 +22,84 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.CoreOptions;
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.PerMethod;
import org.osgi.framework.Bundle;
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class ObrFeatureTest extends AbstractFeatureTest {
@Configuration
public static Option[] configure() {
Option[] options = append(
editConfigurationFilePut("etc/system.properties", "camel.version", MavenUtils.getArtifactVersion("org.apache.camel.karaf", "apache-camel")),
configure("obr"));
// can't see where these deps die in a paxexam container - vanilla distro unpack can install war feature ok
options = append(CoreOptions.mavenBundle("org.apache.xbean", "xbean-bundleutils").versionAsInProject(), options);
options = append(CoreOptions.mavenBundle("org.apache.xbean", "xbean-asm-util").versionAsInProject(), options);
return append(CoreOptions.mavenBundle("org.apache.xbean", "xbean-finder").versionAsInProject(), options);
return new Option[] //
{
configure("obr"),
editConfigurationFilePut("etc/system.properties", "camel.version", camelVersion()),
};
}
@Test(timeout=5 * 60 * 1000)
public void testWar() throws Throwable {
installAndAssertFeature("war");
}
@Test(timeout=5 * 60 * 1000)
@Test(timeout = 5 * 60 * 1000)
public void testClient() throws Throwable {
installAndAssertFeature("activemq-client");
}
@Test(timeout=5 * 60 * 1000)
@Test(timeout = 5 * 60 * 1000)
public void testActiveMQ() throws Throwable {
installAndAssertFeature("activemq");
}
@Test(timeout=5 * 60 * 1000)
@Test(timeout = 5 * 60 * 1000)
public void testBroker() throws Throwable {
installAndAssertFeature("activemq-broker");
}
@Test(timeout=5 * 60 * 1000)
@Test(timeout = 5 * 60 * 1000)
public void testCamel() throws Throwable {
executeCommand("feature:repo-add " + getCamelFeatureUrl());
installAndAssertFeature("activemq-camel");
}
@Test(timeout=5 * 60 * 1000)
@Test(timeout = 5 * 60 * 1000)
public void testClientWithSpring31() throws Throwable {
executeCommand("feature:install spring/3.1.4.RELEASE");
installAndAssertFeature("activemq-client");
verifyBundleInstalledAndRegisteredServices("activemq-osgi", 2);
testWithSpringVersion("3.1.4.RELEASE");
}
@Test(timeout=5 * 60 * 1000)
@Test(timeout = 5 * 60 * 1000)
public void testClientWithSpring32() throws Throwable {
executeCommand("feature:install spring/3.2.14.RELEASE_1");
installAndAssertFeature("activemq-client");
verifyBundleInstalledAndRegisteredServices("activemq-osgi", 2);
testWithSpringVersion("3.2.14.RELEASE_1");
}
@Test(timeout=5 * 60 * 1000)
@Test(timeout = 5 * 60 * 1000)
public void testClientWithSpring40() throws Throwable {
executeCommand("feature:install spring/4.0.7.RELEASE_3");
installAndAssertFeature("activemq-client");
verifyBundleInstalledAndRegisteredServices("activemq-osgi", 2);
testWithSpringVersion("4.0.7.RELEASE_3");
}
@Test(timeout=5 * 60 * 1000)
@Test(timeout = 5 * 60 * 1000)
public void testClientWithSpring41() throws Throwable {
executeCommand("feature:install spring/4.1.7.RELEASE_2");
installAndAssertFeature("activemq-client");
verifyBundleInstalledAndRegisteredServices("activemq-osgi", 2);
testWithSpringVersion("4.1.7.RELEASE_2");
}
@Test(timeout=5 * 60 * 1000)
@Test(timeout = 5 * 60 * 1000)
public void testClientWithSpring42() throws Throwable {
executeCommand("feature:install spring/4.2.2.RELEASE_1");
testWithSpringVersion("4.2.2.RELEASE_1");
}
private void testWithSpringVersion(String version) throws Exception, Throwable {
featuresService.installFeature("spring", version);
installAndAssertFeature("activemq-client");
verifyBundleInstalledAndRegisteredServices("activemq-osgi", 2);
}
public boolean verifyBundleInstalledAndRegisteredServices(final String bundleName, final int numberOfServices) throws Exception {
boolean found = false;
for (final Bundle bundle : bundleContext.getBundles()) {
LOG.debug("Checking: " + bundle.getSymbolicName());
if (bundle.getSymbolicName().contains(bundleName)) {
Assert.assertEquals(Bundle.ACTIVE, bundle.getState());
// Assert that the bundle has registered some services via blueprint
Assert.assertNotNull(bundle.getRegisteredServices());
// Assert that the bundle has registered the correct number of services
Assert.assertEquals(numberOfServices, bundle.getRegisteredServices().length);
found = true;
break;
}
}
return found;
private void verifyBundleInstalledAndRegisteredServices(final String bundleName,
final int numberOfServices)
throws Exception {
Bundle bundle = getBundle(bundleName);
Assert.assertEquals(Bundle.ACTIVE, bundle.getState());
// Assert that the bundle has registered some services via blueprint
Assert.assertNotNull(bundle.getRegisteredServices());
// Assert that the bundle has registered the correct number of services
Assert.assertEquals(numberOfServices, bundle.getRegisteredServices().length);
}
}

View File

@ -135,7 +135,7 @@
<jaxb-basics-version>0.6.4</jaxb-basics-version>
<stompjms-version>1.19</stompjms-version>
<pax-exam-version>4.6.0</pax-exam-version>
<pax-exam-version>4.9.1</pax-exam-version>
<paxexam-karaf-container-version>1.0.0</paxexam-karaf-container-version>
<pax-runner-version>1.8.6</pax-runner-version>
<pax-url-version>2.4.3</pax-url-version>