use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class ClientServerForceInvalidateDUnitTest method createClientCache.
public static void createClientCache(String h, int port1, int port2, boolean empty, boolean concurrenctChecksEnabled) throws Exception {
AbstractRegionMap.FORCE_INVALIDATE_EVENT = true;
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
Cache cache = new ClientServerForceInvalidateDUnitTest().createCacheV(props);
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(h, port1).addServer(h, port2).setSubscriptionEnabled(true).setThreadLocalConnections(true).setReadTimeout(1000).setSocketBufferSize(32768).setMinConnections(3).setSubscriptionRedundancy(-1).setPingInterval(2000).create("ClientServerForceInvalidateDUnitTestPool");
RegionFactory<String, String> factory = cache.createRegionFactory();
if (empty) {
factory.setDataPolicy(DataPolicy.EMPTY);
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
} else {
factory.setDataPolicy(DataPolicy.NORMAL);
}
factory.setPoolName(p.getName());
factory.setConcurrencyChecksEnabled(concurrenctChecksEnabled);
region1 = factory.create(REGION_NAME1);
region1.registerInterest("ALL_KEYS", InterestResultPolicy.NONE, false, false);
region1.getAttributesMutator().addCacheListener(new ClientListener());
assertNotNull(region1);
with().pollDelay(1, TimeUnit.MILLISECONDS).pollInterval(1, TimeUnit.SECONDS).await().atMost(60, TimeUnit.SECONDS).until(() -> poolReady(p));
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class ClientServerMiscDUnitTest method testCCPDestroyOnLastDestroyRegion.
/**
* Test two regions: notify by subscription is true. Both the regions have registered interest in
* all the keys. Destroy region1 on the client. It should reach the server , kill the region on
* the server , propagate it to the interested clients , but it should keep CacheClient Proxy
* alive. Destroy Region2 . It should reach server , close conenction proxy , destroy the region2
* on the server , remove the cache client proxy from the cache client notifier & propagate it to
* the clients. Then create third region and verify that no CacheClientProxy is created on server
*/
@Test
public void testCCPDestroyOnLastDestroyRegion() throws Exception {
PORT1 = initServerCache(true);
PoolImpl pool = (PoolImpl) createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), PORT1);
destroyRegion1();
// pause(5000);
server1.invoke(() -> ClientServerMiscDUnitTest.verifyCacheClientProxyOnServer(new String(REGION_NAME1)));
Connection conn = pool.acquireConnection();
assertNotNull(conn);
assertEquals(1, pool.getConnectedServerCount());
assertEquals(false, pool.isDestroyed());
destroyRegion2();
assertEquals(false, pool.isDestroyed());
destroyPRRegion();
assertEquals(false, pool.isDestroyed());
pool.destroy();
assertEquals(true, pool.isDestroyed());
// pause(5000);
server1.invoke(() -> ClientServerMiscDUnitTest.verifyNoCacheClientProxyOnServer());
try {
getCache().createRegion(REGION_NAME2, attrs);
fail("expected IllegalStateException");
} catch (IllegalStateException expected) {
}
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class ClientServerMiscDUnitTest method testInvalidatesPropagateOnRegionHavingNoPool.
/**
* Create cache, create pool, notify-by-subscription=false, create a region and on client and on
* server. Do not attach pool to region , populate some entries on region both on client and
* server. Update the entries on server the client. The client should not have entry invalidate.
*/
@Test
public void testInvalidatesPropagateOnRegionHavingNoPool() throws Exception {
// start server first
PORT1 = initServerCache(false);
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new ClientServerMiscDUnitTest().createCache(props);
String host = NetworkUtils.getServerHostName(server1.getHost());
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host, PORT1).setSubscriptionEnabled(true).setThreadLocalConnections(true).setReadTimeout(1000).setSocketBufferSize(32768).setMinConnections(3).setSubscriptionRedundancy(-1).setPingInterval(2000).create("testInvalidatesPropagateOnRegionHavingNoPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
// factory.setPoolName(p.getName());
attrs = factory.create();
final Region region1 = getCache().createRegion(REGION_NAME1, attrs);
final Region region2 = getCache().createRegion(REGION_NAME2, attrs);
assertNotNull(region1);
assertNotNull(region2);
pool = p;
conn = pool.acquireConnection();
assertNotNull(conn);
populateCache();
server1.invoke(() -> ClientServerMiscDUnitTest.put());
Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
Object val = region1.getEntry(k1).getValue();
return k1.equals(val);
});
Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
Object val = region1.getEntry(k2).getValue();
return k2.equals(val);
});
Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
Object val = region2.getEntry(k1).getValue();
return k1.equals(val);
});
Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
Object val = region2.getEntry(k2).getValue();
return k2.equals(val);
});
// assertIndexDetailsEquals(region2.getEntry(k2).getValue(), k2);
}
use of org.apache.geode.cache.client.internal.PoolImpl 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;
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class ClearPropagationDUnitTest method acquireConnectionsAndDestroyRegion.
public static void acquireConnectionsAndDestroyRegion(String host) {
try {
Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
assertNotNull(r1);
String poolName = r1.getAttributes().getPoolName();
assertNotNull(poolName);
PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
assertNotNull(pool);
Connection conn1 = pool.acquireConnection(new ServerLocation(host, PORT2));
assertNotNull(conn1);
assertEquals(PORT2, conn1.getServer().getPort());
ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
srp.destroyRegionOnForTestsOnly(conn1, new EventID(new byte[] { 1 }, 1, 1), null);
} catch (Exception ex) {
ex.printStackTrace();
fail("while setting acquireConnections " + ex);
}
}
Aggregations