use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class CacheServerMaxConnectionsJUnitTest method createProxyAndRegionForClient.
/**
* Initializes proxy object and creates region for client
*/
private void createProxyAndRegionForClient() {
// props.setProperty("retryAttempts", "0");
PoolFactory pf = PoolManager.createFactory();
pf.addServer("localhost", PORT);
pf.setMinConnections(0);
pf.setPingInterval(10000);
pf.setThreadLocalConnections(true);
pf.setReadTimeout(2000);
pf.setSocketBufferSize(32768);
proxy = (PoolImpl) pf.create("junitPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setPoolName("junitPool");
RegionAttributes attrs = factory.createRegionAttributes();
cache.createVMRegion(regionName, attrs);
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class DeltaPropagationDUnitTest method testBug40165ClientReconnects.
@Test
public void testBug40165ClientReconnects() throws Exception {
PORT1 = ((Integer) VM0.invoke(() -> DeltaPropagationDUnitTest.createServerCache(HARegionQueue.HA_EVICTION_POLICY_MEMORY))).intValue();
/**
* 1. Create a cache server with slow dispatcher 2. Start a durable client with a custom cache
* listener which shuts itself down as soon as it recieves a marker message. 3. Do some puts on
* the server region 4. Let the dispatcher start dispatching 5. Verify that durable client is
* disconnected as soon as it processes the marker. Server will retain its queue which has some
* events (containing deltas) in it. 6. Restart the durable client without the self-destructing
* listener. 7. Wait till the durable client processes all its events. 8. Verify that no deltas
* are received by it.
*/
// Step 0
prepareDeltas();
VM0.invoke(() -> DeltaPropagationDUnitTest.prepareDeltas());
// Step 1
try {
VM0.invoke(() -> ConflationDUnitTest.setIsSlowStart("60000"));
// Step 2
String durableClientId = getName() + "_client";
PoolFactory pf = PoolManager.createFactory();
pf.addServer("localhost", PORT1).setSubscriptionEnabled(true).setSubscriptionAckInterval(1);
((PoolFactoryImpl) pf).getPoolAttributes();
Properties properties = new Properties();
properties.setProperty(MCAST_PORT, "0");
properties.setProperty(LOCATORS, "");
properties.setProperty(DURABLE_CLIENT_ID, durableClientId);
properties.setProperty(DURABLE_CLIENT_TIMEOUT, String.valueOf(60));
createDurableCacheClient(((PoolFactoryImpl) pf).getPoolAttributes(), regionName, properties, new Integer(DURABLE_CLIENT_LISTENER), Boolean.TRUE);
// Step 3
VM0.invoke(() -> DeltaPropagationDUnitTest.doPuts());
// Step 4
VM0.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
// Step 5
// verifyDurableClientDisconnected();
Thread.sleep(5000);
// Step 6
createDurableCacheClient(((PoolFactoryImpl) pf).getPoolAttributes(), regionName, properties, new Integer(DURABLE_CLIENT_LISTENER), Boolean.FALSE);
// Step 7
waitForLastKey();
// Step 8
long fromDeltasOnClient = DeltaTestImpl.getFromDeltaInvokations().longValue();
assertTrue("No deltas were to be received but received: " + fromDeltasOnClient, fromDeltasOnClient < 1);
} finally {
// Step 4
VM0.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
}
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class ClientConflationDUnitTest method createPool2.
private static void createPool2(String host, AttributesFactory factory, Integer port) {
PoolFactory pf = PoolManager.createFactory();
pf.addServer(host, port.intValue()).setSubscriptionEnabled(true).setThreadLocalConnections(true).setReadTimeout(10000).setSocketBufferSize(32768).setPingInterval(1000).setMinConnections(3).setSubscriptionRedundancy(-1);
Pool pool = pf.create("superpoolish" + (poolNameCounter++));
factory.setPoolName(pool.getName());
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class ClientHealthMonitorJUnitTest method createProxyAndRegionForClient.
/**
* Initializes proxy object and creates region for client
*
*/
private void createProxyAndRegionForClient() {
try {
// props.setProperty("retryAttempts", "5");
PoolFactory pf = PoolManager.createFactory();
proxy = (PoolImpl) pf.addServer("localhost", PORT).setThreadLocalConnections(true).setReadTimeout(10000).setPingInterval(10000).setMinConnections(0).create("junitPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
cache.createVMRegion(regionName, factory.createRegionAttributes());
} catch (Exception ex) {
ex.printStackTrace();
fail("Failed to initialize client");
}
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class ClientServerMiscDUnitTest method _createClientCache.
public static Pool _createClientCache(String h, boolean empty, int... ports) throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
Cache cache = new ClientServerMiscDUnitTest().createCacheV(props);
ClientServerMiscDUnitTest.static_cache = cache;
PoolFactory poolFactory = PoolManager.createFactory();
PoolImpl p = (PoolImpl) addServers(poolFactory, h, ports).setSubscriptionEnabled(true).setThreadLocalConnections(true).setReadTimeout(1000).setSocketBufferSize(32768).setMinConnections(3).setSubscriptionRedundancy(-1).setPingInterval(2000).create("ClientServerMiscDUnitTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
if (empty) {
factory.setDataPolicy(DataPolicy.EMPTY);
}
factory.setPoolName(p.getName());
attrs = factory.create();
Region region1 = cache.createRegion(REGION_NAME1, attrs);
Region region2 = cache.createRegion(REGION_NAME2, attrs);
Region prRegion = cache.createRegion(PR_REGION_NAME, attrs);
assertNotNull(region1);
assertNotNull(region2);
assertNotNull(prRegion);
pool = p;
// conn = pool.acquireConnection();
// assertNotNull(conn);
// TODO does this WaitCriterion actually help?
WaitCriterion wc = new WaitCriterion() {
String excuse;
public boolean done() {
try {
conn = pool.acquireConnection();
if (conn == null) {
excuse = "acquireConnection returned null?";
return false;
}
return true;
} catch (NoAvailableServersException e) {
excuse = "Cannot find a server: " + e;
return false;
}
}
public String description() {
return excuse;
}
};
Wait.waitForCriterion(wc, 60 * 1000, 1000, true);
return p;
}
Aggregations