【问题标题】:Pax Exam how to start multiple containersPax Exam 如何启动多个容器
【发布时间】:2015-05-22 19:35:08
【问题描述】:

对于我正在进行的项目,我们有必要编写 PaxExam 集成测试,这些测试在多个 Karaf 容器上运行。

我们的想法是找到一种方法来扩展/配置 PaxExam 以启动一个 Karaf 容器(或更多)并在那里部署一系列捆绑包,然后启动测试 Karaf 容器,该容器随后将测试功能。

我们需要这个来验证性能测试和其他事情。

有人知道吗?这在 PaxExam 中真的可能吗?

【问题讨论】:

    标签: deployment osgi karaf pax-exam dosgi


    【解决方案1】:

    在找到这篇有趣的文章后,我自己写了答案。

    特别是查看使用 Karaf ShellKaraf 中的分布式集成测试

    部分

    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.
    }
    

    【讨论】:

    • 不确定谁是反对者,但他不明白这一点。感谢您的链接和答案。
    猜你喜欢
    • 2014-03-17
    • 2012-08-14
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    • 2016-02-28
    • 2012-08-06
    相关资源
    最近更新 更多