ebean-orm / ebean-test-containers Goto Github PK
View Code? Open in Web Editor NEWAbility to control docker containers. e.g. Postgres running as docker container for testing
License: Apache License 2.0
Ability to control docker containers. e.g. Postgres running as docker container for testing
License: Apache License 2.0
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.
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();
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.
This is a pain but makes sense given the extraDb property names and related datasource property names. That is, this change makes them consistent.
This is a PITA for people directly using ebean-test-docker but I believe most people will be using this indirectly via ebean-test-config.
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();
...
To preform stop of containers without removing the containers (as opposed to changing the stopMode).
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
.
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.
So the NuoDB docker containers only expect to run with 1 database. This means that generally if we are building/testing multiple applications then from a testing perspective we should just share a common database and put each application into it's own schema.
Also we can make the startup faster and fix use for ebean-test.
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
It occasionally fails at this level waiting for Postgres container.
This is the new location for SQL Server docker images.
Doing this to more closely match the scenario with AWS Postgres RDS where the database user has this role.
For example, this RDS database owner role can be different to the application role/user ... and part of database setup / migration creates the application role/user.
So "mariadb" is the platform name that will use a MariaDB docker image (and otherwise look like MySql).
So these are SQL scripts that can be included in src/test/resources (or a file system path) that will be executed against the newly created DB.
Hi, nice project but does https://github.com/testcontainers/testcontainers-java not the same ?
Defaults to:
v19.1.3
ut_cockroach
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();
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!!
@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();
}
}
}
sath89/oracle-12c taken down by Oracle.
Could look to upgrade to https://hub.docker.com/r/quillbuilduser/oracle-18-xe ... but system login doesn't work - need login as sysdba so more painful to assert when DB is ready etc.
// find /docker-run.properties
// ... and start containers as per configuration.
AutoStart.run()
Default parameters used:
sqlserver.container=ut_sqlserver
sqlserver.dbName=test_db
sqlserver.dbUser=test_user
sqlserver.dbPassword=SqlS3rv#r
sqlserver.dbPort=1433
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.