// this is a slight tweak to avoid port conflicts
final ThriftEventSource tes = new ThriftEventSource(
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 (IOException 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 {
// TODO (jon) this may have different sizes due to the host it is
// running on . Needs to be fixed.
EventSource txt = new NoNlASCIISynthSource(25, 100);
txt.open();
MemorySinkSource mem = new MemorySinkSource();
mem.open();
EventUtil.dumpAll(txt, mem);
txt.close();
// mem -> ThriftEventSink
ThriftEventSink snk = new ThriftEventSink("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.getReport();
assertEquals(4475 * threads, sendByteSum.get());
assertEquals(4475 * threads, rpt
.getLongMetric(ThriftEventSource.A_BYTES_IN).longValue());
assertEquals(25 * threads, rpt.getLongMetric(ThriftEventSource.A_DEQUEUED)