use of de.flapdoodle.embed.process.config.IRuntimeConfig in project gora by apache.
the class GoraMongodbTestDriver method setUpClass.
/**
* Initiate the MongoDB server on the default port
*/
@Override
public void setUpClass() throws IOException {
IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, log).processOutput(ProcessOutput.getDefaultInstanceSilent()).build();
MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);
int port = Network.getFreeServerPort();
IMongodConfig mongodConfig = new MongodConfigBuilder().version(version).net(new Net(port, Network.localhostIsIPv6())).build();
// Store Mongo server "host:port" in Hadoop configuration
// so that MongoStore will be able to get it latter
conf.set(MongoStoreParameters.PROP_MONGO_SERVERS, "127.0.0.1:" + port);
log.info("Starting embedded Mongodb server on {} port.", port);
try {
_mongodExe = runtime.prepare(mongodConfig);
_mongod = _mongodExe.start();
_mongo = new MongoClient("localhost", port);
} catch (Exception e) {
log.error("Error starting embedded Mongodb server... tearing down test driver.");
tearDownClass();
}
}
use of de.flapdoodle.embed.process.config.IRuntimeConfig 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);
}
}
use of de.flapdoodle.embed.process.config.IRuntimeConfig in project raml-module-builder by folio-org.
the class PostgresClient method startEmbeddedPostgres.
/**
* Start an embedded PostgreSQL using the configuration of {@link #getConnectionConfig()}.
* It also sets embedded mode to true, see {@link #setIsEmbedded(boolean)}, but
* doesn't change the configuration.
*
* @throws IOException when starting embedded PostgreSQL fails
*/
public void startEmbeddedPostgres() throws IOException {
// starting Postgres
embeddedMode = true;
if (postgresProcess == null || !postgresProcess.isProcessRunning()) {
// turns off the default functionality of unzipping on every run.
IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(Command.Postgres).artifactStore(new NonCachedPostgresArtifactStoreBuilder().defaults(Command.Postgres).download(new PostgresDownloadConfigBuilder().defaultsForCommand(Command.Postgres).build())).build();
PostgresStarter<PostgresExecutable, PostgresProcess> runtime = PostgresStarter.getInstance(runtimeConfig);
int port = postgreSQLClientConfig.getInteger(PORT);
String username = postgreSQLClientConfig.getString(_USERNAME);
String password = postgreSQLClientConfig.getString(_PASSWORD);
String database = postgreSQLClientConfig.getString(DATABASE);
String locale = "en_US.UTF-8";
String OS = System.getProperty("os.name").toLowerCase();
if (OS.indexOf("win") >= 0) {
locale = "american_usa";
}
final PostgresConfig config = new PostgresConfig(Version.Main.V10, new AbstractPostgresConfig.Net(DEFAULT_IP, port), new AbstractPostgresConfig.Storage(database), new AbstractPostgresConfig.Timeout(20000), new AbstractPostgresConfig.Credentials(username, password));
config.getAdditionalInitDbParams().addAll(Arrays.asList("-E", "UTF-8", "--locale", locale));
postgresProcess = runtime.prepare(config).start();
log.info("embedded postgress started....");
} else {
log.info("embedded postgress is already running...");
}
}
use of de.flapdoodle.embed.process.config.IRuntimeConfig in project logging-log4j2 by apache.
the class MongoDb3TestRule method getMongodStarter.
private static MongodStarter getMongodStarter(final LoggingTarget loggingTarget) {
if (loggingTarget == null) {
return MongodStarter.getDefaultInstance();
}
switch(loggingTarget) {
case NULL:
final Logger logger = LoggerFactory.getLogger(MongoDb3TestRule.class.getName());
final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, logger).processOutput(ProcessOutput.getDefaultInstanceSilent()).build();
return MongodStarter.getInstance(runtimeConfig);
case CONSOLE:
return MongodStarter.getDefaultInstance();
default:
throw new NotImplementedException(loggingTarget.toString());
}
}
use of de.flapdoodle.embed.process.config.IRuntimeConfig in project logging-log4j2 by apache.
the class MongoDb4TestRule method getMongodStarter.
private static MongodStarter getMongodStarter(final LoggingTarget loggingTarget) {
if (loggingTarget == null) {
return MongodStarter.getDefaultInstance();
}
switch(loggingTarget) {
case NULL:
final Logger logger = LoggerFactory.getLogger(MongoDb4TestRule.class.getName());
final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, logger).processOutput(ProcessOutput.getDefaultInstanceSilent()).build();
return MongodStarter.getInstance(runtimeConfig);
case CONSOLE:
return MongodStarter.getDefaultInstance();
default:
throw new NotImplementedException(loggingTarget.toString());
}
}
Aggregations