Search in sources :

Example 21 with MockInterface

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

the class PollerQueryManagerDaoIT method testSendNodeGainedServices.

private void testSendNodeGainedServices(int nodeid, String nodeLabel, String ipAddr, String... svcNames) {
    assertNotNull(svcNames);
    assertTrue(svcNames.length > 0);
    MockNode node = m_network.addNode(nodeid, nodeLabel);
    m_db.writeNode(node);
    MockInterface iface = m_network.addInterface(nodeid, ipAddr);
    m_db.writeInterface(iface);
    List<MockService> services = new ArrayList<MockService>();
    for (String svcName : svcNames) {
        MockService svc = m_network.addService(nodeid, ipAddr, svcName);
        m_db.writeService(svc);
        m_pollerConfig.addService(svc);
        services.add(svc);
    }
    MockVisitor gainSvcSender = new MockVisitorAdapter() {

        @Override
        public void visitService(MockService svc) {
            Event event = MockEventUtil.createNodeGainedServiceEvent("Test", svc);
            m_eventMgr.sendEventToListeners(event);
        }
    };
    node.visit(gainSvcSender);
    MockService svc1 = services.get(0);
    PollAnticipator anticipator = new PollAnticipator();
    svc1.addAnticipator(anticipator);
    anticipator.anticipateAllServices(svc1);
    StringBuffer didNotOccur = new StringBuffer();
    for (MockService service : anticipator.waitForAnticipated(10000)) {
        didNotOccur.append(service.toString());
    }
    StringBuffer unanticipatedStuff = new StringBuffer();
    for (MockService service : anticipator.unanticipatedPolls()) {
        unanticipatedStuff.append(service.toString());
    }
    assertEquals(unanticipatedStuff.toString(), "", didNotOccur.toString());
    anticipateDown(svc1);
    svc1.bringDown();
    verifyAnticipated(10000);
}
Also used : PollAnticipator(org.opennms.netmgt.mock.PollAnticipator) MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockInterface(org.opennms.netmgt.mock.MockInterface) MockVisitor(org.opennms.netmgt.mock.MockVisitor) ArrayList(java.util.ArrayList) MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event) MockNode(org.opennms.netmgt.mock.MockNode)

Example 22 with MockInterface

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

the class PollerQueryManagerDaoIT method testInterfaceDeleted.

// interfaceDeleted: EventConstants.INTERFACE_DELETED_EVENT_UEI
@Test
public void testInterfaceDeleted() {
    MockInterface iface = m_network.getInterface(1, "192.168.1.1");
    testElementDeleted(iface);
}
Also used : MockInterface(org.opennms.netmgt.mock.MockInterface) Test(org.junit.Test)

Example 23 with MockInterface

use of org.opennms.netmgt.mock.MockInterface 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 24 with MockInterface

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

the class PollerQueryManagerDaoIT method testUnmangedWithOpenOutageAtStartup.

// test open outages for unmanaged services
@Test
public void testUnmangedWithOpenOutageAtStartup() throws InterruptedException {
    // before we start we need to initialize the database
    // create an outage for the service
    MockService svc = m_network.getService(1, "192.168.1.1", "SMTP");
    MockInterface iface = m_network.getInterface(1, "192.168.1.2");
    Event svcLostEvent = MockEventUtil.createNodeLostServiceEvent("Test", svc);
    m_db.writeEvent(svcLostEvent);
    createOutages(svc, svcLostEvent);
    Event ifaceDownEvent = MockEventUtil.createInterfaceDownEvent("Test", iface);
    m_db.writeEvent(ifaceDownEvent);
    createOutages(iface, ifaceDownEvent);
    // mark the service as unmanaged
    m_db.setServiceStatus(svc, 'U');
    m_db.setInterfaceStatus(iface, 'U');
    // assert that we have an open outage
    assertEquals(1, m_db.countOpenOutagesForService(svc));
    assertEquals(1, m_db.countOutagesForService(svc));
    assertEquals(iface.getServices().size(), m_db.countOutagesForInterface(iface));
    assertEquals(iface.getServices().size(), m_db.countOpenOutagesForInterface(iface));
    startDaemons();
    // assert that we have no open outages
    assertEquals(0, m_db.countOpenOutagesForService(svc));
    assertEquals(1, m_db.countOutagesForService(svc));
    assertEquals(0, m_db.countOpenOutagesForInterface(iface));
    assertEquals(iface.getServices().size(), m_db.countOutagesForInterface(iface));
}
Also used : MockInterface(org.opennms.netmgt.mock.MockInterface) MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

Example 25 with MockInterface

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

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

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