Search in sources :

Example 46 with MockNode

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

the class PollerQueryManagerDaoIT 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 47 with MockNode

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

the class PollerQueryManagerDaoIT method testNodeLabelChanged.

// nodeLabelChanged: EventConstants.NODE_LABEL_CHANGED_EVENT_UEI
@Test
public void testNodeLabelChanged() {
    MockNode element = m_network.getNode(1);
    String newLabel = "NEW LABEL";
    Event event = element.createNodeLabelChangedEvent(newLabel);
    m_pollerConfig.setNodeOutageProcessingEnabled(false);
    PollAnticipator poll = new PollAnticipator();
    element.addAnticipator(poll);
    poll.anticipateAllServices(element);
    startDaemons();
    // wait until after the first poll of the services
    poll.waitForAnticipated(1000L);
    assertEquals("Router", m_poller.getNetwork().getNode(1).getNodeLabel());
    // now delete the node and send a nodeDeleted event
    element.setLabel(newLabel);
    m_eventMgr.sendEventToListeners(event);
    assertEquals(newLabel, m_poller.getNetwork().getNode(1).getNodeLabel());
}
Also used : PollAnticipator(org.opennms.netmgt.mock.PollAnticipator) Event(org.opennms.netmgt.xml.event.Event) MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Example 48 with MockNode

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

the class PollerIT method testInterfaceReparented.

// interfaceReparented: EventConstants.INTERFACE_REPARENTED_EVENT_UEI
@Test
public void testInterfaceReparented() throws Exception {
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    MockNode node1 = m_network.getNode(1);
    MockNode node2 = m_network.getNode(2);
    assertNotNull("Node 1 should have 192.168.1.1", node1.getInterface("192.168.1.1"));
    assertNotNull("Node 1 should have 192.168.1.2", node1.getInterface("192.168.1.2"));
    assertNull("Node 2 should not yet have 192.168.1.2", node2.getInterface("192.168.1.2"));
    assertNotNull("Node 2 should have 192.168.1.3", node2.getInterface("192.168.1.3"));
    MockInterface dotTwo = m_network.getInterface(1, "192.168.1.2");
    MockInterface dotThree = m_network.getInterface(2, "192.168.1.3");
    Event reparentEvent = MockEventUtil.createReparentEvent("Test", "192.168.1.2", 1, 2);
    // we are going to reparent to node 2 so when we bring down its only
    // current interface we expect an interface down not the whole node.
    anticipateDown(dotThree);
    startDaemons();
    final int waitTime = 2000;
    final int verifyTime = 2000;
    sleep(waitTime);
    // move the reparented interface and send a reparented event
    dotTwo.moveTo(node2);
    m_db.reparentInterface(dotTwo.getIpAddr(), node1.getNodeId(), node2.getNodeId());
    // send the reparent event to the daemons
    m_eventMgr.sendEventToListeners(reparentEvent);
    sleep(waitTime);
    // now bring down the other interface on the new node
    // System.err.println("Bring Down:"+node2Iface);
    dotThree.bringDown();
    verifyAnticipated(verifyTime);
    resetAnticipated();
    anticipateDown(node2);
    // System.err.println("Bring Down:"+reparentedIface);
    dotTwo.bringDown();
    sleep(waitTime);
    verifyAnticipated(verifyTime);
    node1 = m_network.getNode(1);
    node2 = m_network.getNode(2);
    assertNotNull("Node 1 should still have 192.168.1.1", node1.getInterface("192.168.1.1"));
    assertNull("Node 1 should no longer have 192.168.1.2", node1.getInterface("192.168.1.2"));
    assertNotNull("Node 2 should now have 192.168.1.2", node2.getInterface("192.168.1.2"));
    assertNotNull("Node 2 should still have 192.168.1.3", node2.getInterface("192.168.1.3"));
}
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 49 with MockNode

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

the class PollerIT 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)

Example 50 with MockNode

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

the class PollerQueryManagerDaoIT method testNodeOutageProcessingDisabled.

// test to see that node lost/regained service events come in
@Test
public void testNodeOutageProcessingDisabled() throws Exception {
    m_pollerConfig.setNodeOutageProcessingEnabled(false);
    MockNode node = m_network.getNode(1);
    startDaemons();
    resetAnticipated();
    anticipateServicesDown(node);
    node.bringDown();
    verifyAnticipated(10000);
    resetAnticipated();
    anticipateServicesUp(node);
    node.bringUp();
    verifyAnticipated(10000);
}
Also used : MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Aggregations

MockNode (org.opennms.netmgt.mock.MockNode)53 Test (org.junit.Test)43 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 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)5 ResultSet (java.sql.ResultSet)4 PollAnticipator (org.opennms.netmgt.mock.PollAnticipator)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