use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.
the class ConnectionPoolDUnitTest method test014InvalidateAndDestroyPropagation.
/**
* Tests that invalidates and destroys are propagated to {@link Pool}s.
*
* @since GemFire 3.5
*/
@Test
public void test014InvalidateAndDestroyPropagation() throws CacheException {
final String name = this.getName();
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
AttributesFactory factory = getBridgeServerRegionAttributes(null, null);
createRegion(name, factory.create());
// pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
});
final int port = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
SerializableRunnable create = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
getLonerSystem();
getCache();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(false);
ClientServerTestCase.configureConnectionPool(factory, host0, port, -1, true, -1, -1, null);
CertifiableTestCacheListener l = new CertifiableTestCacheListener(org.apache.geode.test.dunit.LogWriterUtils.getLogWriter());
factory.setCacheListener(l);
Region rgn = createRegion(name, factory.create());
rgn.registerInterestRegex(".*", false, false);
}
};
vm1.invoke(create);
vm1.invoke(new CacheSerializableRunnable("Populate region") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
region.put(new Integer(i), "old" + i);
}
}
});
vm2.invoke(create);
Wait.pause(5 * 1000);
vm1.invoke(new CacheSerializableRunnable("Turn on history") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
ctl.enableEventHistory();
}
});
vm2.invoke(new CacheSerializableRunnable("Update region") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
region.put(new Integer(i), "new" + i, "callbackArg" + i);
}
}
});
Wait.pause(5 * 1000);
vm1.invoke(new CacheSerializableRunnable("Verify invalidates") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
ctl.waitForInvalidated(key);
Region.Entry entry = region.getEntry(key);
assertNotNull(entry);
assertNull(entry.getValue());
}
{
List l = ctl.getEventHistory();
assertEquals(10, l.size());
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
EntryEvent ee = (EntryEvent) l.get(i);
assertEquals(key, ee.getKey());
assertEquals("old" + i, ee.getOldValue());
assertEquals(Operation.INVALIDATE, ee.getOperation());
assertEquals("callbackArg" + i, ee.getCallbackArgument());
assertEquals(true, ee.isOriginRemote());
}
}
}
});
vm2.invoke(new CacheSerializableRunnable("Validate original and destroy") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
assertEquals("new" + i, region.getEntry(key).getValue());
region.destroy(key, "destroyCB" + i);
}
}
});
Wait.pause(5 * 1000);
vm1.invoke(new CacheSerializableRunnable("Verify destroys") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
ctl.waitForDestroyed(key);
Region.Entry entry = region.getEntry(key);
assertNull(entry);
}
{
List l = ctl.getEventHistory();
assertEquals(10, l.size());
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
EntryEvent ee = (EntryEvent) l.get(i);
assertEquals(key, ee.getKey());
assertEquals(null, ee.getOldValue());
assertEquals(Operation.DESTROY, ee.getOperation());
assertEquals("destroyCB" + i, ee.getCallbackArgument());
assertEquals(true, ee.isOriginRemote());
}
}
}
});
vm2.invoke(new CacheSerializableRunnable("recreate") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
region.create(key, "create" + i);
}
}
});
Wait.pause(5 * 1000);
vm1.invoke(new CacheSerializableRunnable("Verify creates") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
List l = ctl.getEventHistory();
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("history (should be empty): " + l);
assertEquals(0, l.size());
// now see if we can get it from the server
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
assertEquals("create" + i, region.get(key, "loadCB" + i));
}
l = ctl.getEventHistory();
assertEquals(10, l.size());
for (int i = 0; i < 10; i++) {
Object key = new Integer(i);
EntryEvent ee = (EntryEvent) l.get(i);
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("processing " + ee);
assertEquals(key, ee.getKey());
assertEquals(null, ee.getOldValue());
assertEquals("create" + i, ee.getNewValue());
assertEquals(Operation.LOCAL_LOAD_CREATE, ee.getOperation());
assertEquals("loadCB" + i, ee.getCallbackArgument());
assertEquals(false, ee.isOriginRemote());
}
}
});
SerializableRunnable close = new CacheSerializableRunnable("Close Pool") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.localDestroyRegion();
}
};
vm1.invoke(close);
vm2.invoke(close);
vm0.invoke(new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
});
}
use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.
the class ConnectionPoolDUnitTest method test022ClientRegisterUnregisterRequests.
@Test
public void test022ClientRegisterUnregisterRequests() throws CacheException {
final String regionName1 = this.getName() + "-1";
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM client = host.getVM(2);
SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setConcurrencyChecksEnabled(false);
createRegion(regionName1, factory.create());
// pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
};
// Create server1.
server1.invoke(createServer);
final int port = server1.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server1.getHost());
SerializableRunnable createPool = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
getLonerSystem();
getCache();
Region region1 = null;
AttributesFactory regionFactory = new AttributesFactory();
regionFactory.setScope(Scope.LOCAL);
regionFactory.setConcurrencyChecksEnabled(false);
ClientServerTestCase.configureConnectionPool(regionFactory, host0, port, -1, true, -1, -1, null);
region1 = createRegion(regionName1, regionFactory.create());
region1.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()));
}
};
// Create client.
client.invoke(createPool);
// Init values at server.
server1.invoke(new CacheSerializableRunnable("Create values") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
for (int i = 0; i < 20; i++) {
region1.put("key-string-" + i, "value-" + i);
}
}
});
// Put some values on the client.
client.invoke(new CacheSerializableRunnable("Put values client") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
for (int i = 0; i < 10; i++) {
region1.put("key-string-" + i, "client-value-" + i);
}
}
});
SerializableRunnable closePool = new CacheSerializableRunnable("Close Pool") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
String pName = region1.getAttributes().getPoolName();
region1.localDestroyRegion();
PoolImpl p = (PoolImpl) PoolManager.find(pName);
p.destroy();
}
};
client.invoke(closePool);
SerializableRunnable validateClientRegisterUnRegister = new CacheSerializableRunnable("validate Client Register UnRegister") {
public void run2() throws CacheException {
for (Iterator bi = getCache().getCacheServers().iterator(); bi.hasNext(); ) {
CacheServerImpl bsi = (CacheServerImpl) bi.next();
final CacheClientNotifierStats ccnStats = bsi.getAcceptor().getCacheClientNotifier().getStats();
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return ccnStats.getClientRegisterRequests() == ccnStats.getClientUnRegisterRequests();
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 62 * 1000, 200, true);
assertEquals("HealthMonitor Client Register/UnRegister mismatch.", ccnStats.getClientRegisterRequests(), ccnStats.getClientUnRegisterRequests());
}
}
};
server1.invoke(validateClientRegisterUnRegister);
server1.invoke(new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
});
}
use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.
the class DestroyEntryPropagationDUnitTest method createServerCache.
private static Integer createServerCache() throws Exception {
new DestroyEntryPropagationDUnitTest().createCache(new Properties());
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
CacheServer server = cache.addCacheServer();
int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
server.setPort(port);
server.setNotifyBySubscription(true);
server.start();
return new Integer(server.getPort());
}
use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.
the class DestroyEntryPropagationDUnitTest method createClientCache.
private static void createClientCache(String host, Integer port1, Integer port2) throws Exception {
int PORT1 = port1.intValue();
int PORT2 = port2.intValue();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new DestroyEntryPropagationDUnitTest().createCache(props);
CacheServerTestUtil.disableShufflingOfEndpoints();
Pool p;
try {
p = PoolManager.createFactory().addServer(host, PORT1).addServer(host, PORT2).setSubscriptionEnabled(true).setSubscriptionRedundancy(-1).setReadTimeout(2000).setSocketBufferSize(1000).setMinConnections(4).create("EntryPropagationDUnitTestPool");
} finally {
CacheServerTestUtil.enableShufflingOfEndpoints();
}
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setPoolName(p.getName());
factory.setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
}
use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.
the class CqQueryUsingPoolDUnitTest method testRegionDestroy.
/**
* This will test the events after region destory. The CQs on the destroy region needs to be
* closed.
*/
@Test
public void testRegionDestroy() throws Exception {
final Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client = host.getVM(1);
/* Init Server and Client */
createServer(server);
final int thePort = server.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server.getHost());
String poolName = "testRegionDestroy";
createPool(client, poolName, host0, thePort);
createClient(client, thePort, host0);
/* Create CQs. */
createCQ(client, poolName, "testRegionDestroy_0", cqs[0]);
createCQ(client, poolName, "testRegionDestroy_1", cqs[0]);
createCQ(client, poolName, "testRegionDestroy_2", cqs[0]);
executeCQ(client, "testRegionDestroy_0", false, null);
executeCQ(client, "testRegionDestroy_1", false, null);
executeCQ(client, "testRegionDestroy_2", false, null);
/* Init values at server. */
final int size = 10;
registerInterestListCQ(client, regions[0], size, false);
createValues(server, regions[0], size);
// Wait for client to Synch.
waitForCreated(client, "testRegionDestroy_0", KEY + 10);
// validate CQs.
validateCQ(client, "testRegionDestroy_0", /* resultSize: */
noTest, /* creates: */
size, /* updates: */
noTest, /* deletes; */
noTest, /* queryInserts: */
size, /* queryUpdates: */
0, /* queryDeletes: */
0, /* totalEvents: */
size);
// Validate InterestList.
// CREATE
client.invoke(new CacheSerializableRunnable("validate updates") {
@Override
public void run2() throws CacheException {
// Wait for the region to become the correct size
WaitCriterion wc = new WaitCriterion() {
String excuse;
@Override
public boolean done() {
Region region = getRootRegion().getSubregion(regions[0]);
if (region == null) {
excuse = "Can't find region";
return false;
}
int sz = region.entrySet().size();
if (sz != size) {
excuse = "Region is of size " + sz + ", expected " + size;
return false;
}
return true;
}
@Override
public String description() {
return excuse;
}
};
Wait.waitForCriterion(wc, 30 * 1000, 250, true);
Region region = getRootRegion().getSubregion(regions[0]);
assertNotNull(region);
CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
for (int i = 1; i <= 10; i++) {
ctl.waitForCreated(KEY + i);
assertNotNull(region.getEntry(KEY + i));
}
}
});
// Destroy Region.
server.invoke(new CacheSerializableRunnable("Destroy Region") {
@Override
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regions[0]);
region1.destroyRegion();
}
});
Wait.pause(2 * 1000);
validateCQCount(client, 0);
closeClient(client);
closeServer(server);
}
Aggregations