mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Refactor properties bootup, remove GlobalProperties and allow ServerConfig.loadFromProperties()
This commit is contained in:
+79
@@ -0,0 +1,79 @@
|
||||
package com.avaje.ebeaninternal.server.cluster.socket;
|
||||
|
||||
import com.avaje.ebean.config.ContainerConfig;
|
||||
import com.avaje.ebeaninternal.api.TDSpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventTable;
|
||||
import com.avaje.ebeaninternal.server.cluster.ClusterManager;
|
||||
import com.avaje.ebeaninternal.server.transaction.RemoteTransactionEvent;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class SocketClusterBroadcastTest {
|
||||
|
||||
class TestServer extends TDSpiEbeanServer {
|
||||
|
||||
RemoteTransactionEvent event;
|
||||
|
||||
TestServer(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remoteTransactionEvent(RemoteTransactionEvent event) {
|
||||
this.event = event;
|
||||
}
|
||||
}
|
||||
|
||||
private ContainerConfig createContainerConfig(String local, String threadPoolName) {
|
||||
ContainerConfig container0 = new ContainerConfig();
|
||||
container0.setMode(ContainerConfig.ClusterMode.SOCKET);
|
||||
|
||||
ContainerConfig.SocketConfig socketConfig = new ContainerConfig.SocketConfig();
|
||||
socketConfig.setLocalHostPort(local);
|
||||
socketConfig.setThreadPoolName(threadPoolName);
|
||||
socketConfig.setMembers(Arrays.asList("127.0.0.1:9876", "127.0.0.1:9866"));
|
||||
|
||||
container0.setSocketConfig(socketConfig);
|
||||
return container0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testStartup() throws Exception {
|
||||
|
||||
ContainerConfig container0 = createContainerConfig("127.0.0.1:9876", "pool0");
|
||||
ClusterManager mgr0 = new ClusterManager(container0);
|
||||
|
||||
TestServer server0 = new TestServer("s001");
|
||||
mgr0.registerServer(server0);
|
||||
|
||||
ContainerConfig container1 = createContainerConfig("127.0.0.1:9866", "pool1");
|
||||
ClusterManager mgr1 = new ClusterManager(container1);
|
||||
|
||||
TestServer server1 = new TestServer("s001");
|
||||
mgr1.registerServer(server1);
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
RemoteTransactionEvent evt = new RemoteTransactionEvent("s001");
|
||||
TransactionEventTable.TableIUD tableIUD = new TransactionEventTable.TableIUD("noSuchTable", true, false, false);
|
||||
evt.addTableIUD(tableIUD);
|
||||
|
||||
assertNull(server1.event);
|
||||
|
||||
mgr0.broadcast(evt);
|
||||
Thread.sleep(100);
|
||||
|
||||
assertNotNull(server1.event);
|
||||
|
||||
Thread.sleep(1000);
|
||||
mgr0.shutdown();
|
||||
mgr1.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +1,19 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
import com.avaje.tests.model.mappedsuper.ASimpleBean;
|
||||
import com.avaje.tests.model.mappedsuper.NotEnhancedMappedSuper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestNotEnhancedMappedSuper extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void simpleBean_mappedSuperNotEnhanced_ok() {
|
||||
|
||||
GlobalProperties.put("ebean.search.packages", "com.avaje.tests.model.mappedsuper");
|
||||
|
||||
|
||||
ASimpleBean bean = new ASimpleBean();
|
||||
bean.setName("junk");
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TestDataSourceMax extends BaseTestCase {
|
||||
// return;
|
||||
// }
|
||||
|
||||
DefaultBackgroundExecutor bg = new DefaultBackgroundExecutor(1, 2, 180, 30, "testDs");
|
||||
DefaultBackgroundExecutor bg = new DefaultBackgroundExecutor(1, 1, 2, 180, 30, "testDs");
|
||||
|
||||
try {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ public class TestDataSourceMaxWithEntity extends BaseTestCase {
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
|
||||
DefaultBackgroundExecutor bg = new DefaultBackgroundExecutor(1, 2, 180, 30, "testDs");
|
||||
DefaultBackgroundExecutor bg = new DefaultBackgroundExecutor(1, 1, 2, 180, 30, "testDs");
|
||||
|
||||
try {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
|
||||
+7
-10
@@ -1,17 +1,15 @@
|
||||
package com.avaje.ebeaninternal.server.transaction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.EbeanServerFactory;
|
||||
import com.avaje.ebean.Transaction;
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.tests.model.basic.UTDetail;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TestAutoCommitDataSource extends BaseTestCase {
|
||||
|
||||
@@ -21,17 +19,16 @@ public class TestAutoCommitDataSource extends BaseTestCase {
|
||||
ServerConfig config = new ServerConfig();
|
||||
config.setName("h2autocommit");
|
||||
config.loadFromProperties();
|
||||
config.setDefaultServer(false);
|
||||
config.setRegister(false);
|
||||
|
||||
config.addClass(UTDetail.class);
|
||||
config.setDdlGenerate(true);
|
||||
config.setDdlRun(true);
|
||||
config.setAutoCommitMode(true);
|
||||
|
||||
GlobalProperties.setSkipPrimaryServer(true);
|
||||
|
||||
EbeanServer ebeanServer = EbeanServerFactory.create(config);
|
||||
|
||||
|
||||
|
||||
UTDetail detail1 = new UTDetail("one", 12, 30D);
|
||||
UTDetail detail2 = new UTDetail("two", 11, 30D);
|
||||
UTDetail detail3 = new UTDetail("three", 8, 30D);
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ClassPathSearchTests {
|
||||
public boolean isMatch(Class<?> cls) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}, null);
|
||||
|
||||
List<Class<?>> found = search.findClasses();
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ClassPathSearchTests {
|
||||
public boolean isMatch(Class<?> cls) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
},null);
|
||||
|
||||
runAsserts(search.findClasses(), cl, search, jar, jarBang);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user