use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class HAClearDUnitTest method createClientCache.
public static void createClientCache(String hostName, Integer port1, Integer port2, Boolean listenerAttached, Boolean registerInterest) throws Exception {
int PORT1 = port1.intValue();
int PORT2 = port2.intValue();
boolean isListenerAttached = listenerAttached.booleanValue();
boolean isRegisterInterest = registerInterest.booleanValue();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new HAClearDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
ClientServerTestCase.configureConnectionPool(factory, hostName, new int[] { PORT1, PORT2 }, true, -1, 2, null);
if (isListenerAttached) {
factory.setCacheListener(new CacheListenerAdapter() {
public void afterRegionClear(RegionEvent event) {
LogWriterUtils.getLogWriter().info("-------> afterRegionClear received");
synchronized (HAClearDUnitTest.class) {
gotClearCallback = true;
HAClearDUnitTest.class.notifyAll();
}
}
public void afterRegionDestroy(RegionEvent event) {
synchronized (HAClearDUnitTest.class) {
LogWriterUtils.getLogWriter().info("-------> afterRegionDestroy received");
gotDestroyRegionCallback = true;
HAClearDUnitTest.class.notifyAll();
}
}
});
}
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME);
assertNotNull(region);
if (isRegisterInterest) {
region.registerInterest("ALL_KEYS", InterestResultPolicy.NONE);
} else {
// don't want data but do want events
region.registerInterestRegex("*.", false, false);
}
}
use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class EventIdOptimizationDUnitTest method createClientCache2.
/**
* Creates the client cache2, connected to server3
*
* @param port - bridgeserver port
* @throws Exception - thrown if any problem occurs in setting up the client
*/
public static void createClientCache2(String hostName, Integer port) throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new EventIdOptimizationDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
ClientServerTestCase.configureConnectionPool(factory, hostName, port.intValue(), -1, true, -1, 2, null);
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.addCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
String key = (String) event.getKey();
validateEventsAtReceivingClientListener(key);
}
public void afterDestroy(EntryEvent event) {
String key = (String) event.getKey();
validateEventsAtReceivingClientListener(key);
}
public void afterRegionDestroy(RegionEvent event) {
validateEventsAtReceivingClientListener(" <destroyRegion Event> ");
}
public void afterRegionClear(RegionEvent event) {
validateEventsAtReceivingClientListener(" <clearRegion Event> ");
}
});
RegionAttributes attrs = factory.create();
Region region = cache.createRegion(REGION_NAME, attrs);
region.registerInterest("ALL_KEYS");
for (int i = 0; i < eventIds.length; i++) {
region = cache.createRegion(REGION_NAME + i, attrs);
region.registerInterest("ALL_KEYS");
}
pool = (PoolImpl) PoolManager.find("testPool");
}
use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class VerifyEventIDGenerationInP2PDUnitTest method createServerCache.
public static void createServerCache() throws Exception {
new VerifyEventIDGenerationInP2PDUnitTest().createCache(new Properties());
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setMirrorType(MirrorType.NONE);
factory.setCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
if (!receiver) {
vm0.invoke(() -> VerifyEventIDGenerationInP2PDUnitTest.setEventIDData(((EntryEventImpl) event).getEventId()));
} else {
testEventIDResult = ((EntryEventImpl) event).getEventId().equals(eventId);
}
}
});
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
}
use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class PRDeltaPropagationDUnitTest method createClientCache.
public static void createClientCache(Integer port1, Boolean subscriptionEnable, Boolean isEmpty, Boolean isCq) throws Exception {
PRDeltaPropagationDUnitTest test = new PRDeltaPropagationDUnitTest();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
test.createCache(props);
lastKeyReceived = false;
queryUpdateExecuted = false;
queryDestroyExecuted = false;
notADeltaInstanceObj = false;
isFailed = false;
procced = false;
numValidCqEvents = 0;
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer("localhost", port1).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setThreadLocalConnections(true).setMinConnections(6).setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(5).create("PRDeltaPropagationDUnitTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(true);
if (isEmpty.booleanValue()) {
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
factory.setDataPolicy(DataPolicy.EMPTY);
}
factory.setPoolName(p.getName());
factory.setCloningEnabled(false);
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);
if (subscriptionEnable.booleanValue()) {
deltaPR.registerInterest("ALL_KEYS");
}
pool = p;
if (isCq.booleanValue()) {
CqAttributesFactory cqf = new CqAttributesFactory();
CqListenerAdapter cqlist = new CqListenerAdapter() {
@Override
@SuppressWarnings("synthetic-access")
public void onEvent(CqEvent cqEvent) {
if (LAST_KEY.equals(cqEvent.getKey().toString())) {
lastKeyReceived = true;
} else if (!(cqEvent.getNewValue() instanceof Delta)) {
notADeltaInstanceObj = true;
} else if (cqEvent.getQueryOperation().isUpdate() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
queryUpdateExecuted = true;
} else if (cqEvent.getQueryOperation().isDestroy() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
queryDestroyExecuted = true;
}
if (forOldNewCQVarification) {
if (DELTA_KEY.equals(cqEvent.getKey().toString())) {
if (numValidCqEvents == 0 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 8) {
procced = true;
} else if (procced && numValidCqEvents == 1 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 10) {
// this tell us that every thing is fine
isFailed = true;
}
}
}
numValidCqEvents++;
}
};
cqf.addCqListener(cqlist);
CqAttributes cqa = cqf.create();
CqQuery cq = cache.getQueryService().newCq("CQ_Delta", CQ, cqa);
cq.execute();
}
}
use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class ClientToServerDeltaDUnitTest method createServerCache.
/*
* create server cache
*/
public static Integer createServerCache(Boolean attachListener, Boolean isEmpty, Boolean clone, Boolean enableDelta) throws Exception {
// for validation
updates = 0;
create = 0;
firstUpdate = null;
secondUpdate = null;
error = false;
Properties props = new Properties();
props.setProperty(DELTA_PROPAGATION, enableDelta.toString());
new ClientToServerDeltaDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setConcurrencyChecksEnabled(true);
if (isEmpty) {
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
factory.setDataPolicy(DataPolicy.EMPTY);
} else {
factory.setDataPolicy(DataPolicy.REPLICATE);
}
factory.setCloningEnabled(clone);
RegionAttributes attrs = factory.create();
region = cache.createRegion(REGION_NAME, attrs);
AttributesMutator am = region.getAttributesMutator();
if (attachListener) {
am.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
create++;
}
@Override
public void afterUpdate(EntryEvent event) {
switch(updates) {
case 0:
// first delta
validateUpdates(event, firstUpdate, "FIRST");
updates++;
break;
case 1:
// combine delta
validateUpdates(event, firstUpdate, "FIRST");
validateUpdates(event, secondUpdate, "SECOND");
updates++;
break;
default:
break;
}
}
});
} else if (!isEmpty) {
am.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
switch(create) {
case 1:
validateUpdates(event, firstUpdate, "FIRST");
create++;
break;
case 2:
validateUpdates(event, secondUpdate, "SECOND");
create++;
break;
default:
create++;
break;
}
}
});
}
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());
}
Aggregations