final ThriftEventSource tes = new ThriftEventSource(
conf.getCollectorPort() + 1); // this is a slight
// tweak to avoid port conflicts
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) {
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
t.start(); // drain the sink.
// mem -> ThriftEventSink
ThriftEventSink snk = new ThriftEventSink("0.0.0.0", conf
.getCollectorPort() + 1);
snk.open();
EventUtil.dumpAll(mem, snk);
mem.close();
snk.close();
// a little delay to drain events at ThriftEventSource queue
try {
Thread.sleep(1000);
t.interrupt();
} catch (InterruptedException e) {
}
tes.close();
assertEquals(25, cnt.getCount());
ReportEvent rpt = tes.getMetrics();
assertEquals(4475, rpt.getLongMetric(ThriftEventSource.A_BYTES_IN)
.longValue());
assertEquals(25, rpt.getLongMetric(ThriftEventSource.A_DEQUEUED)
.longValue());