Skip to content

Commit

Permalink
Merge pull request #2688 from ebean-orm/feature/test-docker-52
Browse files Browse the repository at this point in the history
Bump to ebean-test-docker 5.3
  • Loading branch information
rbygrave authored May 12, 2022
2 parents 4b26048 + 317ad8d commit c5940da
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 76 deletions.
31 changes: 5 additions & 26 deletions ebean-test/src/main/java/io/ebean/test/config/platform/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.ebean.datasource.DataSourceConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;

import java.util.Properties;

/**
Expand All @@ -18,7 +18,7 @@ class Config {
* Common optional docker parameters that we just transfer to docker properties.
*/
private static final String[] DOCKER_TEST_PARAMS = {"fastStartMode", "inMemory", "initSqlFile", "seedSqlFile", "adminUser", "adminPassword", "extraDb", "extraDb.dbName", "extraDb.username", "extraDb.password", "extraDb.initSqlFile", "extraDb.seedSqlFile"};
private static final String[] DOCKER_PLATFORM_PARAMS = {"containerName", "image", "internalPort", "startMode", "stopMode", "shutdown", "maxReadyAttempts", "tmpfs", "collation", "characterSet"};
private static final String[] DOCKER_PLATFORM_PARAMS = {"containerName", "image", "internalPort", "startMode", "shutdownMode", "maxReadyAttempts", "tmpfs", "collation", "characterSet"};

private static final String DDL_MODE_OPTIONS = "dropCreate, create, none, migration, createOnly or migrationDropCreate";

Expand Down Expand Up @@ -388,11 +388,10 @@ private void initDockerProperties() {
}

private void setDockerOptionalParameters() {

// check for shutdown mode on all containers
String mode = properties.getProperty("ebean.test.shutdown");
if (mode != null && !ignoreDockerShutdown()) {
dockerProperties.setProperty(dockerKey("shutdown"), mode);
String mode = properties.getProperty("ebean.test.shutdownMode");
if (mode != null) {
dockerProperties.setProperty(dockerKey("shutdownMode"), mode);
}
for (String key : DOCKER_TEST_PARAMS) {
String val = getKey(key, null);
Expand All @@ -410,26 +409,6 @@ private void setDockerOptionalParameters() {
}
}

/**
* For local development we might want to ignore docker shutdown.
* <p>
* So we just want the shutdown mode to be used on the CI server.
*/
boolean ignoreDockerShutdown() {
String localDev = properties.getProperty("ebean.test.localDevelopment", "~/.ebean/ignore-docker-shutdown");
return ignoreDockerShutdown(localDev);
}

boolean ignoreDockerShutdown(String localDev) {

if (localDev.startsWith("~/")) {
File homeDir = new File(System.getProperty("user.home"));
return new File(homeDir, localDev.substring(2)).exists();
}

return new File(localDev).exists();
}

private String dockerKey(String key) {
return dockerPlatform + "." + key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class ElasticSearchSetup {

private static final String[] DOCKER_PARAMS = {"containerName", "image", "internalPort", "startMode", "shutdown"};
private static final String[] DOCKER_PARAMS = {"containerName", "image", "internalPort", "startMode", "shutdownMode"};

private final Properties config;

Expand All @@ -30,9 +30,9 @@ void run() {

private Properties populateDockerProperties(String version) {
PropertiesBuilder properties = new PropertiesBuilder();
String mode = config.getProperty("ebean.test.shutdown");
String mode = config.getProperty("ebean.test.shutdownMode");
if (mode != null) {
properties.set("shutdown", mode);
properties.set("shutdownMode", mode);
}

properties.set("version", version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
/**
* A variation of Postgres that expected Postgis extension support.
*
* Uses mdillon/postgis image by default.
* Uses postgis/postgis image by default.
*/
class PostgisSetup implements PlatformSetup {

@Override
public Properties setup(Config config) {

int defaultPort = config.isUseDocker() ? 7432 : 5432;

config.setDockerPlatform("postgres");
Expand All @@ -27,20 +26,17 @@ public Properties setup(Config config) {
config.urlAppend("?currentSchema=" + schema);
}
config.datasourceDefaults();

return dockerProperties(config);
}

private Properties dockerProperties(Config config) {

if (!config.isUseDocker()) {
return new Properties();
}

config.setExtensions("hstore,pgcrypto,postgis");
config.setDockerImage("mdillon/postgis");
config.setDockerContainerName("postgis");
config.setDockerVersion("10");
config.setDockerContainerName("ut_postgis");
config.setDockerImage("postgis/postgis");
config.setDockerVersion("14");
return config.getDockerProperties();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.ebeaninternal.api.DbOffline;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.util.Properties;
Expand Down Expand Up @@ -140,42 +139,6 @@ void extraDbProperties_withExtraDbOptions() {
assertThat(centralProps.getProperty("datasource.central.username")).isEqualTo("central");
}

@Test
void ignoreDockerShutdown() {
Properties sourceProperties = new Properties();
DatabaseConfig serverConfig = new DatabaseConfig();
serverConfig.loadFromProperties(sourceProperties);

Config config = new Config("main", "postgres", "main", serverConfig);

assertThat(config.ignoreDockerShutdown("./src/test/resources/logback-test.xml")).isTrue();
assertThat(config.ignoreDockerShutdown("./src/test/resources/file-does-not-exist")).isFalse();
}

@Disabled
@Test
void run_local_only_ignoreDockerShutdown() {
Properties sourceProperties = new Properties();
DatabaseConfig serverConfig = new DatabaseConfig();
serverConfig.loadFromProperties(sourceProperties);

Config config = new Config("main", "postgres", "main", serverConfig);
assertThat(config.ignoreDockerShutdown("~/.ebean/ignore-docker-shutdown")).isTrue();
assertThat(config.ignoreDockerShutdown()).isTrue();
}

@Test
void ignoreDockerShutdown_viaProperties() {
Properties sourceProperties = new Properties();
sourceProperties.setProperty("ebean.test.localDevelopment", "./src/test/resources/logback-test.xml");

DatabaseConfig serverConfig = new DatabaseConfig();
serverConfig.loadFromProperties(sourceProperties);

Config config = new Config("main", "postgres", "main", serverConfig);
assertThat(config.ignoreDockerShutdown()).isTrue();
}

@Test
void readImage_fromPlatform() {
Properties p = new Properties();
Expand Down
2 changes: 1 addition & 1 deletion ebean-test/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<logger name="org.tests" level="INFO"/>
<logger name="io.ebean" level="INFO"/>
<logger name="io.avaje.config" level="TRACE"/>
<logger name="io.ebean.docker" level="TRACE"/>
<logger name="io.ebean.docker" level="DEBUG"/>
<logger name="io.ebean.test" level="TRACE"/>

<!-- <logger name="io.ebean.DDL" level="DEBUG"/>-->
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<ebean-ddl-runner.version>2.0</ebean-ddl-runner.version>
<ebean-migration-auto.version>1.2</ebean-migration-auto.version>
<ebean-migration.version>13.6.0</ebean-migration.version>
<ebean-test-docker.version>5.1</ebean-test-docker.version>
<ebean-test-docker.version>5.3</ebean-test-docker.version>
<ebean-datasource.version>8.0</ebean-datasource.version>
<ebean-agent.version>13.6.0</ebean-agent.version>
<ebean-maven-plugin.version>13.6.0</ebean-maven-plugin.version>
Expand Down

0 comments on commit c5940da

Please sign in to comment.