use of cern.laser.client.data.Alarm in project ACS by ACS-Community.
the class AlarmContainerTest method testRemoveOldest.
/**
* Test <code>removeOldest()</code>
*
* @throws Exception
*/
public void testRemoveOldest() throws Exception {
// Add some alarms
final Vector<Alarm> alarms = new Vector<Alarm>();
int notReduced = populateContainer(CONTAINER_SIZE / 2, "TEST", alarms, null);
class EDTReader implements Runnable {
// The value to check after reading from EDT
private final int value;
EDTReader(int val) {
value = val;
}
public void run() {
assertEquals("Wrong not reduced size", CONTAINER_SIZE / 2, container.size(false));
assertEquals("Wrong reduced size", value, container.size(true));
}
}
EDTExecutor.instance().executeSync(new EDTReader(notReduced));
final AlarmTableEntry removedEntry = container.removeOldest();
assertNotNull(removedEntry);
// Check the sizes
class EDTReader2 implements Runnable {
// The value to check after reading from EDT
private final int notReduced;
EDTReader2(int notReduced) {
this.notReduced = notReduced;
}
public void run() {
assertEquals(alarms.size() - 1, container.size(false));
if (removedEntry.isReduced()) {
assertEquals(notReduced, container.size(true));
} else {
assertEquals(notReduced - 1, container.size(true));
}
}
}
EDTExecutor.instance().executeSync(new EDTReader2(notReduced));
// Check if removed alarms was the oldest alarm
assertEquals(alarms.get(0).getAlarmId(), removedEntry.getAlarmId());
}
Aggregations