// this is a slight tweak to avoid port conflicts
final int port = conf.getCollectorPort() + 1;
final ThriftEventSource tes = new ThriftEventSource(port);
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 {
// 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", port);
snk.open();
sendStarted.countDown();
sendStarted.await();
EventUtil.dumpAll(mem, snk);
mem.close();
snk.close();
sendByteSum.addAndGet(snk.getSentBytes());
LOG.info("sink " + id + " sent " + snk.getSentBytes() + " 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(4475 * threads, sendByteSum.get());
assertEquals(4475 * threads, rpt
.getLongMetric(ThriftEventSource.A_BYTES_IN).longValue());
assertEquals(25 * threads, rpt.getLongMetric(ThriftEventSource.A_DEQUEUED)