@Test @JUnitTemporaryDatabase(tempDbClass=MockDatabase.class) public void testPersistManyAlarmsAtOnce() throws InterruptedException { int numberOfAlarmsToReduce = 10; assertEquals(0, m_jdbcTemplate.queryForInt("select count(*) from alarms")); final String reductionKey = "countThese"; final MockNode node = m_mockNetwork.getNode(1); final long millis = System.currentTimeMillis()+2500; final CountDownLatch signal = new CountDownLatch(numberOfAlarmsToReduce); for (int i=1; i<= numberOfAlarmsToReduce; i++) { MockUtil.println("Creating Runnable: "+i+" of "+numberOfAlarmsToReduce+" events to reduce."); class EventRunner implements Runnable { public void run() { try { while (System.currentTimeMillis() < millis) { try { Thread.sleep(10); } catch (InterruptedException e) { MockUtil.println(e.getMessage()); } } sendNodeDownEvent(reductionKey, node); } catch (Throwable t) { t.printStackTrace(); } finally { signal.countDown(); } } } Runnable r = new EventRunner(); Thread p = new Thread(r); p.start(); } signal.await(); int rowCount = m_jdbcTemplate.queryForInt("select count(*) from alarms"); Integer counterColumn = m_jdbcTemplate.queryForInt("select counter from alarms where reductionKey = ?", new Object[] { reductionKey }); MockUtil.println("rowcCount is: "+rowCount+", expected 1."); MockUtil.println("counterColumn is: "+counterColumn+", expected "+numberOfAlarmsToReduce); assertEquals(1, rowCount); if (numberOfAlarmsToReduce != counterColumn) { final List<Integer> reducedEvents = new ArrayList<Integer>(); m_jdbcTemplate.query("select eventid from events where alarmID is not null", new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { reducedEvents.add(rs.getInt(1)); } }); Collections.sort(reducedEvents); final List<Integer> nonReducedEvents = new ArrayList<Integer>(); m_jdbcTemplate.query("select eventid from events where alarmID is null", new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { nonReducedEvents.add(rs.getInt(1)); } }); Collections.sort(nonReducedEvents); fail("number of alarms to reduce (" + numberOfAlarmsToReduce + ") were not reduced into a single alarm (instead the counter column reads " + counterColumn + "); " + "events that were reduced: " + StringUtils.collectionToCommaDelimitedString(reducedEvents) + "; events that were not reduced: " + StringUtils.collectionToCommaDelimitedString(nonReducedEvents)); } Integer alarmId = m_jdbcTemplate.queryForInt("select alarmId from alarms where reductionKey = ?", new Object[] { reductionKey }); rowCount = m_jdbcTemplate.queryForInt("select count(*) from events where alarmid = ?", new Object[] { alarmId }); MockUtil.println(String.valueOf(rowCount) + " of events with alarmid: "+alarmId); rowCount = m_jdbcTemplate.queryForInt("select count(*) from events where alarmid is null"); MockUtil.println(String.valueOf(rowCount) + " of events with null alarmid"); assertEquals(0, rowCount); }
public void start() throws Exception { }
Alarmd implements SpringServiceDaemon, DisposableBean { public void start() throws Exception { } }
Alarmd implements SpringServiceDaemon, DisposableBean { public void start() throws Exception { }  }
Alarmd implements SpringServiceDaemon, DisposableBean { public void start() throws Exception { }  @EventHandler(uei = EventHandler.ALL_UEIS) void onEvent(Event e); void setPersister(AlarmPersister persister); AlarmPersister getPersister(); EventForwarder getEventForwarder(); void setEventForwarder(EventForwarder eventForwarder); @Override void afterPropertiesSet(); void destroy(); String getName(); void start(); void onNorthbounderRegistered(final Northbounder northbounder, final Map<String,String> properties); void onNorthbounderUnregistered(final Northbounder northbounder, final Map<String,String> properties); List<Northbounder> getNorthboundInterfaces(); void setNorthboundInterfaces(List<Northbounder> northboundInterfaces); }
Alarmd implements SpringServiceDaemon, DisposableBean { public void start() throws Exception { }  @EventHandler(uei = EventHandler.ALL_UEIS) void onEvent(Event e); void setPersister(AlarmPersister persister); AlarmPersister getPersister(); EventForwarder getEventForwarder(); void setEventForwarder(EventForwarder eventForwarder); @Override void afterPropertiesSet(); void destroy(); String getName(); void start(); void onNorthbounderRegistered(final Northbounder northbounder, final Map<String,String> properties); void onNorthbounderUnregistered(final Northbounder northbounder, final Map<String,String> properties); List<Northbounder> getNorthboundInterfaces(); void setNorthboundInterfaces(List<Northbounder> northboundInterfaces); static final String NAME; }