use of org.apache.geode.cache.CacheListener in project geode by apache.
the class CacheXml66DUnitTest method testMultipleCacheListener.
/**
* Tests multiple cache listeners on one region
*
* @since GemFire 5.0
*/
@Test
public void testMultipleCacheListener() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
CacheListener l1 = new MyTestCacheListener();
CacheListener l2 = new MySecondTestCacheListener();
attrs.addCacheListener(l1);
attrs.addCacheListener(l2);
cache.createRegion("root", attrs);
testXml(cache);
{
Cache c = getCache();
Region r = c.getRegion("root");
assertEquals(Arrays.asList(new CacheListener[] { l1, l2 }), Arrays.asList(r.getAttributes().getCacheListeners()));
AttributesMutator am = r.getAttributesMutator();
am.removeCacheListener(l2);
assertEquals(Arrays.asList(new CacheListener[] { l1 }), Arrays.asList(r.getAttributes().getCacheListeners()));
am.removeCacheListener(l1);
assertEquals(Arrays.asList(new CacheListener[] {}), Arrays.asList(r.getAttributes().getCacheListeners()));
am.addCacheListener(l1);
assertEquals(Arrays.asList(new CacheListener[] { l1 }), Arrays.asList(r.getAttributes().getCacheListeners()));
am.addCacheListener(l1);
assertEquals(Arrays.asList(new CacheListener[] { l1 }), Arrays.asList(r.getAttributes().getCacheListeners()));
am.addCacheListener(l2);
assertEquals(Arrays.asList(new CacheListener[] { l1, l2 }), Arrays.asList(r.getAttributes().getCacheListeners()));
am.removeCacheListener(l1);
assertEquals(Arrays.asList(new CacheListener[] { l2 }), Arrays.asList(r.getAttributes().getCacheListeners()));
am.removeCacheListener(l1);
assertEquals(Arrays.asList(new CacheListener[] { l2 }), Arrays.asList(r.getAttributes().getCacheListeners()));
am.initCacheListeners(new CacheListener[] { l1, l2 });
assertEquals(Arrays.asList(new CacheListener[] { l1, l2 }), Arrays.asList(r.getAttributes().getCacheListeners()));
}
}
use of org.apache.geode.cache.CacheListener in project geode by apache.
the class vmListenerToCheckHARegionQueue method testGIIBug.
@Ignore("TODO")
@Test
public void testGIIBug() throws Exception {
vm0.invoke(putFromVmBeforeGII("vm0_1"));
populateKeySet("vm0_1");
Thread t1 = new Thread() {
public void run() {
try {
createCache(new Properties());
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
CacheListener regionListener = new vmListenerToCheckHARegionQueue();
factory.setCacheListener(regionListener);
RegionAttributes attrs = factory.create();
Region region = cache.createRegion(REGION_NAME, attrs);
LogWriterUtils.getLogWriter().info("Name of the region is : " + region.getFullPath());
HARegionQueueAttributes hattr = new HARegionQueueAttributes();
// setting expiry time for the regionqueue.
hattr.setExpiryTime(12000000);
RegionQueue regionqueue = null;
regionqueue = HARegionQueue.getHARegionQueueInstance(regionQueueName, cache, hattr, HARegionQueue.NON_BLOCKING_HA_QUEUE, false);
isHARegionQueueUp = true;
vm0.invoke(setStopFlag());
assertNotNull(regionqueue);
} catch (Exception e) {
isTestFailed = true;
e.printStackTrace();
}
}
};
AsyncInvocation[] async = new AsyncInvocation[4];
async[0] = vm0.invokeAsync(putFrmVm("vm0_2"));
t1.start();
ThreadUtils.join(t1, 30 * 1000);
if (isTestFailed)
fail("HARegionQueue can not be created");
for (int count = 0; count < 1; count++) {
ThreadUtils.join(async[count], 30 * 1000);
if (async[count].exceptionOccurred()) {
Assert.fail("Got exception on " + count, async[count].getException());
}
}
total_no_puts[0] = vm0.invoke(() -> HAGIIBugDUnitTest.getTotalNoPuts());
populate_keys_after_gii();
boolean validationFlag = false;
validateResults(validationFlag);
if (keys_set_before_gii.size() != 0)
fail("Data in the HARegion Queue is inconsistent for the keys that are put before GII");
validationFlag = true;
validateResults(validationFlag);
LogWriterUtils.getLogWriter().info("No. of keys that are missed by HARegion Queue during GII " + keys_set_after_gii.size());
if (keys_set_after_gii.size() != 0)
fail("Set of the keys are missed by HARegion Queue during GII");
}
use of org.apache.geode.cache.CacheListener in project geode by apache.
the class ForceInvalidateEvictionDUnitTest method addListener.
private void addListener(VM vm) {
final String name = getUniqueName();
vm.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(name);
AttributesMutator am = region.getAttributesMutator();
am.initCacheListeners(new CacheListener[] { new MyListener() });
}
});
}
use of org.apache.geode.cache.CacheListener in project geode by apache.
the class ClearMultiVmCallBkDUnitTest method createCache.
public static void createCache() {
CacheListener aListener = new ListenerCallBk();
ds = (new ClearMultiVmCallBkDUnitTest()).getSystem(props);
cache = CacheFactory.create(ds);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
// Set Cachelisterner : aListener
factory.setCacheListener(aListener);
RegionAttributes attr = factory.create();
region = cache.createRegion("map", attr);
}
use of org.apache.geode.cache.CacheListener in project geode by apache.
the class CallbackArgDUnitTest method doCommitOtherVm.
private void doCommitOtherVm() {
VM vm = getOtherVm();
vm.invoke(new CacheSerializableRunnable("create root") {
public void run2() throws CacheException {
AttributesFactory af = new AttributesFactory();
CacheListener cl1 = new CacheListenerAdapter() {
public void afterCreate(EntryEvent e) {
assertEquals(callbackArg, e.getCallbackArgument());
}
};
af.addCacheListener(cl1);
af.setScope(Scope.DISTRIBUTED_ACK);
Region r1 = createRootRegion("r1", af.create());
Region r2 = r1.createSubregion("r2", af.create());
Region r3 = r2.createSubregion("r3", af.create());
CacheTransactionManager ctm = getCache().getCacheTransactionManager();
TransactionListener tl1 = new TransactionListenerAdapter() {
public void afterCommit(TransactionEvent e) {
assertEquals(6, e.getEvents().size());
Iterator it = e.getEvents().iterator();
while (it.hasNext()) {
EntryEvent ee = (EntryEvent) it.next();
assertEquals(callbackArg, ee.getCallbackArgument());
assertEquals(true, ee.isCallbackArgumentAvailable());
}
}
};
ctm.addListener(tl1);
ctm.begin();
r2.put("b", "value1", callbackArg);
r3.put("c", "value2", callbackArg);
r1.put("a", "value3", callbackArg);
r1.put("a2", "value4", callbackArg);
r3.put("c2", "value5", callbackArg);
r2.put("b2", "value6", callbackArg);
ctm.commit();
}
});
}
Aggregations