Search in sources :

Example 11 with AsyncEvent

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

the class PDXAsyncEventQueueDUnitTest method createSerialAsyncEventQueue.

protected void createSerialAsyncEventQueue(VM vm, final boolean persistent) {
    SerializableCallable createSystem = new SerializableCallable() {

        public Object call() throws Exception {
            Cache cache = getCache();
            AsyncEventQueue sender = cache.createAsyncEventQueueFactory().setBatchSize(2).setBatchTimeInterval(1000).setBatchConflationEnabled(false).setPersistent(persistent).create("queue", new AsyncEventListener() {

                @Override
                public void close() {
                // TODO Auto-generated method stub
                }

                @Override
                public boolean processEvents(List<AsyncEvent> events) {
                    // do nothing
                    return true;
                }
            });
            return null;
        }
    };
    vm.invoke(createSystem);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent) Cache(org.apache.geode.cache.Cache) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Example 12 with AsyncEvent

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

the class LuceneEventListenerJUnitTest method shouldHandleBucketNotFoundExceptionWithoutLoggingError.

@Test
public void shouldHandleBucketNotFoundExceptionWithoutLoggingError() throws BucketNotFoundException {
    RepositoryManager manager = Mockito.mock(RepositoryManager.class);
    Logger log = Mockito.mock(Logger.class);
    Mockito.when(manager.getRepository(any(), any(), any())).thenThrow(BucketNotFoundException.class);
    LuceneEventListener listener = new LuceneEventListener(manager);
    listener.logger = log;
    AsyncEvent event = Mockito.mock(AsyncEvent.class);
    boolean result = listener.processEvents(Arrays.asList(new AsyncEvent[] { event }));
    assertFalse(result);
    verify(log, never()).error(anyString(), any(Exception.class));
}
Also used : RepositoryManager(org.apache.geode.cache.lucene.internal.repository.RepositoryManager) Logger(org.apache.logging.log4j.Logger) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent) IOException(java.io.IOException) BucketNotFoundException(org.apache.geode.internal.cache.BucketNotFoundException) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 13 with AsyncEvent

use of org.apache.geode.cache.asyncqueue.AsyncEvent 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 14 with AsyncEvent

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

the class CustomAsyncEventListener method processEvents.

public boolean processEvents(List<AsyncEvent> events) {
    int i = 0;
    for (AsyncEvent event : events) {
        i++;
        if (!exceptionThrown && i == 40) {
            i = 0;
            exceptionThrown = true;
            throw new Error("TestError");
        }
        if (exceptionThrown) {
            eventsMap.put((Long) event.getKey(), event);
        }
    }
    return true;
}
Also used : AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent)

Example 15 with AsyncEvent

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

the class MyAsyncEventListener2 method processEvents.

public boolean processEvents(List<AsyncEvent> events) {
    for (AsyncEvent event : events) {
        GatewaySenderEventImpl gatewayEvent = (GatewaySenderEventImpl) event;
        int bucketId = gatewayEvent.getBucketId();
        List<GatewaySenderEventImpl> bucketEvents = this.bucketToEventsMap.get(bucketId);
        if (bucketEvents == null) {
            bucketEvents = new ArrayList<GatewaySenderEventImpl>();
            bucketEvents.add(gatewayEvent);
            this.bucketToEventsMap.put(bucketId, bucketEvents);
        } else {
            bucketEvents.add(gatewayEvent);
        }
    }
    return true;
}
Also used : AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent)

Aggregations

AsyncEvent (org.apache.geode.cache.asyncqueue.AsyncEvent)16 AsyncEventListener (org.apache.geode.cache.asyncqueue.AsyncEventListener)4 IOException (java.io.IOException)3 AsyncEventQueue (org.apache.geode.cache.asyncqueue.AsyncEventQueue)3 RepositoryManager (org.apache.geode.cache.lucene.internal.repository.RepositoryManager)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 InternalGemFireError (org.apache.geode.InternalGemFireError)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)2 Cache (org.apache.geode.cache.Cache)2 Region (org.apache.geode.cache.Region)2 IndexRepository (org.apache.geode.cache.lucene.internal.repository.IndexRepository)2 BucketNotFoundException (org.apache.geode.internal.cache.BucketNotFoundException)2 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)2 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)2