else
wdr = new LoggingWatchDataReplicator();
DynamicConfiguration config = new DynamicConfiguration();
config.setEntry("org.rioproject.watch", "collectionSize", collectionSize);
WatchDataSourceImpl impl = new WatchDataSourceImpl();
impl.setID("watch");
impl.setConfiguration(config);
if(wdrClass.equals(RemoteWDR.class.getName()))
impl.addWatchDataReplicator(((RemoteWDR)wdr).getWatchDataReplicator());
else
impl.addWatchDataReplicator(wdr);
impl.initialize();
/*System.out.println(
"WDS max size=" + impl.getMaxSize() + ", " +
"configured to be=" + collectionSize + ", " +
"count is=" + count);*/
List<Calculable> expected = new ArrayList<Calculable>();
for (int k = 0; k < count; k++) {
Calculable c = new Calculable();
impl.addCalculable(c);
expected.add(c);
}
if (nullCalculable) {
try {
impl.addCalculable(null);
Assert.fail("IllegalArgumentException expected but not thrown");
} catch (IllegalArgumentException e) {
}
} else {
Calculable c = new Calculable();
impl.addCalculable(c);
expected.add(c);
}
long waited = 0;
if(wdrClass.equals(RemoteWDR.class.getName())) {
int maxIterations = 10000;
int iteration = 0;
long current = System.currentTimeMillis();
while(expected.size()!=wdr.calculables().size() && iteration<maxIterations) {
Utils.sleep(1);
iteration++;
}
waited = System.currentTimeMillis()-current;
}
// Replicator should have all the data
System.out.println(
"WDS size=" + impl.getCurrentSize() + ", " +
"Replicator ("+wdrClass.substring(wdrClass.indexOf("$")+1,wdrClass.length())+") " +
"size=" + wdr.calculables().size() +", expected size=" + expected.size()+
(waited==0?"":", waited="+waited+" ms"));
Assert.assertEquals(expected.size(), wdr.calculables().size());
Utils.assertEqualContents(expected, wdr.calculables());
// Data source should contain the tail
int off = Math.max(expected.size() - collectionSize, 0);
expected = expected.subList(off, expected.size());
Calculable[] res = impl.getCalculable();
Utils.assertSameContents(expected, Arrays.asList(res));
impl.close();
if(wdrClass.equals(RemoteWDR.class.getName()))
wdr.close();
}
}