lnrs.add(lnr);
logs.add(log);
watch.addThresholdListener(lnr);
count++;
}
watch.addWatchRecord(new Calculable(id, 0.5));
checkLogs(logs, "");
watch.addWatchRecord(new Calculable(id, -0.1));
checkLogs(logs, "breach(" + id + ",-0.1,0.0,1.0)");
watch.addWatchRecord(new Calculable(id, 1.1));
checkLogs(logs, "clear(" + id + ",1.1,0.0,1.0)"
+ "breach(" + id + ",1.1,0.0,1.0)");
watch.addWatchRecord(new Calculable(id, 0.5));
checkLogs(logs, "clear(" + id + ",0.5,0.0,1.0)");
}
// Test adding the same listeners (should not change anything)
for (LoggingThresholdListener lnr : lnrs) {
watch.addThresholdListener(lnr);
}
watch.addWatchRecord(new Calculable(id, -0.1));
checkLogs(logs, "breach(" + id + ",-0.1,0.0,1.0)");
watch.addWatchRecord(new Calculable(id, 1.1));
checkLogs(logs, "clear(" + id + ",1.1,0.0,1.0)"
+ "breach(" + id + ",1.1,0.0,1.0)");
watch.addWatchRecord(new Calculable(id, 0.5));
checkLogs(logs, "clear(" + id + ",0.5,0.0,1.0)");
// Test removing listeners
count = 0;
for (int checkpoint : checkpoints) {
while (count < checkpoint) {
LoggingThresholdListener lnr = lnrs.get(count);
watch.removeThresholdListener(lnr);
count++;
}
List<StringBuffer> removedLogs = logs.subList(0, count);
List<StringBuffer> remainingLogs = logs.subList(count, logs.size());
watch.addWatchRecord(new Calculable(id, 0.5));
checkLogs(removedLogs, "");
checkLogs(remainingLogs, "");
watch.addWatchRecord(new Calculable(id, -0.1));
checkLogs(removedLogs, "");
checkLogs(remainingLogs, "breach(" + id + ",-0.1,0.0,1.0)");
watch.addWatchRecord(new Calculable(id, 1.1));
checkLogs(removedLogs, "");
checkLogs(remainingLogs, "clear(" + id + ",1.1,0.0,1.0)"
+ "breach(" + id + ",1.1,0.0,1.0)");
watch.addWatchRecord(new Calculable(id, 0.5));
checkLogs(removedLogs, "");
checkLogs(remainingLogs, "clear(" + id + ",0.5,0.0,1.0)");
}
// Test removing the same listeners (should not change anything)
for (LoggingThresholdListener lnr : lnrs) {
watch.removeThresholdListener(lnr);
}
watch.addWatchRecord(new Calculable(id, -0.1));
checkLogs(logs, "");
watch.addWatchRecord(new Calculable(id, 1.1));
checkLogs(logs, "");
watch.addWatchRecord(new Calculable(id, 0.5));
checkLogs(logs, "");
// Test adding 1, 10, and 100 listeners again
count = 0;
for (int checkpoint : checkpoints) {
while (count < checkpoint) {
LoggingThresholdListener lnr = lnrs.get(count);
watch.addThresholdListener(lnr);
count++;
}
List<StringBuffer> addedLogs = logs.subList(0, count);
List<StringBuffer> remainingLogs = logs.subList(count, logs.size());
watch.addWatchRecord(new Calculable(id, 0.5));
checkLogs(addedLogs, "");
checkLogs(remainingLogs, "");
watch.addWatchRecord(new Calculable(id, -0.1));
checkLogs(addedLogs, "breach(" + id + ",-0.1,0.0,1.0)");
checkLogs(remainingLogs, "");
watch.addWatchRecord(new Calculable(id, 1.1));
checkLogs(addedLogs, "clear(" + id + ",1.1,0.0,1.0)"
+ "breach(" + id + ",1.1,0.0,1.0)");
checkLogs(remainingLogs, "");
watch.addWatchRecord(new Calculable(id, 0.5));
checkLogs(addedLogs, "clear(" + id + ",0.5,0.0,1.0)");
checkLogs(remainingLogs, "");
}
// Test adding illegal listener