Search in sources :

Example 11 with MockInterface

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());
}
Also used : MockInterface(org.opennms.netmgt.mock.MockInterface) Test(org.junit.Test)

Example 12 with MockInterface

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);
}
Also used : MockInterface(org.opennms.netmgt.mock.MockInterface) Event(org.opennms.netmgt.xml.event.Event) MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Example 13 with MockInterface

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);
}
Also used : Date(java.util.Date) LinkedList(java.util.LinkedList) MockInterface(org.opennms.netmgt.mock.MockInterface) ResultSet(java.sql.ResultSet) Event(org.opennms.netmgt.xml.event.Event) LinkedList(java.util.LinkedList) List(java.util.List) RowProcessor(org.opennms.core.utils.RowProcessor) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with MockInterface

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);
}
Also used : MockInterface(org.opennms.netmgt.mock.MockInterface) Event(org.opennms.netmgt.xml.event.Event) Date(java.util.Date) Test(org.junit.Test)

Example 15 with MockInterface

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);
}
Also used : MockInterface(org.opennms.netmgt.mock.MockInterface) Date(java.util.Date) Test(org.junit.Test)

Aggregations

MockInterface (org.opennms.netmgt.mock.MockInterface)28 Test (org.junit.Test)24 Event (org.opennms.netmgt.xml.event.Event)13 MockService (org.opennms.netmgt.mock.MockService)8 Date (java.util.Date)7 MockNode (org.opennms.netmgt.mock.MockNode)7 PollAnticipator (org.opennms.netmgt.mock.PollAnticipator)4 MockVisitor (org.opennms.netmgt.mock.MockVisitor)3 MockVisitorAdapter (org.opennms.netmgt.mock.MockVisitorAdapter)3 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Querier (org.opennms.core.utils.Querier)1 RowProcessor (org.opennms.core.utils.RowProcessor)1 Notification (org.opennms.netmgt.config.notifications.Notification)1 MockPathOutage (org.opennms.netmgt.mock.MockPathOutage)1 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)1