new Thread("Concurrent-" + i) {
@Override
public void run() {
try {
File f1 = FileUtil.mktempdir();
AccumulatorSink cnt1 = new AccumulatorSink("count." + idx);
DiskFailoverManager dfoMan = new NaiveFileFailoverManager(f1);
dfos[idx] = dfoMan; // save for checking.
// short trigger causes lots of rolls
EventSink snk = new DiskFailoverDeco(cnt1, LogicalNodeContext
.testingContext(), dfoMan, new TimeTrigger(100), 50);
ReportManager.get().add(cnt1);
// make each parallel instance send a slightly different number of
// messages.
EventSource src = new NoNlASCIISynthSource(events + idx, 100);
src.open();
snk.open();
started.countDown();
EventUtil.dumpAll(src, snk);
src.close();
snk.close(); // this triggers a flush of current file!?
FileUtil.rmr(f1);
} catch (Exception e) {
LOG.error(e, e);
} finally {
done.countDown();
}
}
}.start();
}
started.await();
boolean ok = done.await(timeout, TimeUnit.MILLISECONDS);
assertTrue("Test timed out", ok);
for (int i = 0; i < threads; i++) {
AccumulatorSink cnt = (AccumulatorSink) ReportManager.get()
.getReportable("count." + i);
// check for the slightly different counts based on thread.
int exp = events + i;
LOG
.info("count." + i + " expected " + exp + " and got "
+ cnt.getCount());
assertEquals(exp, (int) cnt.getCount());
// check dfo reports to see if they are sane.
ReportEvent rpt = dfos[i].getMetrics();
LOG.info(rpt);
long failovered = rpt.getLongMetric(DiskFailoverManager.A_MSG_WRITING);