com.wix.mysql.EmbeddedMysql Java Examples

The following examples show how to use com.wix.mysql.EmbeddedMysql. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestMetastoreDatabaseServer.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
TestMetastoreDatabaseServer(Config dbConfig) throws Exception {
  Config realConfig = dbConfig.withFallback(getDefaultConfig()).getConfig(CONFIG_PREFIX);
  this.embeddedMysqlEnabled = realConfig.getBoolean(EMBEDDED_MYSQL_ENABLED_KEY);
  this.dbUserName = realConfig.getString(DBUSER_NAME_KEY);
  this.dbUserPassword = realConfig.getString(DBUSER_PASSWORD_KEY);
  this.dbHost = this.embeddedMysqlEnabled ? "localhost" : realConfig.getString(DBHOST_KEY);
  this.dbPort = this.embeddedMysqlEnabled ? chooseRandomPort() : realConfig.getInt(DBPORT_KEY);

  this.log.error("Starting with config: embeddedMysqlEnabled={} dbUserName={} dbHost={} dbPort={}",
                this.embeddedMysqlEnabled,
                this.dbUserName,
                this.dbHost,
                this.dbPort);

  config = MysqldConfig.aMysqldConfig(Version.v8_latest)
      .withPort(this.dbPort)
      .withUser(this.dbUserName, this.dbUserPassword)
      .build();
  if (this.embeddedMysqlEnabled) {
    testingMySqlServer = EmbeddedMysql.anEmbeddedMysql(config).start();
  }
  else {
    testingMySqlServer = null;
  }
}
 
Example #2
Source File: EmbeddedSupplier.java    From ndbc with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource<PreparedStatement, Row> get() {
  log.info("Starting embedded mysql " + version + " on port " + config.port());

  final String password = config.password().orElseGet(() -> {
    throw new UnsupportedOperationException("Embedded mysql requires a password");
  });

  final DownloadConfig downloadConfig = DownloadConfig.aDownloadConfig()
      .withCacheDir(Paths.get(System.getProperty("user.home"), ".ndbc", "embedded_mysql").toString())
      .build();

  final MysqldConfig mysqldConfig = MysqldConfig.aMysqldConfig(version)
      .withPort(config.port())
      .withUser(config.user(), password)
      .build();

  final Builder builder = EmbeddedMysql.anEmbeddedMysql(mysqldConfig, downloadConfig);

  config.database().ifPresent(db -> builder.addSchema(SchemaConfig.aSchemaConfig(db).build()));

  final EmbeddedMysql mysql = builder.start();

  Runtime.getRuntime().addShutdownHook(new Thread(() -> mysql.stop()));

  log.info("mysql " + version + " started");

  DataSource<PreparedStatement, Row> underlying = DataSource.fromConfig(config.embedded(Optional.empty()));
  return new ProxyDataSource<PreparedStatement, Row>(underlying) {
    @Override
    public Config config() {
      return EmbeddedSupplier.this.config;
    }
  };
}