use of edu.snu.mist.core.task.DefaultQueryImpl 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();
}
Aggregations