Search in sources :

Example 1 with DefaultEventProcessor

use of edu.snu.mist.core.task.groupaware.eventprocessor.DefaultEventProcessor in project mist by snuspl.

the class EventProcessorTest method eventProcessorProcessingTest.

@Test
public void eventProcessorProcessingTest() throws InjectionException, InterruptedException {
    final BlockingQueue<Group> queue = new LinkedBlockingQueue<>();
    final Group group1 = createGroup("group1");
    final Group group2 = createGroup("group2");
    final Group group3 = createGroup("group3");
    final CountDownLatch countDownLatch = new CountDownLatch(31);
    final AtomicInteger numEvent1 = new AtomicInteger(10);
    final SourceOutputEmitter oc1 = mock(SourceOutputEmitter.class);
    final AtomicInteger numEvent2 = new AtomicInteger(20);
    final SourceOutputEmitter oc2 = mock(SourceOutputEmitter.class);
    final AtomicInteger numEvent3 = new AtomicInteger(1);
    final SourceOutputEmitter oc3 = mock(SourceOutputEmitter.class);
    when(oc1.numberOfEvents()).thenReturn(numEvent1.get());
    when(oc1.processAllEvent()).thenAnswer((icm) -> {
        int cnt = 0;
        while (numEvent1.getAndDecrement() != 0) {
            Thread.sleep(10);
            countDownLatch.countDown();
            cnt += 1;
        }
        return cnt;
    });
    when(oc2.numberOfEvents()).thenReturn(numEvent2.get());
    when(oc2.processAllEvent()).thenAnswer((icm) -> {
        int cnt = 0;
        while (numEvent2.getAndDecrement() != 0) {
            Thread.sleep(10);
            countDownLatch.countDown();
            cnt += 1;
        }
        return cnt;
    });
    when(oc3.numberOfEvents()).thenReturn(numEvent3.get());
    when(oc3.processAllEvent()).thenAnswer((icm) -> {
        int cnt = 0;
        while (numEvent3.getAndDecrement() != 0) {
            Thread.sleep(10);
            countDownLatch.countDown();
            cnt += 1;
        }
        return cnt;
    });
    final NextGroupSelector nextGroupSelector = new TestNextGroupSelector(queue);
    final EventProcessor eventProcessor = new DefaultEventProcessor(nextGroupSelector, 1, Long.MAX_VALUE);
    group1.setEventProcessor(eventProcessor);
    group2.setEventProcessor(eventProcessor);
    group3.setEventProcessor(eventProcessor);
    final Query query1 = new DefaultQueryImpl("q1");
    group1.addQuery(query1);
    final Query query2 = new DefaultQueryImpl("q2");
    group2.addQuery(query2);
    final Query query3 = new DefaultQueryImpl("q3");
    group3.addQuery(query3);
    query1.insert(oc1);
    query2.insert(oc2);
    query3.insert(oc3);
    eventProcessor.start();
    queue.add(group1);
    queue.add(group2);
    queue.add(group3);
    countDownLatch.await();
}
Also used : Query(edu.snu.mist.core.task.Query) DefaultEventProcessor(edu.snu.mist.core.task.groupaware.eventprocessor.DefaultEventProcessor) DefaultQueryImpl(edu.snu.mist.core.task.DefaultQueryImpl) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) NextGroupSelector(edu.snu.mist.core.task.groupaware.eventprocessor.NextGroupSelector) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventProcessor(edu.snu.mist.core.task.groupaware.eventprocessor.EventProcessor) DefaultEventProcessor(edu.snu.mist.core.task.groupaware.eventprocessor.DefaultEventProcessor) SourceOutputEmitter(edu.snu.mist.core.task.SourceOutputEmitter) Test(org.junit.Test)

Aggregations

DefaultQueryImpl (edu.snu.mist.core.task.DefaultQueryImpl)1 Query (edu.snu.mist.core.task.Query)1 SourceOutputEmitter (edu.snu.mist.core.task.SourceOutputEmitter)1 DefaultEventProcessor (edu.snu.mist.core.task.groupaware.eventprocessor.DefaultEventProcessor)1 EventProcessor (edu.snu.mist.core.task.groupaware.eventprocessor.EventProcessor)1 NextGroupSelector (edu.snu.mist.core.task.groupaware.eventprocessor.NextGroupSelector)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1