*/
@Test
public void testReservoirMergeAndLandmarkSynch() throws InterruptedException
{
// two low-level reservoirs and one aggregator
MergeableExponentiallyDecayingReservoir res1;
MergeableExponentiallyDecayingReservoir res2;
MergeableExponentiallyDecayingReservoir aggr;
aggr = new MergeableExponentiallyDecayingReservoir(10, 0.015);
Thread.sleep(1000L);
res1 = new MergeableExponentiallyDecayingReservoir(10, 0.015);
Thread.sleep(1000L);
res2 = new MergeableExponentiallyDecayingReservoir(10, 0.015);
//long origLandmarkAggr = aggr.getLandmark();
long origLandmarkRes1 = res1.getLandmark();
long origLandmarkRes2 = res2.getLandmark();
assertTrue("expected aggregator to have older landmark value than res1", aggr.getLandmark() < origLandmarkRes1);
assertTrue("expected res1 to have older landmark value than res2", origLandmarkRes1 < origLandmarkRes2);
// generate some data for both low-level reservoirs, then make sure their landmarks don't change
for (int i = 0; i < 10; ++i)
{
long nowSecs = System.currentTimeMillis() / NUM_MSECS_IN_SEC;
long timestamp1 = nowSecs - i - 3L;
long timestamp2 = nowSecs - i - 5L;
res1.update((double)i, timestamp1);
res2.update((double)(i+100), timestamp2);
}
assertEquals("expected res1 landmark value to be unchanged", origLandmarkRes1, res1.getLandmark());
assertEquals("expected res2 landmark value to be unchanged", origLandmarkRes2, res2.getLandmark());
aggr.merge(res1);
assertEquals("expected res1 landmark value to be unchanged", origLandmarkRes1, res1.getLandmark());
assertEquals("expected aggregator landmark value to match res1", origLandmarkRes1, aggr.getLandmark());
aggr.merge(res2);
assertEquals("expected res2 landmark value to be unchanged", origLandmarkRes2, res2.getLandmark());
assertEquals("expected aggregator landmark value to match res2", origLandmarkRes2, aggr.getLandmark());
// generate some more data for both low-level reservoirs; their landmarks still should not have changed
for (int i = 0; i < 10; ++i)
{
long nowSecs = System.currentTimeMillis() / NUM_MSECS_IN_SEC;
long timestamp1 = nowSecs - i - 1L;
long timestamp2 = nowSecs - i - 2L;
res1.update((double)(i+200), timestamp1);
res2.update((double)(i+300), timestamp2);
}
assertEquals("expected res1 landmark value to be unchanged", origLandmarkRes1, res1.getLandmark());
assertEquals("expected res2 landmark value to be unchanged", origLandmarkRes2, res2.getLandmark());
aggr.merge(res1);
assertEquals("expected aggregator landmark value to be unchanged", origLandmarkRes2, aggr.getLandmark());
assertEquals("expected res1 landmark value to match res2", origLandmarkRes2, res1.getLandmark());
}