Search in sources :

Example 1 with LogWatchStreamProcessor

use of de.flapdoodle.embed.process.io.LogWatchStreamProcessor in project gora by apache.

the class GoraMongodbAuthenticationTestDriver method runScriptAndWait.

private void runScriptAndWait(String scriptText, String token, String[] failures, String dbName, String username, String password) throws IOException {
    IStreamProcessor mongoOutput;
    if (!isEmpty(token)) {
        mongoOutput = new LogWatchStreamProcessor(token, (failures != null) ? new HashSet<>(asList(failures)) : Collections.emptySet(), namedConsole("[mongo shell output]"));
    } else {
        mongoOutput = new NamedOutputStreamProcessor("[mongo shell output]", console());
    }
    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(Command.Mongo).processOutput(new ProcessOutput(mongoOutput, namedConsole("[mongo shell error]"), console())).build();
    MongoShellStarter starter = MongoShellStarter.getInstance(runtimeConfig);
    final File scriptFile = writeTmpScriptFile(scriptText);
    final MongoShellConfigBuilder builder = new MongoShellConfigBuilder();
    if (!isEmpty(dbName)) {
        builder.dbName(dbName);
    }
    if (!isEmpty(username)) {
        builder.username(username);
    }
    if (!isEmpty(password)) {
        builder.password(password);
    }
    starter.prepare(builder.scriptName(scriptFile.getAbsolutePath()).version(mongodConfig.version()).net(mongodConfig.net()).build()).start();
    if (mongoOutput instanceof LogWatchStreamProcessor) {
        ((LogWatchStreamProcessor) mongoOutput).waitForResult(INIT_TIMEOUT_MS);
    }
}
Also used : IStreamProcessor(de.flapdoodle.embed.process.io.IStreamProcessor) NamedOutputStreamProcessor(de.flapdoodle.embed.process.io.NamedOutputStreamProcessor) ProcessOutput(de.flapdoodle.embed.process.config.io.ProcessOutput) LogWatchStreamProcessor(de.flapdoodle.embed.process.io.LogWatchStreamProcessor) File(java.io.File) IRuntimeConfig(de.flapdoodle.embed.process.config.IRuntimeConfig)

Aggregations

IRuntimeConfig (de.flapdoodle.embed.process.config.IRuntimeConfig)1 ProcessOutput (de.flapdoodle.embed.process.config.io.ProcessOutput)1 IStreamProcessor (de.flapdoodle.embed.process.io.IStreamProcessor)1 LogWatchStreamProcessor (de.flapdoodle.embed.process.io.LogWatchStreamProcessor)1 NamedOutputStreamProcessor (de.flapdoodle.embed.process.io.NamedOutputStreamProcessor)1 File (java.io.File)1