use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class CQListGIIDUnitTest method createClientCache.
public static void createClientCache(Integer port1, Integer port2, Integer port3, String rLevel, Boolean addListener) throws Exception {
CacheServerTestUtil.disableShufflingOfEndpoints();
String host = NetworkUtils.getIPLiteral();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new CQListGIIDUnitTest().createCache(props);
PoolFactory pf = PoolManager.createFactory();
int endPointCount = 1;
pf.addServer(host, port1);
if (port2.intValue() != -1) {
pf.addServer(host, port2);
endPointCount++;
}
if (port3.intValue() != -1) {
pf.addServer(host, port3);
endPointCount++;
}
pf.setRetryAttempts(5);
pf.setReadTimeout(2500);
pf.setSocketBufferSize(32768);
pf.setPingInterval(1000);
pf.setMinConnections(endPointCount * 2);
pf.setSubscriptionRedundancy(Integer.parseInt(rLevel));
pf.setSubscriptionEnabled(true).create("clientPool");
try {
cache.getQueryService();
} catch (Exception cqe) {
Assert.fail("Failed to getCQService.", cqe);
}
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setPoolName("clientPool");
RegionAttributes attrs = factory.create();
createRegion(regions[0], "root", attrs);
createRegion(regions[1], "root", attrs);
logger = cache.getLogger();
}
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