use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.
the class CacheXmlGeode10DUnitTest method testAsyncEventQueueIsForwardExpirationDestroyAttribute.
@SuppressWarnings("rawtypes")
@Test
public void testAsyncEventQueueIsForwardExpirationDestroyAttribute() throws Exception {
final String regionName = this.testName.getMethodName();
// Create AsyncEventQueue with Listener
final CacheCreation cache = new CacheCreation();
AsyncEventQueueFactory factory = cache.createAsyncEventQueueFactory();
AsyncEventListener listener = new MyAsyncEventListenerGeode10();
// Test for default forwardExpirationDestroy attribute value (which is false)
String aeqId1 = "aeqWithDefaultFED";
factory.create(aeqId1, listener);
AsyncEventQueue aeq1 = cache.getAsyncEventQueue(aeqId1);
assertFalse(aeq1.isForwardExpirationDestroy());
// Test by setting forwardExpirationDestroy attribute value.
String aeqId2 = "aeqWithFEDsetToTrue";
factory.setForwardExpirationDestroy(true);
factory.create(aeqId2, listener);
AsyncEventQueue aeq2 = cache.getAsyncEventQueue(aeqId2);
assertTrue(aeq2.isForwardExpirationDestroy());
// Create region and set the AsyncEventQueue
final RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.addAsyncEventQueueId(aeqId2);
final Region regionBefore = cache.createRegion(regionName, attrs);
assertNotNull(regionBefore);
assertTrue(regionBefore.getAttributes().getAsyncEventQueueIds().size() == 1);
testXml(cache);
final Cache c = getCache();
assertNotNull(c);
aeq1 = c.getAsyncEventQueue(aeqId1);
assertFalse(aeq1.isForwardExpirationDestroy());
aeq2 = c.getAsyncEventQueue(aeqId2);
assertTrue(aeq2.isForwardExpirationDestroy());
final Region regionAfter = c.getRegion(regionName);
assertNotNull(regionAfter);
assertTrue(regionAfter.getAttributes().getAsyncEventQueueIds().size() == 1);
regionAfter.localDestroyRegion();
// Clear AsyncEventQueues.
c.close();
}
use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.
the class CacheXml70DUnitTest method testAsyncEventQueue.
@Test
public void testAsyncEventQueue() throws Exception {
getSystem();
CacheCreation cache = new CacheCreation();
String id = "WBCLChannel";
AsyncEventQueueFactory factory = cache.createAsyncEventQueueFactory();
factory.setBatchSize(100);
factory.setBatchTimeInterval(500);
factory.setBatchConflationEnabled(true);
factory.setMaximumQueueMemory(200);
factory.setDiskSynchronous(true);
factory.setParallel(false);
factory.setDispatcherThreads(19);
AsyncEventListener eventListener = new MyAsyncEventListener();
AsyncEventQueue asyncEventQueue = factory.create(id, eventListener);
RegionAttributesCreation attrs = new RegionAttributesCreation();
attrs.addAsyncEventQueueId(asyncEventQueue.getId());
cache.createRegion("UserRegion", attrs);
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Set<AsyncEventQueue> asyncEventQueuesOnCache = c.getAsyncEventQueues();
assertTrue("Size of asyncEventQueues should be greater than 0", asyncEventQueuesOnCache.size() > 0);
for (AsyncEventQueue asyncEventQueueOnCache : asyncEventQueuesOnCache) {
validateAsyncEventQueue(asyncEventQueue, asyncEventQueueOnCache);
}
}
use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.
the class MyGatewayEventSubstitutionFilter method validateCustomAsyncEventListener.
public static void validateCustomAsyncEventListener(String asyncQueueId, final int expectedSize) {
AsyncEventListener theListener = null;
Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues();
for (AsyncEventQueue asyncQueue : asyncEventQueues) {
if (asyncQueueId.equals(asyncQueue.getId())) {
theListener = asyncQueue.getAsyncEventListener();
}
}
final Map eventsMap = ((CustomAsyncEventListener) theListener).getEventsMap();
assertNotNull(eventsMap);
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
if (eventsMap.size() == expectedSize) {
return true;
}
return false;
}
public String description() {
return "Expected map entries: " + expectedSize + " but actual entries: " + eventsMap.size();
}
};
// TODO:Yogs
Wait.waitForCriterion(wc, 60000, 500, true);
Iterator<AsyncEvent> itr = eventsMap.values().iterator();
while (itr.hasNext()) {
AsyncEvent event = itr.next();
assertTrue("possibleDuplicate should be true for event: " + event, event.getPossibleDuplicate());
}
}
use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.
the class MyGatewayEventSubstitutionFilter method verifyAsyncEventListenerForPossibleDuplicates.
public static void verifyAsyncEventListenerForPossibleDuplicates(String asyncEventQueueId, Set<Integer> bucketIds, int batchSize) {
AsyncEventListener theListener = null;
Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues();
for (AsyncEventQueue asyncQueue : asyncEventQueues) {
if (asyncEventQueueId.equals(asyncQueue.getId())) {
theListener = asyncQueue.getAsyncEventListener();
}
}
final Map<Integer, List<GatewaySenderEventImpl>> bucketToEventsMap = ((MyAsyncEventListener2) theListener).getBucketToEventsMap();
assertNotNull(bucketToEventsMap);
assertTrue(bucketIds.size() > 1);
for (int bucketId : bucketIds) {
List<GatewaySenderEventImpl> eventsForBucket = bucketToEventsMap.get(bucketId);
LogWriterUtils.getLogWriter().info("Events for bucket: " + bucketId + " is " + eventsForBucket);
assertNotNull(eventsForBucket);
for (int i = 0; i < batchSize; i++) {
GatewaySenderEventImpl senderEvent = eventsForBucket.get(i);
assertTrue(senderEvent.getPossibleDuplicate());
}
}
}
use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.
the class MyGatewayEventSubstitutionFilter method waitForAsyncEventQueueSize.
/**
* This method verifies the queue size of a ParallelGatewaySender. For ParallelGatewaySender
* conflation happens in a separate thread, hence test code needs to wait for some time for
* expected result
*
* @param asyncQueueId Async Queue ID
* @param numQueueEntries expected number of Queue entries
* @throws Exception
*/
public static void waitForAsyncEventQueueSize(String asyncQueueId, final int numQueueEntries) throws Exception {
AsyncEventQueue theAsyncEventQueue = null;
Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues();
for (AsyncEventQueue asyncChannel : asyncEventChannels) {
if (asyncQueueId.equals(asyncChannel.getId())) {
theAsyncEventQueue = asyncChannel;
}
}
GatewaySender sender = ((AsyncEventQueueImpl) theAsyncEventQueue).getSender();
if (sender.isParallel()) {
final Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
Wait.waitForCriterion(new WaitCriterion() {
public String description() {
return "Waiting for EventQueue size to be " + numQueueEntries;
}
public boolean done() {
boolean done = numQueueEntries == queues.toArray(new RegionQueue[queues.size()])[0].getRegion().size();
return done;
}
}, MAX_WAIT, 500, true);
} else {
throw new Exception("This method should be used for only ParallelGatewaySender,SerialGatewaySender should use checkAsyncEventQueueSize() method instead");
}
}
Aggregations