use of org.apache.geode.cache.RegionEvent in project geode by apache.
the class MultiVMRegionTestCase method testRemoteCacheListenerInSubregion.
/**
* Tests that a {@link CacheListener} is invoked in a remote VM.
*/
@Test
public void testRemoteCacheListenerInSubregion() throws Exception {
assumeTrue(supportsSubregions());
assertTrue(getRegionAttributes().getScope().isDistributed());
final String name = this.getUniqueName();
SerializableRunnable create = new CacheSerializableRunnable("Create Region") {
@Override
public void run2() throws CacheException {
createRegion(name);
}
};
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
final VM vm1 = host.getVM(1);
vm0.invoke(new CacheSerializableRunnable("Create Root") {
@Override
public void run2() throws CacheException {
createRootRegion();
}
});
vm1.invoke(create);
vm1.invoke(new CacheSerializableRunnable("Set listener") {
@Override
public void run2() throws CacheException {
final Region region = getRootRegion().getSubregion(name);
listener = new TestCacheListener() {
@Override
public void afterRegionInvalidate2(RegionEvent event) {
assertEquals(Operation.REGION_INVALIDATE, event.getOperation());
assertEquals(region, event.getRegion());
assertTrue(event.getOperation().isDistributed());
assertFalse(event.getOperation().isExpiration());
assertTrue(event.isOriginRemote());
assertEquals(event.getCallbackArgument(), event.getDistributedMember());
}
};
region.getAttributesMutator().addCacheListener(listener);
}
});
vm0.invoke(new CacheSerializableRunnable("Invalidate Root Region") {
@Override
public void run2() throws CacheException {
getRootRegion().invalidateRegion(getSystem().getDistributedMember());
}
});
vm1.invoke(new CacheSerializableRunnable("Verify Invalidate Region") {
@Override
public void run2() throws CacheException {
listener.waitForInvocation(3000, 10);
// Setup listener for next test
final Region region = getRootRegion().getSubregion(name);
listener = new TestCacheListener() {
@Override
public void afterRegionDestroy2(RegionEvent event) {
assertEquals(Operation.REGION_DESTROY, event.getOperation());
assertEquals(region, event.getRegion());
assertTrue(event.getOperation().isDistributed());
assertFalse(event.getOperation().isExpiration());
assertTrue(event.isOriginRemote());
assertEquals(event.getCallbackArgument(), event.getDistributedMember());
}
};
region.getAttributesMutator().addCacheListener(listener);
}
});
vm0.invoke(new CacheSerializableRunnable("Destroy Root Region") {
@Override
public void run2() throws CacheException {
getRootRegion().destroyRegion(getSystem().getDistributedMember());
}
});
vm1.invoke(new CacheSerializableRunnable("Verify Destroy Region") {
@Override
public void run2() throws CacheException {
listener.waitForInvocation(3000, 10);
}
});
}
use of org.apache.geode.cache.RegionEvent in project geode by apache.
the class MapInterface2JUnitTest method testSuccessGlobalScopeInSingleVM.
@Test
public void testSuccessGlobalScopeInSingleVM() {
CacheUtils.getCache().setLockLease(10);
CacheUtils.getCache().setLockTimeout(15);
final Region region = CacheUtils.createRegion("Global", String.class, Scope.GLOBAL);
for (int i = 0; i < 10; i++) {
region.put("" + i, "" + i);
}
LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = true;
CacheObserverHolder.setInstance(new CacheObserverAdapter() {
public void afterRegionClear(RegionEvent event) {
try {
synchronized (MapInterface2JUnitTest.this) {
MapInterface2JUnitTest.this.mainThreadProceed = true;
MapInterface2JUnitTest.this.notify();
}
event.getRegion().getCache().getLogger().info("*******Main THread Notified *********");
Thread.sleep(1000);
event.getRegion().getCache().getLogger().info("******* After Sleeping 5000 *********");
} catch (InterruptedException ie) {
fail("interrupted");
}
}
});
Thread th = new Thread(new Runnable() {
public void run() {
region.clear();
}
});
th.start();
try {
synchronized (this) {
if (!this.mainThreadProceed) {
region.getCache().getLogger().info("*******Main THread is going in wait********");
this.wait();
}
}
region.getCache().getLogger().info("*******Main THread coming out of wait*********");
region.put("test", "test");
String str = (String) region.get("test");
assertNotNull("The put operation has succeeded", str);
} catch (Exception cwe) {
fail("The test experienced exception " + cwe);
}
ThreadUtils.join(th, 30 * 1000);
}
use of org.apache.geode.cache.RegionEvent in project geode by apache.
the class ClearPropagationDUnitTest method createClientCache.
public static void createClientCache(String host, Integer port1, Integer port2) throws Exception {
PORT1 = port1.intValue();
PORT2 = port2.intValue();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new ClearPropagationDUnitTest().createCache(props);
CacheServerTestUtil.disableShufflingOfEndpoints();
Pool p;
try {
p = PoolManager.createFactory().addServer(host, PORT1).addServer(host, PORT2).setSubscriptionEnabled(true).setReadTimeout(2000).setSocketBufferSize(1000).setMinConnections(4).create("ClearPropagationDUnitTestPool");
} finally {
CacheServerTestUtil.enableShufflingOfEndpoints();
}
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setPoolName(p.getName());
factory.setCacheListener(new CacheListenerAdapter() {
public void afterRegionClear(RegionEvent re) {
synchronized (ClearPropagationDUnitTest.class) {
gotClear = true;
ClearPropagationDUnitTest.class.notify();
}
}
public void afterRegionDestroy(RegionEvent re) {
synchronized (ClearPropagationDUnitTest.class) {
gotDestroyed = true;
ClearPropagationDUnitTest.class.notify();
}
}
});
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
}
use of org.apache.geode.cache.RegionEvent in project geode by apache.
the class EventIDVerificationInP2PDUnitTest method createServerCache.
public static void createServerCache(Integer type) throws Exception {
new EventIDVerificationInP2PDUnitTest().createCache(new Properties());
AttributesFactory factory = new AttributesFactory();
if (type.intValue() == DISTRIBUTED_ACK)
factory.setScope(Scope.DISTRIBUTED_ACK);
if (type.intValue() == GLOBAL)
factory.setScope(Scope.GLOBAL);
else
factory.setScope(Scope.DISTRIBUTED_NO_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.addCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
eventId = ((InternalCacheEvent) event).getEventId();
if (receiver) {
synchronized (EventIDVerificationInP2PDUnitTest.class) {
gotCallback = true;
EventIDVerificationInP2PDUnitTest.class.notify();
}
}
}
public void afterUpdate(EntryEvent event) {
eventId = ((InternalCacheEvent) event).getEventId();
if (receiver) {
synchronized (EventIDVerificationInP2PDUnitTest.class) {
gotCallback = true;
EventIDVerificationInP2PDUnitTest.class.notify();
}
}
}
public void afterDestroy(EntryEvent event) {
eventId = ((InternalCacheEvent) event).getEventId();
if (receiver) {
synchronized (EventIDVerificationInP2PDUnitTest.class) {
gotCallback = true;
EventIDVerificationInP2PDUnitTest.class.notify();
}
}
}
public void afterRegionDestroy(RegionEvent event) {
eventId = ((InternalCacheEvent) event).getEventId();
if (receiver) {
synchronized (EventIDVerificationInP2PDUnitTest.class) {
gotCallback = true;
EventIDVerificationInP2PDUnitTest.class.notify();
}
}
}
public void afterRegionInvalidate(RegionEvent event) {
eventId = ((InternalCacheEvent) event).getEventId();
if (receiver) {
synchronized (EventIDVerificationInP2PDUnitTest.class) {
gotCallback = true;
EventIDVerificationInP2PDUnitTest.class.notify();
}
}
}
});
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
}
Aggregations