#862 - ENH: Change ServerConfig such that if H2 is the DataSource/DatabasePlatform then automatically it sets up for testing (ddl generation)

This commit is contained in:
Rob Bygrave
2016-11-07 19:50:05 +13:00
parent b581c893ec
commit d05b593432
11 changed files with 49 additions and 7 deletions
@@ -77,6 +77,12 @@ public class ServerConfig {
*/
private String name = "db";
/**
* When false (default) H2 automatically uses DDL generate and run
* (i.e. assumes we are running tests using in memory h2).
*/
private boolean h2ProductionMode;
/**
* Typically configuration type objects that are passed by this ServerConfig
* to plugins. For example - IgniteConfiguration passed to Ignite plugin.
@@ -509,6 +515,27 @@ public class ServerConfig {
this.name = name;
}
/**
* Return true if H2 should be used in production mode.
* <p>
* Otherwise it is assumed we are using H2 for testing and DDL generate and run is turned on.
* </p>
*/
public boolean isH2ProductionMode() {
return h2ProductionMode;
}
/**
* Set to true for H2 to be used in production mode.
* <p>
* Do this when we want to use H2 and not have the DDL generation and run automatically turned on.
* Otherwise it is assumed we are using H2 for testing purposes.
* </p>
*/
public void setH2ProductionMode(boolean h2ProductionMode) {
this.h2ProductionMode = h2ProductionMode;
}
/**
* Return the container / clustering configuration.
* <p/>
@@ -1444,6 +1471,12 @@ public class ServerConfig {
*/
public void setDatabasePlatform(DatabasePlatform databasePlatform) {
this.databasePlatform = databasePlatform;
if (!h2ProductionMode && databasePlatform != null && databasePlatform.isPlatform(Platform.H2)) {
// we are using H2 to run tests so turn on DDL generation and run
this.ddlGenerate = true;
this.ddlRun = true;
this.ddlCreateOnly = true;
}
}
/**
@@ -2460,6 +2493,7 @@ public class ServerConfig {
jsonDateTime = JsonConfig.DateTime.MILLIS;
}
h2ProductionMode = p.getBoolean("h2ProductionMode", h2ProductionMode);
ddlGenerate = p.getBoolean("ddl.generate", ddlGenerate);
ddlRun = p.getBoolean("ddl.run", ddlRun);
ddlCreateOnly = p.getBoolean("ddl.createOnly", ddlCreateOnly);
@@ -240,7 +240,7 @@ public class DefaultContainer implements SpiContainer {
DatabasePlatform db = factory.create(config);
db.configure(config);
config.setDatabasePlatform(db);
logger.info("DatabasePlatform name:" + config.getName() + " platform:" + db.getName());
logger.info("DatabasePlatform name:{} platform:{}", config.getName(), db.getName());
}
}
@@ -18,6 +18,7 @@ public class EbeanServerFactory_ServerConfigStart_Test {
config.setName("h2");
config.loadFromProperties();
config.setName("h2other");
config.setH2ProductionMode(true);
config.setDdlGenerate(false);
config.setDdlRun(false);
config.setDefaultServer(false);
@@ -34,9 +34,11 @@ public class ServerConfigTest {
props.setProperty("jdbcFetchSizeFindList", "43");
props.setProperty("backgroundExecutorShutdownSecs", "98");
props.setProperty("backgroundExecutorSchedulePoolSize", "4");
props.setProperty("h2ProductionMode", "true");
serverConfig.loadFromProperties(props);
assertTrue(serverConfig.isH2ProductionMode());
assertEquals(PersistBatch.INSERT, serverConfig.getPersistBatch());
assertEquals(PersistBatch.INSERT, serverConfig.getPersistBatchOnCascade());
assertEquals(ServerConfig.DbUuid.BINARY, serverConfig.getDbUuid());
@@ -31,6 +31,7 @@ public class ModelBuild_compoundKeyTest extends BaseTestCase {
config.setName("h2");
config.loadFromProperties();
config.setName("h2other");
config.setH2ProductionMode(true);
config.setDdlGenerate(false);
config.setDdlRun(false);
config.setDefaultServer(false);
@@ -25,6 +25,7 @@ public class ModelBuild_explicitSequencesTest extends BaseTestCase {
config.setName("h2");
config.loadFromProperties();
config.setName("h2other");
config.setH2ProductionMode(true);
config.setDdlGenerate(false);
config.setDdlRun(false);
config.setDefaultServer(false);
@@ -73,6 +73,7 @@ public class BeanPersistControllerTest {
ServerConfig config = new ServerConfig();
config.setName("h2ebasicver");
config.setH2ProductionMode(true);
config.loadFromProperties();
config.setDdlGenerate(true);
config.setDdlRun(true);
@@ -52,6 +52,7 @@ public class BeanPostLoadTest extends BaseTestCase {
config.setName("h2ebasicver");
config.loadFromProperties();
config.setH2ProductionMode(true);
config.setDdlGenerate(true);
config.setDdlRun(true);
@@ -43,6 +43,7 @@ public class TestAutoCommitDataSource extends BaseTestCase {
ServerConfig config = new ServerConfig();
config.setName("h2autocommit");
config.setH2ProductionMode(true);
config.loadFromProperties();
config.setDataSource(pool);
config.setDefaultServer(false);
+2 -2
View File
@@ -15,8 +15,8 @@ ebean.encryptKeyManager=com.avaje.tests.basic.encrypt.BasicEncyptKeyManager
#ebean.autotune.profiling=true
#ebean.autotune.profilingUpdateFrequency=5
ebean.ddl.generate=true
ebean.ddl.run=true
#ebean.ddl.generate=true
#ebean.ddl.run=true
datasource.default=h2
#ebean.persistBatch=NONE
+4 -4
View File
@@ -78,10 +78,10 @@
<logger name="com.avaje.ebean" level="INFO"/>
<logger name="org.avaje.ebean" level="INFO"/>
<!--<logger name="org.avaje.ebean.SQL" level="TRACE"/>-->
<!--<logger name="org.avaje.ebean.TXN" level="TRACE"/>-->
<!--<logger name="org.avaje.ebean.SUM" level="TRACE"/>-->
<!--<logger name="org.avaje.ebean.ELA" level="TRACE"/>-->
<logger name="org.avaje.ebean.SQL" level="TRACE"/>
<logger name="org.avaje.ebean.TXN" level="TRACE"/>
<logger name="org.avaje.ebean.SUM" level="TRACE"/>
<logger name="org.avaje.ebean.ELA" level="TRACE"/>
<!--<logger name="org.avaje.ebean.cache.QUERY" level="TRACE"/>-->
<!--<logger name="org.avaje.ebean.cache.BEAN" level="TRACE"/>-->