简体   繁体   English

Pax考试如何启动多个容器

[英]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.

相关问题 如何仅使用一个代码库对多个容器使用多种配置? - How to use multiple configurations for multiple containers with only one codebase? 如何在许可下部署 docker 容器 - How to deploy docker containers on permise 不同Docker容器上的Rails和Nginx(如何在容器之间共享数据) - Rails and Nginx on different Docker containers (how share data between containers) 通过Jenkins作业将多个战争部署到多个远程容器 - Deploy multiple wars to multiple remote containers through Jenkins job 如何正确重启Docker容器进行部署过程? - How to correctly restart Docker containers for deployment process? 如何在单个Docker容器中部署Angular应用程序和REST Api? - How to deploy an Angular application and a REST Api in individual docker containers? 将 php 应用程序迁移到 Kubernetes - 如何在容器中提取代码? - Migrate php application to Kubernetes - How to pull code in containers? 如何让 ECS 容器访问私有 git 存储库? - How do I give ECS containers access to a private git repo? 如何在引擎厂上启动sidekiq - how to start sidekiq on engineyard 如何在Tomcat启动时设置数据库 - How to setup database on tomcat start
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM