use of alma.alarmsystem.clients.alarm.AlarmFilter in project ACS by ACS-Community.
the class AlarmFilterTest method testFaultMemberFiltering.
public void testFaultMemberFiltering() throws Exception {
AlarmFilter filter = new AlarmFilter(null, "[a-z]+", null, null);
assertNotNull("Invalid null filter", filter);
// These all pass
assertTrue(filter.matches("FF", "member", 1));
assertTrue(filter.matches("Alarm06", "m", 156));
assertTrue(filter.matches("1FF6 h", "test", 3));
// These must be rejected
assertFalse(filter.matches("Test", "Whatever", 1));
assertFalse(filter.matches("test2", "alarm one", 123));
assertFalse(filter.matches("No alarm 1", "A99G", 0));
}
use of alma.alarmsystem.clients.alarm.AlarmFilter in project ACS by ACS-Community.
the class AlarmListenerContainerTest method testDispatchAlarms.
/**
* Test the dispatching of alarms
*
* {@link AlarmListenerForTesting} prints received alarms on the stdout.
*
* This test checks the number of alarms received by 2 listeners:
* <OL>
* <LI>The un-filtered listener must receive all the notifications
* <LI>The filtered listener must be notified only for alarms that pass the filter
* </OL>
*
* This test checks if the filter is applied.
* The correctness of the filtering is tested by {@link AlarmFilterTest}
*/
public void testDispatchAlarms() throws Exception {
// Instantiates 2 listeners one un-filtered and one filtered
assertEquals(0, container.getAlarmListenersSize());
AlarmListenerForTesting alarmL1 = new AlarmListenerForTesting("Unfiltered-listener");
// Unfiltered
AlarmListener listener1 = container.addAlarmListener(alarmL1);
assertNotNull(listener1);
AlarmFilter filter = new AlarmFilter(null, null, 10, 25);
AlarmListenerForTesting alarmL2 = new AlarmListenerForTesting("Filtered-listener");
// Filtered
AlarmListener listener2 = container.addAlarmListener(alarmL2, filter);
assertNotNull(listener2);
assertEquals(2, container.getAlarmListenersSize());
assertEquals(0, container.getStatListenersSize());
int numOfAlarmsToDispatch = 50;
for (int t = 1; t < numOfAlarmsToDispatch + 1; t++) {
AlarmForTesting alarm = new AlarmForTesting("faultFamily", "faultMember", t, 2, true, false, true);
container.dispatchAlarm(alarm);
assertEquals(t, alarmL1.numAlarms);
}
// Filtered listeners is supposed to receive less alarms
// i.e. all the alarms whose FC is in [10,15]
assertEquals(16, alarmL2.numAlarms);
}
use of alma.alarmsystem.clients.alarm.AlarmFilter in project ACS by ACS-Community.
the class AlarmListenerContainerTest method testAddRemoveAlarmListeners.
/**
* Test add.remove alarm listeners
*
* @throws Exception
*/
public void testAddRemoveAlarmListeners() throws Exception {
assertEquals(0, container.getStatListenersSize());
assertEquals(0, container.getAlarmListenersSize());
AlarmListenerForTesting alarmL1 = new AlarmListenerForTesting("AlarmListenerName");
AlarmListener listener1 = container.addAlarmListener(alarmL1);
assertNotNull(listener1);
assertEquals(1, container.getAlarmListenersSize());
assertEquals(0, container.getStatListenersSize());
AlarmListenerForTesting alarmL2 = new AlarmListenerForTesting("AlarmListenerName");
AlarmFilter filter = new AlarmFilter("TheFF", ".*FM.*", -1, 9999);
AlarmListener listener2 = container.addAlarmListener(alarmL2, filter);
assertNotNull(listener2);
assertEquals(2, container.getAlarmListenersSize());
assertEquals(0, container.getStatListenersSize());
AlarmFilter filter2 = new AlarmFilter("TheFF2", "FM", -1, 9999);
AlarmListenerForTesting alarmL3 = new AlarmListenerForTesting("AlarmListenerName");
AlarmListener listener3 = container.new AlarmListener(alarmL3, filter2);
assertTrue(container.addAlarmListener(listener3));
assertEquals(3, container.getAlarmListenersSize());
assertEquals(0, container.getStatListenersSize());
assertTrue(container.removeAlarmListener(listener2));
assertEquals(2, container.getAlarmListenersSize());
assertEquals(0, container.getStatListenersSize());
assertTrue(container.removeAlarmListener(listener1));
assertEquals(1, container.getAlarmListenersSize());
assertEquals(0, container.getStatListenersSize());
AlarmListenerForTesting alarmL4 = new AlarmListenerForTesting("AlarmListenerName");
AlarmListener notExistentListener = container.new AlarmListener(alarmL4, null);
assertFalse(container.removeAlarmListener(notExistentListener));
assertEquals(1, container.getAlarmListenersSize());
assertEquals(0, container.getStatListenersSize());
assertTrue(container.removeAlarmListener(listener3));
assertEquals(0, container.getAlarmListenersSize());
assertEquals(0, container.getStatListenersSize());
}
Aggregations