use of org.apache.geode.internal.cache.PoolFactoryImpl in project geode by apache.
the class LocatorLoadBalancingDUnitTest method testIntersectingServerGroups.
/**
* Test that the locator balances load between three servers with intersecting server groups.
* Server: 1 2 3 Groups: a a,b b
*
* @throws Exception
*/
@Test
public void testIntersectingServerGroups() throws Exception {
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
String hostName = NetworkUtils.getServerHostName(vm0.getHost());
vm0.invoke("Start Locator", () -> startLocator(hostName, locatorPort, ""));
String locators = getLocatorString(host, locatorPort);
int serverPort1 = vm1.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "a" }, locators));
vm2.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "a", "b" }, locators));
vm3.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "b" }, locators));
PoolFactoryImpl pf = new PoolFactoryImpl(null);
pf.addLocator(NetworkUtils.getServerHostName(host), locatorPort);
pf.setMinConnections(12);
pf.setSubscriptionEnabled(false);
pf.setServerGroup("a");
pf.setIdleTimeout(-1);
startBridgeClient(pf.getPoolAttributes(), new String[] { REGION_NAME });
waitForPrefilledConnections(12);
vm1.invoke("Check Connection Count", () -> checkConnectionCount(6));
vm2.invoke("Check Connection Count", () -> checkConnectionCount(6));
vm3.invoke("Check Connection Count", () -> checkConnectionCount(0));
LogWriterUtils.getLogWriter().info("pool1 prefilled");
PoolFactoryImpl pf2 = (PoolFactoryImpl) PoolManager.createFactory();
pf2.init(pf.getPoolAttributes());
pf2.setServerGroup("b");
PoolImpl pool2 = (PoolImpl) pf2.create("testPool2");
waitForPrefilledConnections(12, "testPool2");
// The load will not be perfect, because we created all of the connections
// for group A first.
vm1.invoke("Check Connection Count", () -> checkConnectionCount(6));
vm2.invoke("Check Connection Count", () -> checkConnectionCount(9));
vm3.invoke("Check Connection Count", () -> checkConnectionCount(9));
LogWriterUtils.getLogWriter().info("pool2 prefilled");
ServerLocation location1 = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort1);
PoolImpl pool1 = (PoolImpl) PoolManager.getAll().get(POOL_NAME);
Assert.assertEquals("a", pool1.getServerGroup());
// Use up all of the pooled connections on pool1, and acquire 3 more
for (int i = 0; i < 15; i++) {
pool1.acquireConnection();
}
LogWriterUtils.getLogWriter().info("aquired 15 connections in pool1");
// now the load should be equal
vm1.invoke("Check Connection Count", () -> checkConnectionCount(9));
vm2.invoke("Check Connection Count", () -> checkConnectionCount(9));
vm3.invoke("Check Connection Count", () -> checkConnectionCount(9));
// use up all of the pooled connections on pool2
for (int i = 0; i < 12; i++) {
pool2.acquireConnection();
}
LogWriterUtils.getLogWriter().info("aquired 12 connections in pool2");
// interleave creating connections in both pools
for (int i = 0; i < 6; i++) {
pool1.acquireConnection();
pool2.acquireConnection();
}
LogWriterUtils.getLogWriter().info("interleaved 6 connections from pool1 with 6 connections from pool2");
// The load should still be balanced
vm1.invoke("Check Connection Count", () -> checkConnectionCount(13));
vm2.invoke("Check Connection Count", () -> checkConnectionCount(13));
vm3.invoke("Check Connection Count", () -> checkConnectionCount(13));
}
use of org.apache.geode.internal.cache.PoolFactoryImpl in project geode by apache.
the class LocatorTestBase method startBridgeClient.
protected void startBridgeClient(final String group, final String host, final int port, final String[] regions) throws Exception {
PoolFactoryImpl pf = new PoolFactoryImpl(null);
pf.addLocator(host, port).setServerGroup(group).setPingInterval(200).setSubscriptionEnabled(true).setSubscriptionRedundancy(-1);
startBridgeClient(pf.getPoolAttributes(), regions);
}
use of org.apache.geode.internal.cache.PoolFactoryImpl in project geode by apache.
the class LocatorTestBase method startBridgeClient.
protected void startBridgeClient(final Pool pool, final String[] regions) throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, String.valueOf(0));
props.setProperty(LOCATORS, "");
DistributedSystem ds = getSystem(props);
Cache cache = CacheFactory.create(ds);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setPoolName(POOL_NAME);
PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
pf.init(pool);
LocatorDiscoveryCallback locatorCallback = new MyLocatorCallback();
remoteObjects.put(CALLBACK_KEY, locatorCallback);
pf.setLocatorDiscoveryCallback(locatorCallback);
pf.create(POOL_NAME);
RegionAttributes attrs = factory.create();
for (int i = 0; i < regions.length; i++) {
cache.createRegion(regions[i], attrs);
}
remoteObjects.put(CACHE_KEY, cache);
}
use of org.apache.geode.internal.cache.PoolFactoryImpl in project geode by apache.
the class CacheXml66DUnitTest method testAlreadyExistingPool.
@Test
public void testAlreadyExistingPool() throws Exception {
getSystem();
PoolFactoryImpl f = (PoolFactoryImpl) PoolManager.createFactory();
f.setStartDisabled(true).addLocator(ALIAS2, 12345).create("mypool");
try {
// now make sure declarative cache can't create the same pool
CacheCreation cache = new CacheCreation();
cache.createPoolFactory().addLocator(ALIAS2, 12345).create("mypool");
IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.PoolManagerImpl_POOL_NAMED_0_ALREADY_EXISTS.toLocalizedString("mypool"));
try {
testXml(cache);
fail("expected IllegalStateException");
} catch (IllegalStateException expected) {
} finally {
expectedException.remove();
}
} finally {
PoolManager.close();
}
}
use of org.apache.geode.internal.cache.PoolFactoryImpl in project geode by apache.
the class CacheServerTestUtil method createCacheClient.
public static void createCacheClient(Pool poolAttr, String regionName, Properties dsProperties, Boolean addControlListener, Properties javaSystemProperties) throws Exception {
new CacheServerTestUtil().createCache(dsProperties);
IgnoredException.addIgnoredException("java.net.ConnectException||java.net.SocketException");
if (javaSystemProperties != null && javaSystemProperties.size() > 0) {
Enumeration e = javaSystemProperties.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
System.setProperty(key, javaSystemProperties.getProperty(key));
}
}
PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
pf.init(poolAttr);
PoolImpl p = (PoolImpl) pf.create("CacheServerTestUtil");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setPoolName(p.getName());
if (addControlListener.booleanValue()) {
factory.addCacheListener(new ControlListener());
}
RegionAttributes attrs = factory.create();
cache.createRegion(regionName, attrs);
pool = p;
}
Aggregations