[英]Pax Exam how to start multiple containers
for a project i'm working on, we have the necessity to write PaxExam integration tests which run over multiple Karaf containers. 对于我正在从事的项目,我们有必要编写在多个Karaf容器上运行的PaxExam集成测试。
The idea would be finding a way to extend/configure PaxExam to start-up a Karaf container (or more) and deploying there a bounce of bundles, and then start the test Karaf container which will then test the functionality. 这个想法将是找到一种扩展/配置PaxExam的方法,以启动一个Karaf容器(或更多),并在其中部署一束捆绑,然后启动测试Karaf容器,然后对其进行功能测试。
We need this to verify performance tests and other things. 我们需要它来验证性能测试和其他内容。
Does someone know anything about that? 有人知道吗? Is that actually possible in PaxExam? 在PaxExam中实际上可行吗?
I write the answer by myself, after having found this interesting article. 找到这篇有趣的文章后,我自己写答案。
In particular have a look at the sections Using the Karaf Shell and Distributed integration tests in Karaf 特别要看一下在Karaf中使用Karaf Shell和分布式集成测试部分。
http://planet.jboss.org/post/advanced_integration_testing_with_pax_exam_karaf http://planet.jboss.org/post/advanced_integration_testing_with_pax_exam_karaf
This is basically what the article says: 这基本上就是文章所说的:
first of all you have to change the test probe header, allowing the dynamic-package 首先,您必须更改测试探针头,以允许动态打包
@ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
probe.setHeader(Constants.DYNAMICIMPORT_PACKAGE, "*;status=provisional");
return probe;
}
After that, the article suggests the following code that is able to execute commands in the Karaf shell 之后,本文提出了以下能够在Karaf shell中执行命令的代码
@Inject
CommandProcessor commandProcessor;
protected String executeCommands(final String ...commands) {
String response;
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final PrintStream printStream = new PrintStream(byteArrayOutputStream);
final CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err);
FutureTask<string> commandFuture = new FutureTask<string>(
new Callable<string>() {
public String call() {
try {
for(String command:commands) {
System.err.println(command);
commandSession.execute(command);
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
return byteArrayOutputStream.toString();
}
});
try {
executor.submit(commandFuture);
response = commandFuture.get(COMMAND_TIMEOUT, TimeUnit.MILLISECONDS);
} catch (Exception e) {
e.printStackTrace(System.err);
response = "SHELL COMMAND TIMED OUT: ";
}
return response;
}
Then, the rest is kind of trivial, you will have to implement a layer able to start-up a child instance of Karaf 然后,剩下的事情就微不足道了,您将必须实现一个能够启动Karaf子实例的层。
public void createInstances() {
//Install broker feature that is provided by FuseESB
executeCommands("admin:create --feature broker brokerChildInstance");
//Install producer feature that provided by imaginary feature repo.
executeCommands("admin:create --featureURL mvn:imaginary/repo/1.0/xml/features --feature producer producerChildInstance");
//Install producer feature that provided by imaginary feature repo.
executeCommands("admin:create --featureURL mvn:imaginary/repo/1.0/xml/features --feature consumer consumerChildInstance");
//start child instances
executeCommands("admin:start brokerChildInstance");
executeCommands("admin:start producerChildInstance");
executeCommands("admin:start consumerChildInstance");
//You will need to destroy the child instances once you are done.
//Using @After seems the right place to do that.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.