Search in sources :

Example 6 with MockNode

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

the class PollerQueryManagerDaoIT method testNodeDeleted.

// nodeDeleted: EventConstants.NODE_DELETED_EVENT_UEI
@Test
public void testNodeDeleted() {
    MockNode node = m_network.getNode(1);
    testElementDeleted(node);
}
Also used : MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Example 7 with MockNode

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

the class PollerIT method restoresServiceStateOnRestart.

@Test
public void restoresServiceStateOnRestart() {
    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();
    // Bring the critical service up and expect a nodeUp
    // The service should restore the proper state and know that the outage
    // was triggered by a node down
    anticipateUp(node);
    criticalService.bringUp();
    // (Re)start the poller
    startDaemons();
    // Verify
    verifyAnticipated(10000);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Example 8 with MockNode

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

the class PollerIT 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 9 with MockNode

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

the class PollerIT method testNodeGainedServiceWhileNodeDownAndServiceDown.

@Test
public void testNodeGainedServiceWhileNodeDownAndServiceDown() {
    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();
    MockService newSvc = m_network.addService(4, "192.168.1.6", "SMTP");
    m_db.writeService(newSvc);
    newSvc.bringDown();
    Event e = MockEventUtil.createNodeGainedServiceEvent("Test", newSvc);
    m_eventMgr.sendEventToListeners(e);
    sleep(5000);
    System.err.println(m_db.getOutages());
    verifyAnticipated(8000);
    anticipateUp(node);
    anticipateDown(svc, true);
    newSvc.bringUp();
    verifyAnticipated(5000);
}
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)

Example 10 with MockNode

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

the class PollerIT method testBug709.

@Test
public void testBug709() {
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    MockNode node = m_network.getNode(2);
    MockService icmpService = m_network.getService(2, "192.168.1.3", "ICMP");
    MockService httpService = m_network.getService(2, "192.168.1.3", "HTTP");
    // start the poller
    startDaemons();
    //
    // Bring Down the HTTP service and expect nodeLostService Event
    //
    resetAnticipated();
    anticipateDown(httpService);
    // bring down the HTTP service
    httpService.bringDown();
    verifyAnticipated(10000);
    //
    // Bring Down the ICMP (on the only interface on the node) now expect
    // nodeDown
    // only.
    //
    resetAnticipated();
    anticipateDown(node);
    // bring down the ICMP service
    icmpService.bringDown();
    // make sure the down events are received
    // verifyAnticipated(10000);
    sleep(5000);
    //
    // Bring up both the node and the httpService at the same time. Expect
    // both a nodeUp and a nodeRegainedService
    //
    resetAnticipated();
    // the order matters here
    anticipateUp(httpService);
    anticipateUp(node);
    // bring up all the services on the node
    node.bringUp();
    // make sure the down events are received
    verifyAnticipated(10000);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) 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