use of org.opennms.netmgt.mock.MockInterface in project opennms by OpenNMS.
the class PollerQueryManagerDaoIT method testDontPollDuringScheduledOutages.
// what about scheduled outages?
@Test
public void testDontPollDuringScheduledOutages() {
long start = System.currentTimeMillis();
MockInterface iface = m_network.getInterface(1, "192.168.1.2");
m_pollerConfig.addScheduledOutage(m_pollerConfig.getPackage("TestPackage"), "TestOutage", start, start + 5000, iface.getIpAddr());
MockUtil.println("Begin Outage");
startDaemons();
long now = System.currentTimeMillis();
sleep(3000 - (now - start));
MockUtil.println("End Outage");
assertEquals(0, iface.getPollCount());
sleep(5000);
assertTrue(0 < iface.getPollCount());
}
use of org.opennms.netmgt.mock.MockInterface in project opennms by OpenNMS.
the class PollerQueryManagerDaoIT method testReparentCausesStatusChange.
// test open outages for unmanaged services
@Test
public void testReparentCausesStatusChange() {
m_pollerConfig.setNodeOutageProcessingEnabled(true);
MockNode node1 = m_network.getNode(1);
MockNode node2 = m_network.getNode(2);
MockInterface dotOne = m_network.getInterface(1, "192.168.1.1");
MockInterface dotTwo = m_network.getInterface(1, "192.168.1.2");
MockInterface dotThree = m_network.getInterface(2, "192.168.1.3");
//
// Plan to bring down both nodes except the reparented interface
// the node owning the interface should be up while the other is down
// after reparenting we should got the old owner go down while the other
// comes up.
//
anticipateDown(node2);
anticipateDown(dotOne);
// bring down both nodes but bring iface back up
node1.bringDown();
node2.bringDown();
dotTwo.bringUp();
Event reparentEvent = MockEventUtil.createReparentEvent("Test", "192.168.1.2", 1, 2);
startDaemons();
verifyAnticipated(2000);
m_db.reparentInterface(dotTwo.getIpAddr(), dotTwo.getNodeId(), node2.getNodeId());
dotTwo.moveTo(node2);
resetAnticipated();
anticipateDown(node1, true);
anticipateUp(node2, true);
anticipateDown(dotThree, true);
m_eventMgr.sendEventToListeners(reparentEvent);
verifyAnticipated(20000);
}
use of org.opennms.netmgt.mock.MockInterface in project opennms by OpenNMS.
the class NotifdIT method testGetUsersNotified.
@Test
public void testGetUsersNotified() throws Exception {
MockInterface iface = m_network.getInterface(1, "192.168.1.1");
Date downDate = new Date();
anticipateNotificationsForGroup("interface 192.168.1.1 down.", "All services are down on interface 192.168.1.1, dot1 interface alias.", "InitialGroup", downDate, 0);
//bring node down now
Event event = iface.createDownEvent(downDate);
m_eventMgr.sendEventToListeners(event);
sleep(1000);
Collection<List<String>> expectedResults = new LinkedList<List<String>>();
Collection<String> users = getUsersInGroup("InitialGroup");
for (String userID : users) {
List<String> cmdList = new LinkedList<String>();
cmdList.add(userID);
cmdList.add("mockNotifier");
expectedResults.add(cmdList);
}
Collection<Integer> notifIds = m_db.findNoticesForEvent(event);
assertEquals("notification ID size", 1, notifIds.size());
Integer notifId = notifIds.iterator().next();
assertNotNull("first notifId should not be null", notifId);
final Collection<List<String>> actualResults = new LinkedList<List<String>>();
RowProcessor rp = new RowProcessor() {
@Override
public void processRow(ResultSet rs) throws SQLException {
List<String> cmdList = new LinkedList<String>();
cmdList.add(rs.getString("userID"));
cmdList.add(rs.getString("media"));
actualResults.add(cmdList);
}
};
m_notificationManager.forEachUserNotification(notifId.intValue(), rp);
/*
* This test does not work reliably because notifications within a
* group are not guaranteed to be in a certain order.
*/
//assertEquals("Notifications", expectedResults, actualResults);
// Use a set instead so we don't care about ordering.
Set<List<String>> expectedSet = new HashSet<List<String>>(expectedResults);
Set<List<String>> actualSet = new HashSet<List<String>>(actualResults);
assertEquals("Notifications as a set", expectedSet, actualSet);
}
use of org.opennms.netmgt.mock.MockInterface in project opennms by OpenNMS.
the class NotifdIT method testAutoAcknowledge2.
@Test
public void testAutoAcknowledge2() throws Exception {
MockInterface iface = m_network.getInterface(1, "192.168.1.1");
Date downDate = new Date();
anticipateNotificationsForGroup("interface 192.168.1.1 down.", "All services are down on interface 192.168.1.1, dot1 interface alias.", "InitialGroup", downDate, 0);
//bring node down now
Event event = iface.createDownEvent(downDate);
m_eventMgr.sendEventToListeners(event);
sleep(1000);
Date date = new Date();
Event upEvent = iface.createUpEvent(date);
anticipateNotificationsForGroup("RESOLVED: interface 192.168.1.1 down.", "RESOLVED: All services are down on interface 192.168.1.1, dot1 interface alias.", "InitialGroup", date, 0);
long endTime = anticipateNotificationsForGroup("interface 192.168.1.1 up.", "The interface which was previously down is now up.", "UpGroup", date, 0);
m_eventMgr.sendEventToListeners(upEvent);
verifyAnticipated(endTime, 1000, 5000);
}
use of org.opennms.netmgt.mock.MockInterface in project opennms by OpenNMS.
the class NotifdIT method testEscalate.
@Test
public void testEscalate() throws Exception {
MockInterface iface = m_network.getInterface(1, "192.168.1.1");
Date now = new Date();
anticipateNotificationsForGroup("interface 192.168.1.1 down.", "All services are down on interface 192.168.1.1, dot1 interface alias.", "InitialGroup", now, 0);
long endTime = anticipateNotificationsForGroup("interface 192.168.1.1 down.", "All services are down on interface 192.168.1.1, dot1 interface alias.", "EscalationGroup", now.getTime() + 2500, 0);
m_eventMgr.sendEventToListeners(iface.createDownEvent(now));
verifyAnticipated(endTime, 3000);
}
Aggregations