use of org.apache.geode.cache.EntryEvent 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.EntryEvent 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.EntryEvent 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.EntryEvent in project geode by apache.
the class ConflationDUnitTest method createClientCache2UniqueWriter.
/**
* create client 2 with 2 regions each with a unique writer but both having a common listener
*
* @throws Exception
*/
public static void createClientCache2UniqueWriter(String host, Integer port) throws Exception {
ConflationDUnitTest test = new ConflationDUnitTest();
cache = test.createCache(createProperties1());
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setPoolName(createPool(host, "p1", port, true).getName());
factory.addCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
String val = (String) event.getNewValue();
LogWriterUtils.getLogWriter().info("Listener received event " + event);
synchronized (ConflationDUnitTest.class) {
if (val.equals(MARKER)) {
count++;
} else {
counterCreate++;
}
if (2 == count) {
ConflationDUnitTest.class.notify();
}
}
}
public void afterUpdate(EntryEvent event) {
synchronized (this) {
counterUpdate++;
}
}
public void afterDestroy(EntryEvent event) {
synchronized (this) {
if (!event.getKey().equals(MARKER)) {
counterDestroy++;
}
}
}
});
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME1, attrs);
factory.setPoolName(createPool(host, "p2", port, true).getName());
attrs = factory.create();
cache.createRegion(REGION_NAME2, attrs);
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class ConflationDUnitTest method createClientCache2CommonWriterTest3.
public static void createClientCache2CommonWriterTest3(String host, Integer port) throws Exception {
ConflationDUnitTest test = new ConflationDUnitTest();
cache = test.createCache(createProperties1());
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setPoolName(createPool(host, "p1", port, true).getName());
factory.addCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
LogWriterUtils.getLogWriter().info("Listener received event " + event);
String val = (String) event.getNewValue();
synchronized (ConflationDUnitTest.class) {
if (val.equals(MARKER)) {
count++;
} else {
counterCreate++;
}
if (2 == count) {
ConflationDUnitTest.class.notify();
}
}
}
public void afterUpdate(EntryEvent event) {
LogWriterUtils.getLogWriter().info("Listener received event " + event);
synchronized (this) {
counterUpdate++;
}
}
public void afterDestroy(EntryEvent event) {
LogWriterUtils.getLogWriter().info("Listener received event " + event);
synchronized (this) {
if (!event.getKey().equals(MARKER)) {
counterDestroy++;
}
}
}
});
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME1, attrs);
cache.createRegion(REGION_NAME2, attrs);
}
Aggregations