* @throws RemoteException if watch data source causes problems
*/
@Test
public void testAddValue1() throws RemoteException {
String id = "watch";
GaugeWatch watch = new GaugeWatch(id);
DataSourceMonitor mon = new DataSourceMonitor(watch);
final int checkpoints[] = new int[] {0, 1, 50, 1000, 1001, 2000, 10000};
final int collectionSize = 1000;
List<Double> added = new ArrayList<Double>();
// Go through the checkpoints
for (int checkpoint : checkpoints) {
if(watch.getWatchDataSource().getMaxSize()<checkpoint) {
watch.getWatchDataSource().setMaxSize(1000);
}
// Generate samples to reach the checkpoint
while (added.size() < checkpoint) {
double d = Math.random();
added.add(d);
watch.addValue(d);
}
//mon.waitFor(added.size());
mon.waitFor(Math.min(collectionSize, checkpoint));
// Verify that the data has been added correctly
Calculable[] calcs = watch.getWatchDataSource().getCalculable();
int offset = Math.max(added.size() - collectionSize, 0);
List<Double> expected = added.subList(offset, added.size());
List<Double> actual = new ArrayList<Double>();
for (Calculable calc : calcs) {
Assert.assertEquals(id, calc.getId());
actual.add(calc.getValue());
}
Assert.assertEquals(expected, actual);
}
Utils.close(watch.getWatchDataSource());
}