Search in sources :

Example 11 with MockNode

use of org.opennms.netmgt.mock.MockNode in project opennms by OpenNMS.

the class PollerIT method testCritSvcStatusPropagation.

@Test
public void testCritSvcStatusPropagation() {
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    MockNode node = m_network.getNode(1);
    anticipateDown(node);
    startDaemons();
    bringDownCritSvcs(node);
    verifyAnticipated(8000);
}
Also used : MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Example 12 with MockNode

use of org.opennms.netmgt.mock.MockNode in project opennms by OpenNMS.

the class PollerIT method closesOpenOutagesWithNoSvcLostEventIdOnRestart.

/**
     * Test for NMS-7585
     */
@Test
public void closesOpenOutagesWithNoSvcLostEventIdOnRestart() {
    MockNode node = m_network.getNode(2);
    MockService criticalService = m_network.getService(2, "192.168.1.3", "ICMP");
    // Bring the critical service down
    anticipateDown(node);
    criticalService.bringDown();
    // Start the poller
    startDaemons();
    // Verify
    verifyAnticipated(10000);
    // Stop the poller
    stopDaemons();
    // Remove the reference to the lost service event from all of the outages,
    // and let's pretend that they weren't even there in the first place
    Set<Integer> outageIds = new HashSet<Integer>();
    for (OnmsOutage outage : m_outageDao.findAll()) {
        outage.setServiceLostEvent(null);
        m_outageDao.update(outage);
        outageIds.add(outage.getId());
    }
    m_outageDao.flush();
    // We should get another node down
    m_eventMgr.getEventAnticipator().anticipateEvent(node.createDownEvent());
    // (Re)start the poller
    startDaemons();
    // Verify
    m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
    // Wait for the outages to be populated (this happen after
    // the down event is sent)
    sleep(1000);
    for (OnmsOutage outage : m_outageDao.findAll()) {
        if (outageIds.contains(outage.getId())) {
            // Outages in our list should be closed with
            // no svcRegainedEvent
            assertNotNull(outage.getIfRegainedService());
            assertNull(outage.getServiceRegainedEvent());
        } else {
            // Other outages should be open
            assertNull(outage.getIfRegainedService());
        }
    }
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) MockService(org.opennms.netmgt.mock.MockService) MockNode(org.opennms.netmgt.mock.MockNode) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with MockNode

use of org.opennms.netmgt.mock.MockNode in project opennms by OpenNMS.

the class PollerIT method testNoInvalidPollsAfterNodeCategoryMembershipChanged.

/**
     * Test for NMS-9112
     */
@Test
public void testNoInvalidPollsAfterNodeCategoryMembershipChanged() throws InterruptedException {
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    MockNode node = m_network.getNode(1);
    // Start the poller
    startDaemons();
    // Send a uei.opennms.org/nodes/nodeCategoryMembershipChanged
    // This will remove, add or reschedule services for the node as necessary
    EventBuilder eventBuilder = MockEventUtil.createEventBuilder("Test", EventConstants.NODE_CATEGORY_MEMBERSHIP_CHANGED_EVENT_UEI);
    eventBuilder.setNodeid(node.getNodeId());
    Event nodeCatMemChangedEvent = eventBuilder.getEvent();
    m_eventMgr.sendEventToListeners(nodeCatMemChangedEvent);
    // Delete the node and send a nodeDeleted event
    m_network.removeElement(node);
    Event deleteEvent = node.createDeleteEvent();
    m_eventMgr.sendEventToListeners(deleteEvent);
    // Wait a little long than a polling cycle
    sleep(3000);
    m_network.resetInvalidPollCount();
    // Sleep some more and verify that no invalid polls have occurred
    sleep(3000);
    assertEquals("Received a poll for an element that doesn't exist", 0, m_network.getInvalidPollCount());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event) MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Example 14 with MockNode

use of org.opennms.netmgt.mock.MockNode in project opennms by OpenNMS.

the class PollerQueryManagerDaoIT method testCritSvcStatusPropagation.

@Test
public void testCritSvcStatusPropagation() {
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    MockNode node = m_network.getNode(1);
    anticipateDown(node);
    startDaemons();
    bringDownCritSvcs(node);
    verifyAnticipated(8000);
}
Also used : MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Example 15 with MockNode

use of org.opennms.netmgt.mock.MockNode in project opennms by OpenNMS.

the class PollerQueryManagerDaoIT method testNodeGainedServiceWhileNodeDownAndServiceUp.

@Test
public void testNodeGainedServiceWhileNodeDownAndServiceUp() {
    startDaemons();
    MockNode node = m_network.getNode(4);
    MockService svc = m_network.getService(4, "192.168.1.6", "SNMP");
    anticipateDown(node);
    node.bringDown();
    verifyAnticipated(5000);
    resetAnticipated();
    anticipateUp(node);
    anticipateDown(svc, true);
    MockService newSvc = m_network.addService(4, "192.168.1.6", "SMTP");
    m_db.writeService(newSvc);
    Event e = MockEventUtil.createNodeGainedServiceEvent("Test", newSvc);
    m_eventMgr.sendEventToListeners(e);
    sleep(5000);
    System.err.println(m_db.getOutages());
    verifyAnticipated(8000);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event) MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Aggregations

MockNode (org.opennms.netmgt.mock.MockNode)52 Test (org.junit.Test)42 Event (org.opennms.netmgt.xml.event.Event)21 MockService (org.opennms.netmgt.mock.MockService)16 MockInterface (org.opennms.netmgt.mock.MockInterface)7 Date (java.util.Date)5 ResultSet (java.sql.ResultSet)4 PollAnticipator (org.opennms.netmgt.mock.PollAnticipator)4 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)4 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 MockNetwork (org.opennms.netmgt.mock.MockNetwork)3 MockVisitor (org.opennms.netmgt.mock.MockVisitor)3 MockVisitorAdapter (org.opennms.netmgt.mock.MockVisitorAdapter)3 Ignore (org.junit.Ignore)2 Querier (org.opennms.core.utils.Querier)2 RowCallbackHandler (org.springframework.jdbc.core.RowCallbackHandler)2 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1