mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
No effective change - tidy tests that create unregistered Database instances (shutdown)
This commit is contained in:
1 parent
63116f25ec
commit
8c7a84be9c
8 files changed
+81
-65
No files matched your search
@@ -1,7 +1,6 @@
|
||||
package io.ebean;
|
||||
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.event.ServerConfigStartup;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.UTDetail;
|
||||
@@ -13,7 +12,7 @@ public class EbeanServerFactory_ServerConfigStart_Test {
|
||||
@Test
|
||||
public void test() throws InterruptedException {
|
||||
|
||||
ServerConfig config = new ServerConfig();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.setName("h2");
|
||||
config.loadFromProperties();
|
||||
config.setName("h2other");
|
||||
@@ -30,17 +29,17 @@ public class EbeanServerFactory_ServerConfigStart_Test {
|
||||
OnStartup onStartup = new OnStartup();
|
||||
config.addServerConfigStartup(onStartup);
|
||||
|
||||
EbeanServer ebeanServer = EbeanServerFactory.create(config);
|
||||
Database db = DatabaseFactory.create(config);
|
||||
|
||||
assertThat(onStartup.calledWithConfig).isSameAs(config);
|
||||
assertThat(OnStartupViaClass.calledWithConfig).isSameAs(config);
|
||||
|
||||
assertThat(ebeanServer).isNotNull();
|
||||
assertThat(db).isNotNull();
|
||||
|
||||
// test server shutdown and restart using the same ServerConfig
|
||||
ebeanServer.shutdown(true, false);
|
||||
db.shutdown(true, false);
|
||||
|
||||
EbeanServer restartedServer = EbeanServerFactory.create(config);
|
||||
Database restartedServer = DatabaseFactory.create(config);
|
||||
restartedServer.shutdown(true, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package io.ebean.config;
|
||||
|
||||
import io.ebean.EbeanServer;
|
||||
import io.ebean.EbeanServerFactory;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.DatabaseFactory;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.config.dbplatform.DbIdentity;
|
||||
import io.ebean.config.dbplatform.IdType;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.EBasicVer;
|
||||
import org.tests.model.draftable.BasicDraftableBean;
|
||||
@@ -15,7 +16,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class PlatformNoGeneratedKeysTest {
|
||||
|
||||
static EbeanServer server = testH2Server();
|
||||
static Database server = testH2Server();
|
||||
|
||||
@AfterClass
|
||||
public static void shutdown() {
|
||||
server.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void global_serverConfig_setDisableLazyLoading() {
|
||||
@@ -79,9 +85,9 @@ public class PlatformNoGeneratedKeysTest {
|
||||
assertThat(one.isDraft()).isFalse();
|
||||
}
|
||||
|
||||
private static EbeanServer testH2Server() {
|
||||
private static Database testH2Server() {
|
||||
|
||||
ServerConfig config = new ServerConfig();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.setName("h2_noGeneratedKeys");
|
||||
|
||||
OtherH2Platform platform = new OtherH2Platform();
|
||||
@@ -108,7 +114,7 @@ public class PlatformNoGeneratedKeysTest {
|
||||
config.getClasses().add(BasicDraftableBean.class);
|
||||
|
||||
|
||||
return EbeanServerFactory.create(config);
|
||||
return DatabaseFactory.create(config);
|
||||
}
|
||||
|
||||
public static class OtherH2Platform extends H2Platform {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package io.ebean.event;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.EbeanServer;
|
||||
import io.ebean.EbeanServerFactory;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.DatabaseFactory;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import io.ebean.common.BeanList;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import org.junit.Test;
|
||||
import org.tests.example.ModUuidGenerator;
|
||||
import org.tests.model.basic.EBasic;
|
||||
@@ -23,7 +23,7 @@ public class BeanFindControllerTest extends BaseTestCase {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ServerConfig config = new ServerConfig();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
|
||||
config.setName("h2otherfind");
|
||||
config.loadFromProperties();
|
||||
@@ -40,27 +40,27 @@ public class BeanFindControllerTest extends BaseTestCase {
|
||||
EBasicFindController findController = new EBasicFindController();
|
||||
config.getFindControllers().add(findController);
|
||||
|
||||
EbeanServer ebeanServer = EbeanServerFactory.create(config);
|
||||
Database db = DatabaseFactory.create(config);
|
||||
|
||||
assertFalse(findController.calledInterceptFind);
|
||||
ebeanServer.find(EBasic.class, 42);
|
||||
db.find(EBasic.class, 42);
|
||||
assertTrue(findController.calledInterceptFind);
|
||||
|
||||
findController.findIntercept = true;
|
||||
EBasic eBasic = ebeanServer.find(EBasic.class, 42);
|
||||
EBasic eBasic = db.find(EBasic.class, 42);
|
||||
|
||||
assertEquals(Integer.valueOf(47), eBasic.getId());
|
||||
assertEquals("47", eBasic.getName());
|
||||
|
||||
assertFalse(findController.calledInterceptFindMany);
|
||||
|
||||
List<EBasic> list = ebeanServer.find(EBasic.class).where().eq("name", "AnInvalidNameSoEmpty").findList();
|
||||
List<EBasic> list = db.find(EBasic.class).where().eq("name", "AnInvalidNameSoEmpty").findList();
|
||||
assertEquals(0, list.size());
|
||||
assertTrue(findController.calledInterceptFindMany);
|
||||
|
||||
findController.findManyIntercept = true;
|
||||
|
||||
list = ebeanServer.find(EBasic.class).where().eq("name", "AnInvalidNameSoEmpty").findList();
|
||||
list = db.find(EBasic.class).where().eq("name", "AnInvalidNameSoEmpty").findList();
|
||||
assertEquals(1, list.size());
|
||||
|
||||
eBasic = list.get(0);
|
||||
@@ -68,8 +68,9 @@ public class BeanFindControllerTest extends BaseTestCase {
|
||||
assertEquals("47", eBasic.getName());
|
||||
|
||||
ECustomId bean = new ECustomId("check");
|
||||
ebeanServer.save(bean);
|
||||
db.save(bean);
|
||||
assertNotNull(bean.getId());
|
||||
db.shutdown();
|
||||
}
|
||||
|
||||
static class EBasicFindController implements BeanFindController {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package io.ebean.event;
|
||||
|
||||
|
||||
import io.ebean.EbeanServer;
|
||||
import io.ebean.EbeanServerFactory;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.DatabaseFactory;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.EBasicVer;
|
||||
import org.tests.model.basic.UTDetail;
|
||||
@@ -25,15 +25,15 @@ public class BeanPersistControllerTest {
|
||||
@Test
|
||||
public void issue_1341() {
|
||||
|
||||
EbeanServer ebeanServer = getEbeanServer(continuePersistingAdapter);
|
||||
Database db = getDatabase(continuePersistingAdapter);
|
||||
|
||||
UTMaster bean0 = new UTMaster("one0");
|
||||
UTDetail detail0 = new UTDetail("detail0", 12, 23D);
|
||||
bean0.getDetails().add(detail0);
|
||||
|
||||
ebeanServer.save(bean0);
|
||||
db.save(bean0);
|
||||
|
||||
UTMaster master = ebeanServer.find(UTMaster.class)
|
||||
UTMaster master = db.find(UTMaster.class)
|
||||
.setId(bean0.getId())
|
||||
.fetch("details", "name, version")
|
||||
.findOne();
|
||||
@@ -41,79 +41,82 @@ public class BeanPersistControllerTest {
|
||||
UTDetail utDetail = master.getDetails().get(0);
|
||||
utDetail.setName("detail0 mod");
|
||||
|
||||
Transaction txn = ebeanServer.beginTransaction();
|
||||
Transaction txn = db.beginTransaction();
|
||||
try {
|
||||
txn.setBatchMode(true);
|
||||
ebeanServer.save(master);
|
||||
db.save(master);
|
||||
txn.commit();
|
||||
} finally {
|
||||
txn.end();
|
||||
}
|
||||
|
||||
db.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertUpdateDelete_given_continuePersistingAdapter() {
|
||||
|
||||
EbeanServer ebeanServer = getEbeanServer(continuePersistingAdapter);
|
||||
|
||||
Database db = getDatabase(continuePersistingAdapter);
|
||||
|
||||
EBasicVer bean = new EBasicVer("testController");
|
||||
|
||||
ebeanServer.save(bean);
|
||||
db.save(bean);
|
||||
assertThat(continuePersistingAdapter.methodsCalled).hasSize(2);
|
||||
assertThat(continuePersistingAdapter.methodsCalled).containsExactly("preInsert", "postInsert");
|
||||
continuePersistingAdapter.methodsCalled.clear();
|
||||
|
||||
bean.setName("modified");
|
||||
ebeanServer.save(bean);
|
||||
db.save(bean);
|
||||
assertThat(continuePersistingAdapter.methodsCalled).hasSize(2);
|
||||
assertThat(continuePersistingAdapter.methodsCalled).containsExactly("preUpdate", "postUpdate");
|
||||
continuePersistingAdapter.methodsCalled.clear();
|
||||
|
||||
ebeanServer.delete(bean);
|
||||
db.delete(bean);
|
||||
assertThat(continuePersistingAdapter.methodsCalled).hasSize(2);
|
||||
assertThat(continuePersistingAdapter.methodsCalled).containsExactly("preDelete", "postDelete");
|
||||
|
||||
db.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertUpdateDelete_given_stopPersistingAdapter() {
|
||||
|
||||
EbeanServer ebeanServer = getEbeanServer(stopPersistingAdapter);
|
||||
Database db = getDatabase(stopPersistingAdapter);
|
||||
|
||||
EBasicVer bean = new EBasicVer("testController");
|
||||
|
||||
ebeanServer.save(bean);
|
||||
db.save(bean);
|
||||
assertThat(stopPersistingAdapter.methodsCalled).hasSize(1);
|
||||
assertThat(stopPersistingAdapter.methodsCalled).containsExactly("preInsert");
|
||||
stopPersistingAdapter.methodsCalled.clear();
|
||||
|
||||
bean.setName("modified");
|
||||
ebeanServer.update(bean);
|
||||
db.update(bean);
|
||||
assertThat(stopPersistingAdapter.methodsCalled).hasSize(1);
|
||||
assertThat(stopPersistingAdapter.methodsCalled).containsExactly("preUpdate");
|
||||
stopPersistingAdapter.methodsCalled.clear();
|
||||
|
||||
ebeanServer.delete(bean);
|
||||
db.delete(bean);
|
||||
assertThat(stopPersistingAdapter.methodsCalled).hasSize(1);
|
||||
assertThat(stopPersistingAdapter.methodsCalled).containsExactly("preDelete");
|
||||
stopPersistingAdapter.methodsCalled.clear();
|
||||
|
||||
ebeanServer.delete(EBasicVer.class, 22);
|
||||
db.delete(EBasicVer.class, 22);
|
||||
assertThat(stopPersistingAdapter.methodsCalled).hasSize(1);
|
||||
assertThat(stopPersistingAdapter.methodsCalled).containsExactly("preDeleteById");
|
||||
stopPersistingAdapter.methodsCalled.clear();
|
||||
|
||||
ebeanServer.deleteAll(EBasicVer.class, Arrays.asList(22,23,24));
|
||||
db.deleteAll(EBasicVer.class, Arrays.asList(22,23,24));
|
||||
assertThat(stopPersistingAdapter.methodsCalled).hasSize(3);
|
||||
assertThat(stopPersistingAdapter.methodsCalled).containsExactly("preDeleteById", "preDeleteById", "preDeleteById");
|
||||
stopPersistingAdapter.methodsCalled.clear();
|
||||
|
||||
db.shutdown();
|
||||
}
|
||||
|
||||
private EbeanServer getEbeanServer(PersistAdapter persistAdapter) {
|
||||
private Database getDatabase(PersistAdapter persistAdapter) {
|
||||
|
||||
ServerConfig config = new ServerConfig();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.setName("h2ebasicver");
|
||||
config.loadFromProperties();
|
||||
config.setDdlGenerate(true);
|
||||
@@ -128,7 +131,7 @@ public class BeanPersistControllerTest {
|
||||
|
||||
config.add(persistAdapter);
|
||||
|
||||
return EbeanServerFactory.create(config);
|
||||
return DatabaseFactory.create(config);
|
||||
}
|
||||
|
||||
static class PersistAdapter extends BeanPersistAdapter {
|
||||
|
||||
@@ -3,10 +3,10 @@ package io.ebean.event;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.BeanState;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.DatabaseFactory;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.EbeanServer;
|
||||
import io.ebean.EbeanServerFactory;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import org.tests.model.basic.EBasicVer;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -22,15 +22,15 @@ public class BeanPostLoadTest extends BaseTestCase {
|
||||
@Test
|
||||
public void testPostLoad() {
|
||||
|
||||
EbeanServer ebeanServer = getEbeanServer();
|
||||
Database db = createDatabase();
|
||||
|
||||
EBasicVer bean = new EBasicVer("testPostLoad");
|
||||
bean.setDescription("someDescription");
|
||||
bean.setOther("other");
|
||||
|
||||
ebeanServer.save(bean);
|
||||
db.save(bean);
|
||||
|
||||
EBasicVer found = ebeanServer.find(EBasicVer.class)
|
||||
EBasicVer found = db.find(EBasicVer.class)
|
||||
.select("name, other")
|
||||
.setId(bean.getId())
|
||||
.findOne();
|
||||
@@ -40,13 +40,14 @@ public class BeanPostLoadTest extends BaseTestCase {
|
||||
assertThat(postLoad.beanState.getLoadedProps()).containsExactly("id", "name", "other");
|
||||
assertThat(postLoad.bean).isSameAs(found);
|
||||
|
||||
ebeanServer.delete(bean);
|
||||
db.delete(bean);
|
||||
db.shutdown();
|
||||
}
|
||||
|
||||
|
||||
private EbeanServer getEbeanServer() {
|
||||
private Database createDatabase() {
|
||||
|
||||
ServerConfig config = new ServerConfig();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
|
||||
config.setName("h2ebasicver");
|
||||
config.loadFromProperties();
|
||||
@@ -60,7 +61,7 @@ public class BeanPostLoadTest extends BaseTestCase {
|
||||
|
||||
config.add(postLoad);
|
||||
|
||||
return EbeanServerFactory.create(config);
|
||||
return DatabaseFactory.create(config);
|
||||
}
|
||||
|
||||
static class PostLoad implements BeanPostLoad {
|
||||
|
||||
+8
-8
@@ -4,7 +4,6 @@ import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.DatabaseFactory;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
@@ -25,7 +24,7 @@ public class DefaultTransactionThreadLocalTest extends BaseTestCase {
|
||||
@ForPlatform({Platform.H2})
|
||||
@Test
|
||||
public void get() {
|
||||
Ebean.execute(() -> {
|
||||
DB.execute(() -> {
|
||||
SpiTransaction txn = getInScopeTransaction();
|
||||
assertNotNull(txn);
|
||||
});
|
||||
@@ -38,12 +37,12 @@ public class DefaultTransactionThreadLocalTest extends BaseTestCase {
|
||||
@Test
|
||||
public void tryWithResources_expect_scopeCleanup() {
|
||||
|
||||
try (Transaction transaction = Ebean.beginTransaction()) {
|
||||
try (Transaction transaction = DB.beginTransaction()) {
|
||||
assertNotNull(transaction);
|
||||
SpiTransaction txn = getInScopeTransaction();
|
||||
assertSame(txn, transaction);
|
||||
|
||||
try (Transaction nested = Ebean.beginTransaction()) {
|
||||
try (Transaction nested = DB.beginTransaction()) {
|
||||
assertNotNull(nested);
|
||||
SpiTransaction txnNested = getInScopeTransaction();
|
||||
assertSame(txnNested, nested);
|
||||
@@ -59,7 +58,7 @@ public class DefaultTransactionThreadLocalTest extends BaseTestCase {
|
||||
@Test
|
||||
public void afterCommit_expect_scopeCleanup() {
|
||||
|
||||
try (Transaction transaction = Ebean.beginTransaction()) {
|
||||
try (Transaction transaction = DB.beginTransaction()) {
|
||||
transaction.commit();
|
||||
assertNull(getInScopeTransaction());
|
||||
}
|
||||
@@ -70,7 +69,7 @@ public class DefaultTransactionThreadLocalTest extends BaseTestCase {
|
||||
@Test
|
||||
public void afterRollback_expect_scopeCleanup() {
|
||||
|
||||
try (Transaction transaction = Ebean.beginTransaction()) {
|
||||
try (Transaction transaction = DB.beginTransaction()) {
|
||||
|
||||
transaction.rollback();
|
||||
assertNull(getInScopeTransaction());
|
||||
@@ -82,8 +81,8 @@ public class DefaultTransactionThreadLocalTest extends BaseTestCase {
|
||||
@Test
|
||||
public void end_withoutActiveTransaction_isFine() {
|
||||
|
||||
assertNull(Ebean.currentTransaction());
|
||||
Ebean.endTransaction();
|
||||
assertNull(DB.currentTransaction());
|
||||
DB.endTransaction();
|
||||
}
|
||||
|
||||
@ForPlatform({Platform.H2})
|
||||
@@ -128,6 +127,7 @@ public class DefaultTransactionThreadLocalTest extends BaseTestCase {
|
||||
assertNull(foundDefaultDb);
|
||||
|
||||
otherDb.delete(bean);
|
||||
otherDb.shutdown();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.tests.basic;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.ESimple;
|
||||
@@ -22,6 +23,11 @@ public class TestQueryUsingDatabase {
|
||||
DB.byName(SOME_OTHER_DB_NAME).insert(RECORD2);
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdown() {
|
||||
DB.byName(SOME_OTHER_DB_NAME).shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usingNonDefaultDatabase() {
|
||||
final Database nonDefaultDb = DB.byName(SOME_OTHER_DB_NAME);
|
||||
|
||||
@@ -86,7 +86,7 @@ datasource.h2.poolListener=org.tests.basic.MyTestDataSourcePoolListener
|
||||
|
||||
datasource.h2multitenant.username=sa
|
||||
datasource.h2multitenant.password=
|
||||
datasource.h2multitenant.url=jdbc:h2:mem:h2multitenant
|
||||
datasource.h2multitenant.url=jdbc:h2:mem:h2multitenant;DB_CLOSE_ON_EXIT=FALSE
|
||||
|
||||
datasource.h2autocommit.autoCommit=true
|
||||
datasource.h2autocommit.username=sa
|
||||
@@ -100,11 +100,11 @@ datasource.h2autocommit2.url=jdbc:h2:mem:autocommit2tests
|
||||
|
||||
datasource.h2other.username=sa
|
||||
datasource.h2other.password=
|
||||
datasource.h2other.url=jdbc:h2:mem:h2other
|
||||
datasource.h2other.url=jdbc:h2:mem:h2other;DB_CLOSE_ON_EXIT=FALSE
|
||||
|
||||
datasource.h2otherfind.username=sa
|
||||
datasource.h2otherfind.password=
|
||||
datasource.h2otherfind.url=jdbc:h2:mem:h2otherfind
|
||||
datasource.h2otherfind.url=jdbc:h2:mem:h2otherfind;DB_CLOSE_ON_EXIT=FALSE
|
||||
|
||||
datasource.h2ebasicver.username=sa
|
||||
datasource.h2ebasicver.password=
|
||||
|
||||
Reference in new issue
Block a user