0

私が取り組んでいるプロジェクトでは、複数の Karaf コンテナーで実行される PaxExam 統合テストを作成する必要があります。

アイデアは、PaxExam を拡張/構成して Karaf コンテナ (またはそれ以上) を起動し、そこにバンドルのバウンスを展開してから、機能をテストするテスト Karaf コンテナを起動する方法を見つけることです。

これは、パフォーマンス テストなどを検証するために必要です。

誰かそれについて何か知っていますか?それは PaxExam で実際に可能ですか?

4

1 に答える 1

1

この興味深い記事を見つけた後、私は自分で答えを書きます。

特に、「Karaf シェルの使用」セクションと「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 シェルでコマンドを実行できる次のコードを提案しています。

@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.
}
于 2015-03-22T15:33:33.493 に答える