{
eventStatsCollectors.addStatsCollector(sw.getStatsName(), sw.getEventsStatsCollector());
}
//aggregator thread; 250 ms poll time
GlobalStatsCalc agg = new GlobalStatsCalc(10);
agg.registerStatsCollector(eventStatsCollectors);
Thread aggThread = new Thread(agg);
aggThread.start();
//start writers
for (StatsWriter sw : nStatsWriters)
{
sw.start();
}
//Let the writers start
Thread.sleep(1000);
long startTimeMs = System.currentTimeMillis();
long durationInMs = 5*1000; //5s
DbusEventsTotalStats globalStats = aggregateEventStatsCollectors.getTotalStats();
long prevValue = 0, prevSize =0;
while (System.currentTimeMillis() < (startTimeMs+durationInMs))
{
//constraint checks;
//check that readers don't have partial updates or get initialized
long value = globalStats.getNumDataEvents();
long size = globalStats.getSizeDataEvents();
Assert.assertTrue(value > 0);
if (prevValue > 0 && (value != prevValue))
{
Assert.assertTrue(size != prevSize);
prevValue = value;
prevSize = size;
}
Assert.assertTrue(globalStats.getMaxSeenWinScn() > 0);
Thread.sleep(RngUtils.randomPositiveInt()%10+1);
}
//shut down
for (StatsWriter sw : nStatsWriters)
{
sw.shutdown();
sw.interrupt();
}
//Give a chance to catch up
Thread.sleep(1000);
agg.halt();
aggThread.interrupt();
//final tally aggregatedEventTotalStats = sum of all individual statsWriter objects in a thread free way
AggregatedDbusEventsTotalStats myTotalStats = new AggregatedDbusEventsTotalStats(StatsWriter.OWNERID, "mytotal", true, false, null);