use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class HAEventIdPropagationDUnitTest method createClientCache.
/** function to create client cache * */
public static void createClientCache(String hostName, Integer port1) throws Exception {
int PORT1 = port1.intValue();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new HAEventIdPropagationDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
PoolImpl pi = (PoolImpl) ClientServerTestCase.configureConnectionPool(factory, hostName, new int[] { PORT1 }, true, -1, 2, null);
factory.setScope(Scope.DISTRIBUTED_ACK);
CacheListener clientListener = new HAEventIdPropagationListenerForClient();
factory.setCacheListener(clientListener);
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME);
assertNotNull(region);
region.registerInterest("ALL_KEYS", InterestResultPolicy.NONE);
System.out.println("KKKKKK:[" + pi.getName() + "]");
;
PoolImpl p2 = (PoolImpl) PoolManager.find("testPool");
System.out.println("QQQQ:" + p2);
pool = pi;
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DestroyEntryPropagationDUnitTest method testVerifyDestroyNotReceivedBySender.
/**
* This tests whether the destroy are received by the sender or not if there are situation of
* Interest List fail over
*/
// GEODE-897: random port, time sensitive, waitForCriterion, 2 minute
@Category(FlakyTest.class)
// timeouts, eats exception (1 fixed)
@Test
public void testVerifyDestroyNotReceivedBySender() {
final int maxWaitTime = Integer.getInteger(WAIT_PROPERTY, WAIT_DEFAULT).intValue();
// First create entries on both servers via the two client
vm2.invoke(() -> DestroyEntryPropagationDUnitTest.createEntriesK1andK2());
vm3.invoke(() -> DestroyEntryPropagationDUnitTest.createEntriesK1andK2());
vm2.invoke(() -> DestroyEntryPropagationDUnitTest.registerKey1());
vm3.invoke(() -> DestroyEntryPropagationDUnitTest.registerKey1());
// Induce fail over of InterestList Endpoint to Server 2 by killing server1
vm0.invoke(() -> DestroyEntryPropagationDUnitTest.killServer(new Integer(PORT1)));
// Wait for 10 seconds to allow fail over. This would mean that Interest
// has failed over to Server2.
vm2.invoke(new CacheSerializableRunnable("Wait for server on port1 to be dead") {
public void run2() throws CacheException {
Region r = cache.getRegion(REGION_NAME);
try {
// Used in the case where we don't have a LiveServerMonitorThread
r.put("ping", "pong1");
} catch (CacheWriterException itsOK) {
}
try {
// Used in the case where we don't have a LiveServerMonitorThread
r.put("ping", "pong1");
} catch (CacheWriterException itsOK) {
}
String poolName = r.getAttributes().getPoolName();
assertNotNull(poolName);
final PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
assertNotNull(pool);
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return pool.getConnectedServerCount() != 2;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, maxWaitTime, 200, true);
}
});
// Start Server1 again so that both clients1 & Client 2 will establish
// connection to server1 too.
vm0.invoke(() -> DestroyEntryPropagationDUnitTest.startServer(new Integer(PORT1)));
vm2.invoke(new CacheSerializableRunnable("Wait for server on port1 to spring to life") {
public void run2() throws CacheException {
Region r = cache.getRegion(REGION_NAME);
String poolName = r.getAttributes().getPoolName();
assertNotNull(poolName);
final PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
assertNotNull(pool);
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return pool.getConnectedServerCount() == 2;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, maxWaitTime, 200, true);
}
});
// Do a destroy on Server1 via Connection object from client1.
// Client1 should not receive updated value while client2 should receive
vm2.invoke(() -> acquireConnectionsAndDestroyEntriesK1andK2());
// pause(10000);
// Check if both the puts ( on key1 & key2 ) have reached the servers
vm0.invoke(() -> DestroyEntryPropagationDUnitTest.verifyEntriesAreDestroyed());
vm1.invoke(() -> DestroyEntryPropagationDUnitTest.verifyEntriesAreDestroyed());
vm2.invoke(() -> DestroyEntryPropagationDUnitTest.verifyNoDestroyEntryInSender());
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DestroyEntryPropagationDUnitTest method acquireConnectionsAndDestroyEntriesK1andK2.
private void acquireConnectionsAndDestroyEntriesK1andK2() {
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 conn = pool.acquireConnection();
final Connection conn1;
if (conn.getServer().getPort() != PORT2) {
// Ensure we have a server with the proper port
conn1 = pool.acquireConnection();
} else {
conn1 = conn;
}
assertNotNull(conn1);
assertEquals(PORT2, conn1.getServer().getPort());
ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
srp.destroyOnForTestsOnly(conn1, "key1", null, Operation.DESTROY, new EventIDHolder(new EventID(new byte[] { 1 }, 100000, 1)), null);
srp.destroyOnForTestsOnly(conn1, "key2", null, Operation.DESTROY, new EventIDHolder(new EventID(new byte[] { 1 }, 100000, 2)), null);
} catch (Exception ex) {
throw new AssertionError("Failed while setting acquireConnectionsAndDestroyEntry ", ex);
}
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DurableClientBug39997DUnitTest method testNoServerAvailableOnStartup.
@Test
public void testNoServerAvailableOnStartup() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final String hostName = NetworkUtils.getServerHostName(host);
final int port = AvailablePortHelper.getRandomAvailableTCPPort();
vm0.invoke(new SerializableRunnable("create cache") {
public void run() {
getSystem(getClientProperties());
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(hostName, port).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).create("DurableClientReconnectDUnitTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setPoolName(p.getName());
Cache cache = getCache();
Region region1 = cache.createRegion("region", factory.create());
cache.readyForEvents();
try {
region1.registerInterest("ALL_KEYS");
fail("Should have received an exception trying to register interest");
} catch (NoSubscriptionServersAvailableException expected) {
// this is expected
}
}
});
vm1.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
cache.createRegion("region", factory.create());
CacheServer server = cache.addCacheServer();
server.setPort(port);
try {
server.start();
} catch (IOException e) {
Assert.fail("couldn't start server", e);
}
}
});
vm0.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
final Region region = cache.getRegion("region");
Wait.waitForCriterion(new WaitCriterion() {
public String description() {
return "Wait for register interest to succeed";
}
public boolean done() {
try {
region.registerInterest("ALL_KEYS");
} catch (NoSubscriptionServersAvailableException e) {
return false;
}
return true;
}
}, 30000, 1000, true);
}
});
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DurableClientReconnectDUnitTest method createCacheClientAndConnectToSingleServer.
private void createCacheClientAndConnectToSingleServer(String host, int redundancyLevel) {
try {
final String durableClientId = "DurableClientReconnectDUnitTest_client";
// keep the client alive for 60 seconds
final int durableClientTimeout = 60;
Properties props = getClientDistributedSystemProperties(durableClientId, durableClientTimeout);
instance = new DurableClientReconnectDUnitTest();
instance.createCache(props);
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host, PORT1.intValue()).setSubscriptionEnabled(true).setReadTimeout(10000).setSubscriptionRedundancy(redundancyLevel).create("DurableClientReconnectDUnitTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setPoolName(p.getName());
RegionAttributes attrs = factory.create();
Region r = cache.createRegion(REGION_NAME, attrs);
assertNotNull(r);
pool = p;
conn = pool.acquireConnection();
assertNotNull(conn);
cache.readyForEvents();
} catch (Exception e) {
Assert.fail("test failed due to ", e);
}
}
Aggregations