use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class HARQueueNewImplDUnitTest method createClientCache.
public static void createClientCache(String host, Integer port1, Integer port2, String rLevel, Boolean addListener) throws Exception {
CacheServerTestUtil.disableShufflingOfEndpoints();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new HARQueueNewImplDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
ClientServerTestCase.configureConnectionPool(factory, host, port1.intValue(), port2.intValue(), true, Integer.parseInt(rLevel), 2, null, 1000, 250, false);
factory.setScope(Scope.LOCAL);
if (addListener.booleanValue()) {
factory.addCacheListener(new CacheListenerAdapter() {
public void afterInvalidate(EntryEvent event) {
logger.fine("Invalidate Event: <" + event.getKey() + ", " + event.getNewValue() + ">");
numOfInvalidates++;
}
public void afterCreate(EntryEvent event) {
logger.fine("Create Event: <" + event.getKey() + ", " + event.getNewValue() + ">");
numOfCreates++;
}
public void afterUpdate(EntryEvent event) {
logger.fine("Update Event: <" + event.getKey() + ", " + event.getNewValue() + ">");
numOfUpdates++;
}
});
}
RegionAttributes attrs = factory.create();
cache.createRegion(regionName, attrs);
logger = cache.getLogger();
}
use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class PRDeltaPropagationDUnitTest method createServerCache.
public static Integer createServerCache(Boolean isListAttach, Boolean isEmpty) throws Exception {
Properties props = new Properties();
new PRDeltaPropagationDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setConcurrencyChecksEnabled(true);
if (isEmpty.booleanValue()) {
factory.setDataPolicy(DataPolicy.EMPTY);
} else {
factory.setDataPolicy(DataPolicy.REPLICATE);
}
lastKeyReceived = false;
RegionAttributes attrs = factory.create();
deltaPR = cache.createRegion(REGION_NAME, attrs);
AttributesMutator am = deltaPR.getAttributesMutator();
if (isListAttach.booleanValue()) {
am.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
if (event.getNewValue() == null)
isFailed = true;
if (event.getKey().equals(LAST_KEY)) {
lastKeyReceived = true;
}
}
@Override
public void afterUpdate(EntryEvent event) {
if (event.getNewValue() == null)
isFailed = true;
}
});
}
CacheServer server = cache.addCacheServer();
int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
server.setPort(port);
// ensures updates to be sent instead of invalidations
server.setNotifyBySubscription(true);
server.start();
return new Integer(server.getPort());
}
use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class PRDeltaPropagationDUnitTest method createClientCache.
public static void createClientCache(Integer port1, Integer port2) throws Exception {
PRDeltaPropagationDUnitTest test = new PRDeltaPropagationDUnitTest();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
test.createCache(props);
lastKeyReceived = false;
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer("localhost", port1).addServer("localhost", port2).setSubscriptionEnabled(true).setSubscriptionRedundancy(1).setThreadLocalConnections(true).setMinConnections(6).setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(5).create("PRDeltaPropagationDUnitTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setPoolName(p.getName());
factory.setCloningEnabled(false);
factory.setConcurrencyChecksEnabled(true);
factory.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
if (LAST_KEY.equals(event.getKey())) {
lastKeyReceived = true;
}
}
});
RegionAttributes attrs = factory.create();
deltaPR = cache.createRegion(REGION_NAME, attrs);
// deltaPR.create(DELTA_KEY, new PRDeltaTestImpl());
deltaPR.registerInterest("ALL_KEYS");
pool = p;
}
use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class WANTestBase method addCacheListenerAndDestroyRegion.
public static void addCacheListenerAndDestroyRegion(String regionName) {
final Region region = cache.getRegion(Region.SEPARATOR + regionName);
assertNotNull(region);
CacheListenerAdapter cl = new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
if ((Long) event.getKey() == 99) {
region.destroyRegion();
}
}
};
region.getAttributesMutator().addCacheListener(cl);
}
use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class DiskRegionJUnitTest method testClearInteractionWithLRUList_Bug37605.
/**
* If an entry which has just been written on the disk, sees clear just before updating the
* LRULiist, then that deleted entry should not go into the LRUList
*/
@Test
public void testClearInteractionWithLRUList_Bug37605() throws Exception {
DiskRegionProperties props = new DiskRegionProperties();
props.setOverflow(true);
props.setOverFlowCapacity(1);
props.setDiskDirs(dirs);
props.setRegionName("IGNORE_EXCEPTION_testClearInteractionWithLRUList_Bug37605");
final Region region = DiskRegionHelperFactory.getSyncOverFlowAndPersistRegion(cache, props);
final Thread th = new Thread(new Runnable() {
public void run() {
region.clear();
}
});
region.getAttributesMutator().setCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
th.start();
}
});
region.create("key1", "value1");
try {
cache.getLogger().info("waiting for clear to finish");
ThreadUtils.join(th, 30 * 1000);
} catch (Exception ie) {
DiskRegionJUnitTest.this.exceptionOccurred = true;
DiskRegionJUnitTest.this.failureCause = ie.toString();
}
assertFalse(this.failureCause, this.exceptionOccurred);
NewLRUClockHand lruList = ((VMLRURegionMap) ((LocalRegion) region).entries)._getLruList();
assertEquals(region.size(), 0);
lruList.audit();
assertNull("The LRU List should have been empty instead it contained a cleared entry", lruList.getLRUEntry());
}
Aggregations