use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class ConnectionPoolAndLoaderDUnitTest method testPoolLoadAndPeer.
/**
* Test that we can have a peer, a server, and a bridge loader for the same region.
*
* Expected order 1 localCache 2 peer 3 server 4 loader
*/
@Test
public void testPoolLoadAndPeer() throws Exception {
final String regionName = this.getName();
final Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client1 = host.getVM(1);
VM client2 = host.getVM(2);
final int serverPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
server.invoke(new SerializableCallable() {
public Object call() throws IOException {
Cache cache = getCache();
AttributesFactory af = new AttributesFactory();
RegionAttributes attrs = af.create();
cache.createRegion(regionName, attrs);
startBridgeServer(serverPort, true);
return null;
}
});
SerializableCallable createClient1 = new SerializableCallable() {
public Object call() {
// Make sure we get a distributed system that has the locator
useLocator = true;
Cache cache = getCache();
useLocator = false;
PoolFactory factory = PoolManager.createFactory();
factory.addServer(NetworkUtils.getServerHostName(host), serverPort);
factory.create("pool1");
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.NORMAL);
af.setScope(Scope.DISTRIBUTED_ACK);
af.setPoolName("pool1");
af.setCacheLoader(new MyCacheLoader("loaded1"));
RegionAttributes attrs = af.create();
cache.createRegion(regionName, attrs);
return null;
}
};
client1.invoke(createClient1);
SerializableCallable createClient2 = new SerializableCallable() {
public Object call() {
// Make sure we get a distributed system that has the locator
useLocator = true;
Cache cache = getCache();
useLocator = false;
PoolFactory factory = PoolManager.createFactory();
factory.addServer(NetworkUtils.getServerHostName(host), serverPort);
factory.create("pool1");
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.NORMAL);
af.setScope(Scope.DISTRIBUTED_ACK);
af.setCacheLoader(new MyCacheLoader("loaded2"));
af.setPoolName("pool1");
RegionAttributes attrs = af.create();
cache.createRegion(regionName, attrs);
return null;
}
};
client2.invoke(createClient2);
// We need to test what happens when
// we do a load in client1 in each of these cases:
// Case On Server On Client 1 On Client 2 Expected
// a X server
// b X X client1
// c X X X client1
// d X X client2
// e X client1
// f X X client1
// g X client2 (loader does a netSearch)
// h client1 loader
// Setup scenarios
client1.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
region.put("b", "client1-b");
region.put("c", "client1-c");
region.put("e", "client1-e");
region.put("f", "client1-f");
}
});
client2.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
assertEquals("client1-c", region.get("c"));
region.put("d", "client2-d");
assertEquals("client1-f", region.get("f"));
region.put("g", "client2-g");
}
});
server.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
region.put("a", "server-a");
region.localDestroy("e");
region.localDestroy("f");
region.localDestroy("g");
}
});
// Test the scenarios
client1.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
assertEquals("server-a", region.get("a"));
assertEquals("client1-b", region.get("b"));
assertEquals("client1-c", region.get("c"));
assertEquals("client2-d", region.get("d"));
assertEquals("client1-e", region.get("e"));
assertEquals("client1-f", region.get("f"));
assertEquals("client2-g", region.get("g"));
assertEquals("loaded1-h", region.get("h"));
}
});
server.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
assertEquals("server-a", region.get("a"));
assertEquals("client1-b", region.get("b"));
assertEquals("client1-c", region.get("c"));
assertEquals("client2-d", region.get("d"));
assertEquals(null, region.get("e"));
assertEquals(null, region.get("f"));
// dsmith - This result seems somewhat suspect. client1 did a net load
// which found a value in client2, but it never propagated that result
// to the server. After talking with Darrel we decided to keep it this
// way for now.
assertEquals(null, region.get("g"));
assertEquals("loaded1-h", region.get("h"));
}
});
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class CacheXml66DUnitTest method testTwoConnectionPools.
@Test
public void testTwoConnectionPools() throws Exception {
getSystem();
CacheCreation cache = new CacheCreation();
PoolFactory f = cache.createPoolFactory();
f.addLocator(ALIAS2, 3777).create("mypool");
f.reset().addLocator(ALIAS1, 3888).create("mypool2");
try {
f.create("mypool");
fail("expected IllegalStateException");
} catch (IllegalStateException expected) {
}
try {
f.create("mypool2");
fail("expected IllegalStateException");
} catch (IllegalStateException expected) {
}
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setPoolName("mypool");
cache.createVMRegion("rootNORMAL", attrs);
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Region r = c.getRegion("rootNORMAL");
assertNotNull(r);
assertEquals("mypool", r.getAttributes().getPoolName());
Pool cp = PoolManager.find("mypool");
assertNotNull(cp);
assertEquals(0, cp.getServers().size());
assertEquals(1, cp.getLocators().size());
assertEquals(createINSA(ALIAS2, 3777), cp.getLocators().get(0));
cp = PoolManager.find("mypool2");
assertNotNull(cp);
assertEquals(0, cp.getServers().size());
assertEquals(1, cp.getLocators().size());
assertEquals(createINSA(ALIAS1, 3888), cp.getLocators().get(0));
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class CacheXml66DUnitTest method testDefaultConnectionPool.
/**
* test for checking default value of PR_Single_Hop feature. Test for checking default value of
* multiuser-authentication attribute.
*/
@Test
public void testDefaultConnectionPool() throws Exception {
getSystem();
CacheCreation cache = new CacheCreation();
PoolFactory f = cache.createPoolFactory();
f.addLocator(ALIAS2, 3777);
f.create("mypool");
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setPoolName("mypool");
cache.createVMRegion("rootNORMAL", attrs);
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Region r = c.getRegion("rootNORMAL");
assertNotNull(r);
assertEquals("mypool", r.getAttributes().getPoolName());
Pool cp = PoolManager.find("mypool");
assertNotNull(cp);
assertEquals(1, cp.getLocators().size());
assertEquals(0, cp.getServers().size());
assertEquals(createINSA(ALIAS2, 3777), cp.getLocators().get(0));
assertEquals(PoolFactory.DEFAULT_FREE_CONNECTION_TIMEOUT, cp.getFreeConnectionTimeout());
assertEquals(PoolFactory.DEFAULT_LOAD_CONDITIONING_INTERVAL, cp.getLoadConditioningInterval());
assertEquals(PoolFactory.DEFAULT_SOCKET_BUFFER_SIZE, cp.getSocketBufferSize());
assertEquals(PoolFactory.DEFAULT_THREAD_LOCAL_CONNECTIONS, cp.getThreadLocalConnections());
assertEquals(PoolFactory.DEFAULT_READ_TIMEOUT, cp.getReadTimeout());
assertEquals(PoolFactory.DEFAULT_MIN_CONNECTIONS, cp.getMinConnections());
assertEquals(PoolFactory.DEFAULT_MAX_CONNECTIONS, cp.getMaxConnections());
assertEquals(PoolFactory.DEFAULT_RETRY_ATTEMPTS, cp.getRetryAttempts());
assertEquals(PoolFactory.DEFAULT_IDLE_TIMEOUT, cp.getIdleTimeout());
assertEquals(PoolFactory.DEFAULT_PING_INTERVAL, cp.getPingInterval());
assertEquals(PoolFactory.DEFAULT_STATISTIC_INTERVAL, cp.getStatisticInterval());
assertEquals(PoolFactory.DEFAULT_SERVER_GROUP, cp.getServerGroup());
assertEquals(PoolFactory.DEFAULT_SUBSCRIPTION_ENABLED, cp.getSubscriptionEnabled());
assertEquals(PoolFactory.DEFAULT_PR_SINGLE_HOP_ENABLED, cp.getPRSingleHopEnabled());
assertEquals(PoolFactory.DEFAULT_SUBSCRIPTION_REDUNDANCY, cp.getSubscriptionRedundancy());
assertEquals(PoolFactory.DEFAULT_SUBSCRIPTION_MESSAGE_TRACKING_TIMEOUT, cp.getSubscriptionMessageTrackingTimeout());
assertEquals(PoolFactory.DEFAULT_SUBSCRIPTION_ACK_INTERVAL, cp.getSubscriptionAckInterval());
assertEquals(PoolFactory.DEFAULT_MULTIUSER_AUTHENTICATION, cp.getMultiuserAuthentication());
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class GemFireCacheImpl method createDefaultPF.
private PoolFactory createDefaultPF() {
PoolFactory defaultPoolFactory = PoolManager.createFactory();
try {
String localHostName = SocketCreator.getHostName(SocketCreator.getLocalHost());
defaultPoolFactory.addServer(localHostName, CacheServer.DEFAULT_PORT);
} catch (UnknownHostException ex) {
throw new IllegalStateException("Could not determine local host name", ex);
}
return defaultPoolFactory;
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class DeltaSizingDUnitTest method doClientTest.
private void doClientTest(final boolean clone, final boolean copyOnRead) throws Exception {
AccessorFactory factory = new AccessorFactory() {
public Region<Integer, TestDelta> createRegion(Host host, Cache cache, int port1, int port2) {
AttributesFactory<Integer, TestDelta> attr = new AttributesFactory<Integer, TestDelta>();
PoolFactory pf = PoolManager.createFactory();
pf.addServer(NetworkUtils.getServerHostName(host), port1);
pf.addServer(NetworkUtils.getServerHostName(host), port2);
pf.create("pool");
attr.setCloningEnabled(clone);
attr.setDataPolicy(DataPolicy.EMPTY);
attr.setScope(Scope.LOCAL);
attr.setPoolName("pool");
Region<Integer, TestDelta> region = cache.createRegion("region1", attr.create());
return region;
}
};
doTest(factory, clone, copyOnRead);
}
Aggregations