@Test
public void testBatch() throws IOException, InterruptedException {
final int total = 104;
// create a batch
CounterSink cnt = new CounterSink("count");
MemorySinkSource mem = new MemorySinkSource();
FanOutSink<EventSink> fo = new FanOutSink<EventSink>(cnt, mem);
BatchingDecorator<EventSink> b = new BatchingDecorator<EventSink>(fo, 10, 0);
b.open();
for (int i = 0; i < total; i++) {
Event e = new EventImpl(("message " + i).getBytes());
b.append(e);
}
b.close();
Assert.assertEquals(11, cnt.getCount());
// unbatch the batch.
CounterSink cnt2 = new CounterSink("unbatch");
UnbatchingDecorator<EventSink> ub = new UnbatchingDecorator<EventSink>(cnt2);
Event ue = null;
ub.open();
while ((ue = mem.next()) != null) {
ub.append(ue);
}
Assert.assertEquals(total, cnt2.getCount());
}