use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class CacheXmlParser method doLocator.
/**
* @since GemFire 5.7
*/
private void doLocator(Attributes atts) {
PoolFactory f = (PoolFactory) stack.peek();
String host = atts.getValue(HOST).trim();
int port = parseInt(atts.getValue(PORT));
f.addLocator(host, port);
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class ConnectionPoolFactoryJUnitTest method testAddIllegalArgs.
@Test
public void testAddIllegalArgs() {
PoolFactory cpf = PoolManager.createFactory();
try {
cpf.addServer("localhost", 0);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
try {
cpf.addServer("localhost", 65536);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
try {
cpf.addLocator("localhost", 0);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
try {
cpf.addLocator("localhost", 65536);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
// Fix for #45348
// try {
// cpf.addLocator("noWayThisIsAValidHost", 12345);
// fail("expected IllegalArgumentException");
// } catch (IllegalArgumentException expected) {
// if (!(expected.getCause() instanceof java.net.UnknownHostException)) {
// fail("expected cause to be UnknownHostException but was " + expected.getCause());
// }
// }
cpf.addLocator("localhost", 12345);
try {
cpf.addServer("localhost", 12345);
fail("expected IllegalStateException");
} catch (IllegalStateException expected) {
}
cpf.reset();
cpf.addServer("localhost", 12345);
try {
cpf.addLocator("localhost", 12345);
fail("expected IllegalStateException");
} catch (IllegalStateException expected) {
}
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class ConnectionPoolFactoryJUnitTest method testCreateADirectPool.
@Test
public void testCreateADirectPool() throws Exception {
int connectionTimeout = 20;
boolean threadLocalConnections = true;
int readTimeout = 20;
int messageTrackingTimeout = 20;
int redundancy = 20;
int bufferSize = 20;
int ackInterval = 15;
PoolFactory cpf = PoolManager.createFactory();
((PoolFactoryImpl) cpf).setStartDisabled(true);
cpf.addServer("localhost", 40907).setFreeConnectionTimeout(connectionTimeout).setThreadLocalConnections(threadLocalConnections).setReadTimeout(readTimeout).setSubscriptionEnabled(true).setSubscriptionRedundancy(redundancy).setSubscriptionMessageTrackingTimeout(messageTrackingTimeout).setSubscriptionAckInterval(ackInterval).setSocketBufferSize(bufferSize);
Pool pool1 = cpf.create("myfriendlypool");
// @todo validate non default props
Map pools = PoolManager.getAll();
assertEquals("there should be one pool", 1, pools.size());
assertNotNull("pool myfriendlypool should exist and be non null", pools.get("myfriendlypool"));
/* lets make another with same name - should fail! */
boolean gotit = false;
try {
cpf.create("myfriendlypool");
} catch (IllegalStateException ise) {
gotit = true;
}
assertTrue("should have gotten an illegal state when creating duplicate pool name", gotit);
pools = PoolManager.getAll();
assertEquals("there should be one pool", 1, pools.size());
assertNotNull("pool myfriendlypool should exist and be non null", pools.get("myfriendlypool"));
/* create another legit one */
Pool pool2 = cpf.create("myfriendlypool2");
pools = PoolManager.getAll();
assertEquals("there should be two pools", 2, pools.size());
assertNotNull("pool myfriendlypool should exist and be non null", pools.get("myfriendlypool"));
assertNotNull("pool myfriendlypool2 should exist and be non null", pools.get("myfriendlypool2"));
/* lets remove them one by one */
assertEquals(pool1, PoolManager.find("myfriendlypool"));
pool1.destroy();
assertEquals(null, PoolManager.find("myfriendlypool"));
pools = PoolManager.getAll();
assertEquals("there should be one pool", 1, pools.size());
assertNull("pool myfriendlypool should NOT exist", pools.get("myfriendlypool"));
assertNotNull("pool myfriendlypool2 should exist and be non null", pools.get("myfriendlypool2"));
assertEquals(pool2, PoolManager.find("myfriendlypool2"));
pool2.destroy();
assertEquals(null, PoolManager.find("myfriendlypool2"));
pools = PoolManager.getAll();
assertEquals("there should be 0 pools", 0, pools.size());
assertNull("pool myfriendlypool should NOT exist", pools.get("myfriendlypool"));
assertNull("pool myfriendlypool2 should NOT exist and be non null", pools.get("myfriendlypool2"));
cache.close();
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class ConnectionPoolAndLoaderDUnitTest method testPoolAndWriter.
/**
* Test the we can have both a connection pool and a cache writer.
*
* The expected order of operations for put is: local writer put on server
*/
@Test
public void testPoolAndWriter() throws Exception {
final String regionName = this.getName();
final Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client = host.getVM(1);
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;
}
});
client.invoke(new SerializableCallable() {
public Object call() {
Cache cache = getCache();
PoolFactory factory = PoolManager.createFactory();
factory.addServer(NetworkUtils.getServerHostName(host), serverPort);
factory.create("pool1");
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.DEFAULT);
af.setScope(Scope.LOCAL);
af.setPoolName("pool1");
af.setCacheWriter(new MyCacheWriter());
RegionAttributes attrs = af.create();
cache.createRegion(regionName, attrs);
return null;
}
});
client.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
MyCacheWriter writer = (MyCacheWriter) region.getAttributes().getCacheWriter();
region.put("a", "a");
region.put("b", "b");
region.put("c", "c");
region.destroy("c");
writer.throwException = true;
try {
region.put("a", "new-a");
fail("Should have gotten a cache writer exception");
} catch (CacheWriterException e) {
assertEquals("beforeUpdate", e.getMessage());
}
try {
region.destroy("b");
fail("Should have gotten a cache writer exception");
} catch (CacheWriterException e) {
assertEquals("beforeDestroy", e.getMessage());
}
try {
region.put("d", "d");
fail("Should have gotten a cache writer exception");
} catch (CacheWriterException e) {
assertEquals("beforeCreate", e.getMessage());
}
try {
region.clear();
fail("Should have gotten a cache writer exception");
} catch (CacheWriterException e) {
assertEquals("beforeRegionClear", e.getMessage());
}
try {
region.destroyRegion();
fail("Should have gotten a cache writer exception");
} catch (CacheWriterException e) {
assertEquals("beforeRegionDestroy", e.getMessage());
}
}
});
server.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
assertEquals("a", region.get("a"));
assertEquals("b", region.get("b"));
assertEquals(null, region.get("c"));
assertEquals(null, region.get("d"));
}
});
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class ConnectionPoolAndLoaderDUnitTest method testPoolAndLoader.
/**
* Tests that we can have both a connection pool and a bridge loader. The expected order of
* operations for get is. get from server load from loader.
*
* Anything that is loaded on the client is put on the server..
*/
@Test
public void testPoolAndLoader() throws Exception {
final String regionName = this.getName();
final Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client = host.getVM(1);
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;
}
});
client.invoke(new SerializableCallable() {
public Object call() {
Cache cache = getCache();
PoolFactory factory = PoolManager.createFactory();
factory.addServer(NetworkUtils.getServerHostName(host), serverPort);
factory.create("pool1");
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.DEFAULT);
af.setScope(Scope.LOCAL);
af.setPoolName("pool1");
af.setCacheLoader(new MyCacheLoader("loaded"));
RegionAttributes attrs = af.create();
cache.createRegion(regionName, attrs);
return null;
}
});
client.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
region.put("a", "put-a");
region.put("b", "put-b");
assertEquals("loaded-c", region.get("c"));
assertEquals("loaded-d", region.get("d"));
}
});
server.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
assertEquals("put-a", region.get("a"));
assertEquals("put-b", region.get("b"));
assertEquals("loaded-c", region.get("c"));
assertEquals("loaded-d", region.get("d"));
region.put("e", "server-e");
}
});
client.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
assertEquals("put-a", region.get("a"));
assertEquals("put-b", region.get("b"));
assertEquals("loaded-c", region.get("c"));
assertEquals("loaded-d", region.get("d"));
assertEquals("server-e", region.get("e"));
}
});
}
Aggregations