Search in sources :

Example 41 with AsyncEventQueue

use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.

the class MyGatewayEventSubstitutionFilter method waitForAsyncQueueToGetEmpty.

public static void waitForAsyncQueueToGetEmpty(String asyncQueueId) {
    AsyncEventQueue theAsyncEventQueue = null;
    Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues();
    for (AsyncEventQueue asyncChannel : asyncEventChannels) {
        if (asyncQueueId.equals(asyncChannel.getId())) {
            theAsyncEventQueue = asyncChannel;
        }
    }
    final GatewaySender sender = ((AsyncEventQueueImpl) theAsyncEventQueue).getSender();
    if (sender.isParallel()) {
        final Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
        WaitCriterion wc = new WaitCriterion() {

            public boolean done() {
                int size = 0;
                for (RegionQueue q : queues) {
                    size += q.size();
                }
                if (size == 0) {
                    return true;
                }
                return false;
            }

            public String description() {
                int size = 0;
                for (RegionQueue q : queues) {
                    size += q.size();
                }
                return "Expected queue size to be : " + 0 + " but actual entries: " + size;
            }
        };
        Wait.waitForCriterion(wc, 60000, 500, true);
    } else {
        WaitCriterion wc = new WaitCriterion() {

            public boolean done() {
                Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
                int size = 0;
                for (RegionQueue q : queues) {
                    size += q.size();
                }
                if (size == 0) {
                    return true;
                }
                return false;
            }

            public String description() {
                Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
                int size = 0;
                for (RegionQueue q : queues) {
                    size += q.size();
                }
                return "Expected queue size to be : " + 0 + " but actual entries: " + size;
            }
        };
        Wait.waitForCriterion(wc, 60000, 500, true);
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl) RegionQueue(org.apache.geode.internal.cache.RegionQueue)

Example 42 with AsyncEventQueue

use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.

the class MyGatewayEventSubstitutionFilter method validateAsyncEventForOperationDetail.

public static void validateAsyncEventForOperationDetail(String asyncQueueId, final int expectedSize, boolean isLoad, boolean isPutAll) {
    AsyncEventListener theListener = null;
    Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues();
    for (AsyncEventQueue asyncQueue : asyncEventQueues) {
        if (asyncQueueId.equals(asyncQueue.getId())) {
            theListener = asyncQueue.getAsyncEventListener();
        }
    }
    final Map eventsMap = ((MyAsyncEventListener_CacheLoader) 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);
    Collection values = eventsMap.values();
    Iterator itr = values.iterator();
    while (itr.hasNext()) {
        AsyncEvent asyncEvent = (AsyncEvent) itr.next();
        if (isLoad)
            assertTrue(asyncEvent.getOperation().isLoad());
        if (isPutAll)
            assertTrue(asyncEvent.getOperation().isPutAll());
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) Iterator(java.util.Iterator) Collection(java.util.Collection) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Example 43 with AsyncEventQueue

use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.

the class MyGatewayEventSubstitutionFilter method verifySubstitutionFilterToDataInvocations.

public static void verifySubstitutionFilterToDataInvocations(String asyncEventQueueId, int expectedToDataInvoations) {
    AsyncEventQueue queue = cache.getAsyncEventQueue(asyncEventQueueId);
    assertNotNull(queue);
    // Verify the GatewayEventSubstitutionFilter has been invoked the appropriate number of times
    SizeableGatewayEventSubstitutionFilter filter = (SizeableGatewayEventSubstitutionFilter) queue.getGatewayEventSubstitutionFilter();
    assertNotNull(filter);
    assertEquals(expectedToDataInvoations, filter.getNumToDataInvocations());
}
Also used : AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue)

Example 44 with AsyncEventQueue

use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.

the class MyGatewayEventSubstitutionFilter method createConcurrentAsyncEventQueue.

public static void createConcurrentAsyncEventQueue(String asyncChannelId, boolean isParallel, Integer maxMemory, Integer batchSize, boolean isConflation, boolean isPersistent, String diskStoreName, boolean isDiskSynchronous, int dispatcherThreads, OrderPolicy policy) {
    createDiskStore(asyncChannelId, diskStoreName);
    AsyncEventListener asyncEventListener = new MyAsyncEventListener();
    AsyncEventQueueFactory factory = getInitialAsyncEventQueueFactory(isParallel, maxMemory, batchSize, isPersistent, diskStoreName);
    factory.setDiskSynchronous(isDiskSynchronous);
    factory.setBatchConflationEnabled(isConflation);
    factory.setOrderPolicy(policy);
    AsyncEventQueue asyncChannel = factory.create(asyncChannelId, asyncEventListener);
}
Also used : AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Example 45 with AsyncEventQueue

use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.

the class MyGatewayEventSubstitutionFilter method killAsyncEventQueue.

public static Boolean killAsyncEventQueue(String asyncQueueId) {
    Set<AsyncEventQueue> queues = cache.getAsyncEventQueues();
    AsyncEventQueueImpl queue = null;
    for (AsyncEventQueue q : queues) {
        if (q.getId().equals(asyncQueueId)) {
            queue = (AsyncEventQueueImpl) q;
            break;
        }
    }
    if (queue.isPrimary()) {
        LogWriterUtils.getLogWriter().info("AsyncEventQueue is killed by a test");
        cache.getDistributedSystem().disconnect();
        return Boolean.TRUE;
    }
    return Boolean.FALSE;
}
Also used : AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl)

Aggregations

AsyncEventQueue (org.apache.geode.cache.asyncqueue.AsyncEventQueue)62 Test (org.junit.Test)20 AsyncEventListener (org.apache.geode.cache.asyncqueue.AsyncEventListener)19 AsyncEventQueueFactory (org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory)13 AsyncEventQueueImpl (org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl)13 Cache (org.apache.geode.cache.Cache)10 GatewaySender (org.apache.geode.cache.wan.GatewaySender)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)9 UnitTest (org.apache.geode.test.junit.categories.UnitTest)8 Expectations (org.jmock.Expectations)8 DiskStore (org.apache.geode.cache.DiskStore)7 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)6 Region (org.apache.geode.cache.Region)5 AsyncEventQueueStats (org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueStats)5 RegionAttributesCreation (org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)5 File (java.io.File)4 Properties (java.util.Properties)4