对于我正在进行的项目,我们有必要编写运行在多个Karaf容器上的PaxExam集成测试。
这个想法是找到一种方法来扩展/配置PaxExam以启动一个Karaf容器(或更多)并在那里部署一堆bundle,然后启动测试Karaf容器,然后测试该功能。
我们需要这个来验证性能测试和其他事情。
有人知道这件事吗?这在PaxExam中实际可行吗?
答案 0 :(得分:1)
在找到这篇有趣的文章之后,我自己写了答案。
特别要看一下使用Karaf Shell 和 Karaf中的分布式集成测试
部分http://planet.jboss.org/post/advanced_integration_testing_with_pax_exam_karaf
这基本上就是文章所说的:
首先,您必须更改测试探针头,允许动态包
@ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
probe.setHeader(Constants.DYNAMICIMPORT_PACKAGE, "*;status=provisional");
return probe;
}
之后,本文建议以下代码能够在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;
}
然后,其余的都是微不足道的,你将不得不实现一个能够启动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.
}