Search in sources :

Example 16 with AsyncEventQueue

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

the class MyGatewayEventSubstitutionFilter method createAsyncEventQueueWithCustomListener.

public static void createAsyncEventQueueWithCustomListener(String asyncChannelId, boolean isParallel, Integer maxMemory, Integer batchSize, boolean isConflation, boolean isPersistent, String diskStoreName, boolean isDiskSynchronous, int nDispatchers) {
    IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName());
    try {
        createDiskStore(asyncChannelId, diskStoreName);
        AsyncEventListener asyncEventListener = new CustomAsyncEventListener();
        AsyncEventQueueFactory factory = getInitialAsyncEventQueueFactory(isParallel, maxMemory, batchSize, isPersistent, diskStoreName);
        factory.setDispatcherThreads(nDispatchers);
        AsyncEventQueue asyncChannel = factory.create(asyncChannelId, asyncEventListener);
    } finally {
        exp.remove();
    }
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) IgnoredException(org.apache.geode.test.dunit.IgnoredException) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Example 17 with AsyncEventQueue

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

the class MyGatewayEventSubstitutionFilter method checkAsyncEventQueueStats_Failover.

public static void checkAsyncEventQueueStats_Failover(String asyncEventQueueId, final int eventsReceived) {
    Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues();
    AsyncEventQueue queue = null;
    for (AsyncEventQueue q : asyncEventQueues) {
        if (q.getId().equals(asyncEventQueueId)) {
            queue = q;
            break;
        }
    }
    final AsyncEventQueueStats statistics = ((AsyncEventQueueImpl) queue).getStatistics();
    assertEquals(eventsReceived, statistics.getEventsReceived());
    assertEquals(eventsReceived, (statistics.getEventsQueued() + statistics.getUnprocessedTokensAddedByPrimary() + statistics.getUnprocessedEventsRemovedByPrimary()));
}
Also used : AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl) AsyncEventQueueStats(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueStats)

Example 18 with AsyncEventQueue

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

the class MyGatewayEventSubstitutionFilter method validateConcurrentAsyncEventQueueAttributes.

/**
   * Validate whether all the attributes set on AsyncEventQueueFactory are set on the sender
   * underneath the AsyncEventQueue.
   */
public static void validateConcurrentAsyncEventQueueAttributes(String asyncChannelId, int maxQueueMemory, int batchSize, int batchTimeInterval, boolean isPersistent, String diskStoreName, boolean isDiskSynchronous, boolean batchConflationEnabled, int dispatcherThreads, OrderPolicy policy) {
    AsyncEventQueue theChannel = null;
    Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues();
    for (AsyncEventQueue asyncChannel : asyncEventChannels) {
        if (asyncChannelId.equals(asyncChannel.getId())) {
            theChannel = asyncChannel;
        }
    }
    GatewaySender theSender = ((AsyncEventQueueImpl) theChannel).getSender();
    assertEquals("maxQueueMemory", maxQueueMemory, theSender.getMaximumQueueMemory());
    assertEquals("batchSize", batchSize, theSender.getBatchSize());
    assertEquals("batchTimeInterval", batchTimeInterval, theSender.getBatchTimeInterval());
    assertEquals("isPersistent", isPersistent, theSender.isPersistenceEnabled());
    assertEquals("diskStoreName", diskStoreName, theSender.getDiskStoreName());
    assertEquals("isDiskSynchronous", isDiskSynchronous, theSender.isDiskSynchronous());
    assertEquals("batchConflation", batchConflationEnabled, theSender.isBatchConflationEnabled());
    assertEquals("dispatcherThreads", dispatcherThreads, theSender.getDispatcherThreads());
    assertEquals("orderPolicy", policy, theSender.getOrderPolicy());
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl)

Example 19 with AsyncEventQueue

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

the class MyGatewayEventSubstitutionFilter method checkAsyncEventQueueSize.

public static void checkAsyncEventQueueSize(String asyncQueueId, int numQueueEntries) {
    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()) {
        Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
        assertEquals(numQueueEntries, queues.toArray(new RegionQueue[queues.size()])[0].getRegion().size());
    } else {
        Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
        int size = 0;
        for (RegionQueue q : queues) {
            size += q.size();
        }
        assertEquals(numQueueEntries, size);
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl) RegionQueue(org.apache.geode.internal.cache.RegionQueue)

Example 20 with AsyncEventQueue

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

the class MyGatewayEventSubstitutionFilter method createAsyncEventQueueWithDiskStore.

public static String createAsyncEventQueueWithDiskStore(String asyncChannelId, boolean isParallel, Integer maxMemory, Integer batchSize, boolean isPersistent, String diskStoreName) {
    AsyncEventListener asyncEventListener = new MyAsyncEventListener();
    File persistentDirectory = null;
    if (diskStoreName == null) {
        persistentDirectory = new File(asyncChannelId + "_disk_" + System.currentTimeMillis() + "_" + VM.getCurrentVMNum());
    } else {
        persistentDirectory = new File(diskStoreName);
    }
    LogWriterUtils.getLogWriter().info("The ds is : " + persistentDirectory.getName());
    persistentDirectory.mkdir();
    DiskStoreFactory dsf = cache.createDiskStoreFactory();
    File[] dirs1 = new File[] { persistentDirectory };
    AsyncEventQueueFactory factory = cache.createAsyncEventQueueFactory();
    factory.setBatchSize(batchSize);
    factory.setParallel(isParallel);
    if (isPersistent) {
        factory.setPersistent(isPersistent);
        factory.setDiskStoreName(dsf.setDiskDirs(dirs1).create(asyncChannelId).getName());
    }
    factory.setMaximumQueueMemory(maxMemory);
    // set dispatcher threads
    factory.setDispatcherThreads(numDispatcherThreadsForTheRun);
    AsyncEventQueue asyncChannel = factory.create(asyncChannelId, asyncEventListener);
    return persistentDirectory.getName();
}
Also used : AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

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