final FlumeConfiguration conf = FlumeConfiguration.get();
// this is a slight tweak to avoid port conflicts
final AvroEventSource tes = new AvroEventSource(conf.getCollectorPort() + 1);
tes.open();
final CounterSink cnt = new CounterSink("count");
cnt.open();
Thread t = new Thread("drain") {
public void run() {
try {
EventUtil.dumpAll(tes, cnt);
} catch (Exception e) {
}
}
};
t.start(); // drain the sink.
// fork off threads threads and have them start all the same time.
final CountDownLatch sendStarted = new CountDownLatch(threads);
final CountDownLatch sendDone = new CountDownLatch(threads);
final AtomicLong sendByteSum = new AtomicLong(0);
for (int i = 0; i < threads; i++) {
final int id = i;
Thread th = new Thread() {
public void run() {
try {
EventSource txt = new NoNlASCIISynthSource(25, 100);
txt.open();
MemorySinkSource mem = new MemorySinkSource();
mem.open();
EventUtil.dumpAll(txt, mem);
txt.close();
// mem -> AvroEventSink
AvroEventSink snk = new AvroEventSink("0.0.0.0", conf
.getCollectorPort() + 1);
snk.open();
sendStarted.countDown();
sendStarted.await();
EventUtil.dumpAll(mem, snk);
mem.close();
snk.close();
sendByteSum.addAndGet(snk.sentBytes.get());
LOG.info("sink " + id + " sent " + snk.sentBytes + " bytes");
sendDone.countDown();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
th.start();
}
// wait for senders to send all
sendDone.await();
// a little delay get data to the receiving side.
Thread.sleep(1000);
tes.close();
assertEquals(25 * threads, cnt.getCount());
ReportEvent rpt = tes.getMetrics();
assertEquals(2500 * threads, sendByteSum.get());
assertEquals(2500 * threads, rpt.getLongMetric(AvroEventSource.A_BYTES_IN)
.longValue());
assertEquals(25 * threads, rpt.getLongMetric(AvroEventSource.A_DEQUEUED)