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 QueryIndexUpdateRIDUnitTest method asyncRegisterInterestList.
/* Register Interest on data on server */
public void asyncRegisterInterestList(VM vm, final String regionName, final int keySize, final int policy, final int start) {
vm.invokeAsync(new CacheSerializableRunnable("Register InterestList") {
public void run2() throws CacheException {
// Get Query Service.
Region region = null;
try {
if ("root".equals(regionName)) {
region = getRootRegion();
} else {
region = getRootRegion().getSubregion(regionName);
}
region.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
} catch (Exception cqe) {
AssertionError err = new AssertionError("Failed to get Region.");
err.initCause(cqe);
throw err;
}
try {
switch(policy) {
case REGEX:
region.registerInterestRegex(REGULAR_EXPRESSION);
break;
case KEYS:
List list = new ArrayList();
for (int i = start != 0 ? start : 1; i <= keySize; i++) {
list.add(KEY + i);
}
region.registerInterest(list);
break;
default:
region.registerInterest("ALL_KEYS");
}
} catch (Exception ex) {
AssertionError err = new AssertionError("Failed to Register InterestList");
err.initCause(ex);
throw err;
}
}
});
}
use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.
the class DestroyEntryPropagationDUnitTest method waitForDestroyEvent.
private static void waitForDestroyEvent(Region r, final Object key) {
final CertifiableTestCacheListener ccl = (CertifiableTestCacheListener) r.getAttributes().getCacheListener();
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return ccl.destroys.contains(key);
}
public String description() {
return "waiting for destroy event for " + key;
}
};
Wait.waitForCriterion(ev, 10 * 1000, 200, true);
ccl.destroys.remove(key);
}
use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.
the class ConnectionPoolDUnitTest method test016InvalidateAndDestroyToEmptyCCPropagation.
/**
* Tests that invalidates and destroys are propagated to {@link Pool}s correctly to
* DataPolicy.EMPTY + InterestPolicy.CACHE_CONTENT
*
* @since GemFire 5.0
*/
@Test
public void test016InvalidateAndDestroyToEmptyCCPropagation() 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());
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 createEmpty = 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);
factory.setDataPolicy(DataPolicy.EMPTY);
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.CACHE_CONTENT));
Region rgn = createRegion(name, factory.create());
rgn.registerInterestRegex(".*", false, false);
}
};
SerializableRunnable createNormal = 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(createEmpty);
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(createNormal);
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();
List l = ctl.getEventHistory();
assertEquals(0, l.size());
}
});
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);
}
}
});
vm1.invoke(new CacheSerializableRunnable("Verify destroys") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
List l = ctl.getEventHistory();
assertEquals(0, l.size());
}
});
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, "createCB" + 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();
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);
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());
}
});
}
Aggregations