Code Monkey home page Code Monkey logo

ebean-test-containers's People

Contributors

breglerj avatar dependabot[bot] avatar rbygrave avatar rob-bygrave avatar rpraml avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

breglerj foconis

ebean-test-containers's Issues

ENH: Add support for a fastStartMode where ... if its Mode.Create & the container is running & we are using fast start ...

if its Mode.Create and the container is running and we are using fast start mode ...

Just check the existence of the database. If it exists then assume that it has been created correctly (users, extensions etc) and return.

This would then skip the normal checks ... does the user exist, create db extensions if they don't exist etc.

This is a mode that should only apply for local development and not on a CI server.

Add support for executing initial SQL script files after the database is created

    PostgresConfig config = new PostgresConfig("10.1");
    config.setPort("9823");
    config.setUser("main_user");
    config.setDbName("main_db");

    // A sql file to execute after creating the database
    config.setDbInitSqlFile("init-main-database.sql");

    config.setExtraDb("extra");
    // A sql file to execute after creating the extra database
    config.setExtraDbInitSqlFile("init-extra-database.sql");

    PostgresContainer container = new PostgresContainer(config);
    container.startWithDropCreate();

ENH: Add ability for containers to automatically stop via JVM shutdown hook - shutdown: stop or shutdown: remove

So we can set shutdownHookMode to be remove or stop to either stop and remove the container or just stop the container on JVM shutdown.

The intention is that in a CI pipeline it can be preferred to have that behaviour where the container is stopped (& maybe removed). In the CI build the JVM shutdown should match the end of testing. This is an alternative to hooking into the maven and gradle build lifecycle.

Add support for extra database and extra database user (for Postgres)

So the motivation is that we want to make it nice from a testing perspective when the application under development uses multiple databases.

This will typically be exposed via ebean-test-config (application-test.yml) for code wise:

    PostgresConfig config = new PostgresConfig("10.1");
    config.setContainerName("junk_postgres10");
    config.setPort("9823");
    config.setExtensions("hstore,pgcrypto");

    // The primary user and database 
    config.setUser("main_user");
    config.setDbName("main_db");

    // Creating an extra user and database 
    config.setExtraDbUser("extra_user");
    config.setExtraDb("extra_db");

    PostgresContainer container = new PostgresContainer(config);
    container.startWithCreate();
    ...

With shutdown "none" ... do not register a shutdown hook

This means we can have valid values for shutdown of

  • stop
  • remove
  • none

At the moment if we put none it will register the shutdown hook so it acts like stop. So we have to comment out shutdown config rather than set it to none.

ENH: Add support to read System property docker_run_with or environment variable DOCKER_RUN_WITH

  private static String defaultRunWith() {
    String runWith = System.getenv("DOCKER_RUN_WITH");
    return System.getProperty("docker_run_with", runWith);
  }

This means that in docker-run.properties we can specify many containers (like postgres, mysql, sqlserver) ... and then specify via system property which container to run. Only running the container we choose.

The intention is to be able to easily run Ebean tests against one of several different DB containers and control which one to run against via the system property.


What this means is that something (like ebean-docker-run) can set the system property docker_run_with and there by only start that container (and not say postgres, mysql etc) and run the tests against that DB.

ENH: Add support for Redis container

ebean:
  test:
    redis: latest
#    useDocker: false
#    shutdown: stop # stop | remove
    platform: h2 # h2, postgres, mysql, oracle, sqlserver, sqlite
    ddlMode: dropCreate # none | dropCreate | create | migration | createOnly | migrationDropCreate
    dbName: myapp

ENH: Add support for CockroachDB - community edition, no users, default v19.1.3

Defaults to:

  • image version v19.1.3
  • container name ut_cockroach
  • port 26257
  • admin port 8888
    CockroachConfig config = new CockroachConfig() ;//  default v19.1.3
    // config.setContainerName("junk_roach"); // default ut_cockroach
    config.setDbName("my_app");
    // don't set user ... 

    CockroachContainer container = new CockroachContainer(config);

    container.startWithDropCreate();

    try (Connection connection = container.createConnection()) {
      try (Statement statement = connection.createStatement()) {
        statement.execute("drop table if exists foobar");
        statement.execute("create table foobar (acol integer)");
        statement.execute("insert into foobar (acol) values (42)");
      }
    }

    container.stopRemove();

ENH: Add support for NuoDB community edition

This starts the 3 containers that we need for NuoDB, performs the various waits that we need plus the setup of the database schema and user with grants etc.

This has the ebean-test-docker "fast start" option so it detects when the container and database is already running and skips various parts as necessary.

The NuoDB docker containers are fast coming up and fast drop and re-create - impressive and nice!!

Example programmatic use

  @Test
  public void start_executeSql_stop() {

    NuoDBConfig config = new NuoDBConfig();
    //config.setContainerName("ut_nuodb");
    //config.setAdminUser("dba");
    //config.setAdminPassword("dba");
    //config.setDbName("testdb");
    config.setSchema("my_app");
    config.setUser("my_app");
    config.setPassword("test");

    NuoDBContainer container = new NuoDBContainer(config);
    container.start();

    try (Connection connection = config.createConnection()) {
      final Random random = new Random();

      exeSql(connection, "drop table if exists test_junk");
      exeSql(connection, "create table test_junk (acol integer)");
      exeSql(connection, "insert into test_junk (acol) values (" + random.nextInt() + ")");
      exeSql(connection, "insert into test_junk (acol) values (" + random.nextInt() + ")");
      exeSql(connection, "insert into test_junk (acol) values (" + random.nextInt() + ")");

      connection.commit();

    } catch (SQLException e) {
      throw new RuntimeException(e);

    } finally {
      //container.stopRemove();
    }
  }

  private void exeSql(Connection connection, String sql) throws SQLException {
    try (PreparedStatement st = connection.prepareStatement(sql)) {
      st.execute();
    }
  }

}

ENH: Add SQL Server container support

Default parameters used:

sqlserver.container=ut_sqlserver
sqlserver.dbName=test_db
sqlserver.dbUser=test_user
sqlserver.dbPassword=SqlS3rv#r
sqlserver.dbPort=1433

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.