AlarmServiceImpl implements AlarmService { @Override public void raiseAlarm(AlarmInfo alarm) { AlarmChange alarmChange = AlarmChange.createFromAlarmInfo(AlarmChangeType.RAISE_OR_UPDATE, alarm); m_alarmQueue.addAlarmChanges(Collections.singletonList(alarmChange)); } AlarmServiceImpl(PersistenceManagerUtil persistenceManagerUtil, AlarmQueue alarmQueue); void init(); void close(); @Override void raiseAlarm(AlarmInfo alarm); @Override void raiseAlarms(List<AlarmInfo> alarmInfoList); @Override void clearAlarm(AlarmInfo alarm); @Override void clearAlarms(List<AlarmInfo> alarmInfoList); @Override @Transactional(value = TxType.REQUIRED, rollbackOn = {RuntimeException.class}) List<Alarm> getAlarms(PagingInput pagingInput); @Override @Transactional(value = TxType.REQUIRED, rollbackOn = {RuntimeException.class}) List<Alarm> getAlarms(PagingInput pagingInput, String deviceId); @Override void clearAlarmsOnNodeAndSubtree(ModelNodeId identifier, String mountKey); @Override void clearAlarmsOnDevice(String deviceId); @Override @Transactional(value = TxType.REQUIRED, rollbackOn = {RuntimeException.class}) List<Alarm> getAlarmsUnderResource(String resourceDbIdLike); @Override void updateAlarmsForResync(List<AlarmInfo> newRaiseAlarms, List<AlarmInfo> updateAlarms, List<AlarmInfo> clearAlarms); @Override void updateAlarmNotificationQNameToAdapterTypeVersion(QName alarmNotificationQName, String typeVersion); @Override void removeAlarmNotificationQNameToAdapterTypeVersion(QName alarmNotificationQName, String typeVersion); @Override Set<String> retrieveAdapterTypeVersionsFromAlarmNotificationQName(QName alarmNotificationQName);  }
@Test public void testActiveAlarms() throws Exception { EntityDataStoreManager manager = m_persistenceManager.getEntityDataStoreManager(); AlarmInfo alarmInfo = buildAlarmInfo(); m_alarmService.raiseAlarm(alarmInfo); manager.beginTransaction(); m_alarmQueue.clearQueue(); manager.commitTransaction(); assertEquals(1, m_internalAlarmService.getActiveAlarms()); }
@Test public void testRaiseUnknownAlarm() { AlarmInfo alarmInfo = buildAlarmInfo(); m_alarmService.raiseAlarm(alarmInfo); m_persistenceManager.getEntityDataStoreManager().beginTransaction(); m_alarmQueue.clearQueue(); m_persistenceManager.getEntityDataStoreManager().commitTransaction(); }
@Test public void testAlarmQueueThreadError() { EntityDataStoreManager manager = m_persistenceManager.getEntityDataStoreManager(); AlarmQueue alarmQueue = mock(AlarmQueue.class); AlarmQueueThread alarmQueueThread = new AlarmQueueThread(alarmQueue); AlarmInfo alarmInfo = buildAlarmInfo(); m_alarmService.raiseAlarm(alarmInfo); doThrow(new RuntimeException("error")).when(alarmQueue).clearQueue(); manager.beginTransaction(); alarmQueueThread.doOneRun(); manager.commitTransaction(); manager.beginTransaction(); List<Alarm> alarms = manager.findAll(Alarm.class); manager.commitTransaction(); assertEquals(0, alarms.size()); }
@Test public void testGetActiveAlarms() throws Exception { EntityDataStoreManager manager = m_persistenceManager.getEntityDataStoreManager(); AlarmInfo alarmInfo = buildAlarmInfoWithResourceTypeString(); m_alarmService.raiseAlarm(alarmInfo); manager.beginTransaction(); m_alarmQueue.clearQueue(); manager.commitTransaction(); assertEquals(1, m_internalAlarmService.getActiveAlarms()); alarmInfo = buildAlarmInfo(); m_alarmService.raiseAlarm(alarmInfo); manager.beginTransaction(); m_alarmQueue.clearQueue(); manager.commitTransaction(); assertEquals(2, m_internalAlarmService.getActiveAlarms()); }