Search in sources :

Example 46 with AsyncEventQueue

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

the class MyGatewayEventSubstitutionFilter method getAsyncEventListener.

public static AsyncEventListener getAsyncEventListener(String asyncEventQueueId) {
    AsyncEventListener theListener = null;
    Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues();
    for (AsyncEventQueue asyncQueue : asyncEventQueues) {
        if (asyncEventQueueId.equals(asyncQueue.getId())) {
            return asyncQueue.getAsyncEventListener();
        }
    }
    return null;
}
Also used : AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Example 47 with AsyncEventQueue

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

the class MyGatewayEventSubstitutionFilter method checkAsyncEventQueueUnprocessedStats.

public static void checkAsyncEventQueueUnprocessedStats(String asyncQueueId, int events) {
    Set<AsyncEventQueue> asyncQueues = cache.getAsyncEventQueues();
    AsyncEventQueue queue = null;
    for (AsyncEventQueue q : asyncQueues) {
        if (q.getId().equals(asyncQueueId)) {
            queue = q;
            break;
        }
    }
    final AsyncEventQueueStats statistics = ((AsyncEventQueueImpl) queue).getStatistics();
    assertEquals(events, (statistics.getUnprocessedEventsAddedBySecondary() + statistics.getUnprocessedTokensRemovedBySecondary()));
    assertEquals(events, (statistics.getUnprocessedEventsRemovedByPrimary() + statistics.getUnprocessedTokensAddedByPrimary()));
}
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 48 with AsyncEventQueue

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

the class MyGatewayEventSubstitutionFilter method verifySubstitutionFilterInvocations.

public static void verifySubstitutionFilterInvocations(String asyncEventQueueId, int expectedNumInvocations) {
    AsyncEventQueue queue = cache.getAsyncEventQueue(asyncEventQueueId);
    assertNotNull(queue);
    // Verify the GatewayEventSubstitutionFilter has been invoked the appropriate number of times
    MyGatewayEventSubstitutionFilter filter = (MyGatewayEventSubstitutionFilter) queue.getGatewayEventSubstitutionFilter();
    assertNotNull(filter);
    assertEquals(expectedNumInvocations, filter.getNumInvocations());
    // Verify the AsyncEventListener has received the substituted values
    MyAsyncEventListener listener = (MyAsyncEventListener) queue.getAsyncEventListener();
    final Map eventsMap = listener.getEventsMap();
    assertNotNull(eventsMap);
    assertEquals(expectedNumInvocations, eventsMap.size());
    for (Iterator i = eventsMap.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry<Integer, String> entry = (Map.Entry<Integer, String>) i.next();
        assertEquals(MyGatewayEventSubstitutionFilter.SUBSTITUTION_PREFIX + entry.getKey(), entry.getValue());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) Iterator(java.util.Iterator) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 49 with AsyncEventQueue

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

the class ClusterConfigDistributionDUnitTest method testIndexAndAsyncEventQueueCommands.

@Test
public void testIndexAndAsyncEventQueueCommands() throws Exception {
    final String DESTROY_REGION = "regionToBeDestroyed";
    gfshConnector.executeAndVerifyCommand("create region --name=" + REPLICATE_REGION + " --type=REPLICATE");
    gfshConnector.executeAndVerifyCommand("create region --name=" + PARTITION_REGION + " --type=PARTITION");
    gfshConnector.executeAndVerifyCommand("create region --name=" + DESTROY_REGION + " --type=REPLICATE");
    gfshConnector.executeAndVerifyCommand("create index --name=" + INDEX1 + " --expression=AAPL --region=" + REPLICATE_REGION);
    gfshConnector.executeAndVerifyCommand("create index --name=" + INDEX2 + " --expression=VMW --region=" + PARTITION_REGION);
    String asyncEventQueueJarPath = createAsyncEventQueueJar();
    gfshConnector.executeAndVerifyCommand("deploy --jar=" + asyncEventQueueJarPath);
    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_ASYNC_EVENT_QUEUE);
    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, AsyncEventQueue1);
    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER, "com.qcdunit.QueueCommandsDUnitTestListener");
    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISK_STORE, null);
    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCH_SIZE, "1000");
    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__GROUP, null);
    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__PERSISTENT, "false");
    csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__MAXIMUM_QUEUE_MEMORY, "1000");
    gfshConnector.executeAndVerifyCommand(csb.getCommandString());
    gfshConnector.executeAndVerifyCommand("destroy region --name=" + DESTROY_REGION);
    gfshConnector.executeAndVerifyCommand("destroy index --name=" + INDEX2 + " --region=" + PARTITION_REGION);
    gfshConnector.executeAndVerifyCommand("alter runtime --copy-on-read=true");
    // Start a new member which receives the shared configuration
    // Verify the config creation on this member
    MemberVM server = lsRule.startServerVM(2, new Properties(), locator.getPort());
    server.invoke(() -> {
        Cache cache = LocatorServerStartupRule.serverStarter.getCache();
        assertNotNull(cache);
        assertTrue(cache.getCopyOnRead());
        Region region1 = cache.getRegion(REPLICATE_REGION);
        assertNotNull(region1);
        Region region2 = cache.getRegion(PARTITION_REGION);
        assertNotNull(region2);
        Region region3 = cache.getRegion(DESTROY_REGION);
        assertNull(region3);
        // Index verification
        Index index1 = cache.getQueryService().getIndex(region1, INDEX1);
        assertNotNull(index1);
        assertNull(cache.getQueryService().getIndex(region2, INDEX2));
        // ASYNC-EVENT-QUEUE verification
        AsyncEventQueue aeq = cache.getAsyncEventQueue(AsyncEventQueue1);
        assertNotNull(aeq);
        assertFalse(aeq.isPersistent());
        assertTrue(aeq.getBatchSize() == 1000);
        assertTrue(aeq.getMaximumQueueMemory() == 1000);
    });
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) MemberVM(org.apache.geode.test.dunit.rules.MemberVM) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) Region(org.apache.geode.cache.Region) Index(org.apache.geode.cache.query.Index) Properties(java.util.Properties) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 50 with AsyncEventQueue

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

the class CacheXmlParser method endAsyncEventQueue.

private void endAsyncEventQueue() {
    AsyncEventQueueCreation asyncEventChannelCreation = (AsyncEventQueueCreation) stack.peek();
    AsyncEventQueueFactory factory = cache.createAsyncEventQueueFactory();
    factory.setParallel(asyncEventChannelCreation.isParallel());
    factory.setBatchSize(asyncEventChannelCreation.getBatchSize());
    factory.setBatchTimeInterval(asyncEventChannelCreation.getBatchTimeInterval());
    factory.setBatchConflationEnabled(asyncEventChannelCreation.isBatchConflationEnabled());
    factory.setPersistent(asyncEventChannelCreation.isPersistent());
    factory.setDiskStoreName(asyncEventChannelCreation.getDiskStoreName());
    factory.setDiskSynchronous(asyncEventChannelCreation.isDiskSynchronous());
    factory.setMaximumQueueMemory(asyncEventChannelCreation.getMaximumQueueMemory());
    factory.setDispatcherThreads(asyncEventChannelCreation.getDispatcherThreads());
    factory.setOrderPolicy(asyncEventChannelCreation.getOrderPolicy());
    factory.setForwardExpirationDestroy(asyncEventChannelCreation.isForwardExpirationDestroy());
    List<GatewayEventFilter> gatewayEventFilters = asyncEventChannelCreation.getGatewayEventFilters();
    for (GatewayEventFilter gatewayEventFilter : gatewayEventFilters) {
        factory.addGatewayEventFilter(gatewayEventFilter);
    }
    factory.setGatewayEventSubstitutionListener(asyncEventChannelCreation.getGatewayEventSubstitutionFilter());
    AsyncEventQueue asyncEventChannel = factory.create(asyncEventChannelCreation.getId(), asyncEventChannelCreation.getAsyncEventListener());
    stack.pop();
}
Also used : AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) GatewayEventFilter(org.apache.geode.cache.wan.GatewayEventFilter)

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