Search in sources :

Example 1 with MockInterface

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

the class MockDatabase method populate.

public void populate(MockNetwork network) {
    MockVisitor dbCreater = new MockVisitorAdapter() {

        @Override
        public void visitNode(MockNode node) {
            writeNode(node);
        }

        @Override
        public void visitInterface(MockInterface iface) {
            writeInterface(iface);
        }

        @Override
        public void visitService(MockService svc) {
            writeService(svc);
        }

        @Override
        public void visitPathOutage(MockPathOutage out) {
            writePathOutage(out);
        }
    };
    network.visit(dbCreater);
    getJdbcTemplate().queryForObject("SELECT setval('nodeNxtId', max(nodeid)) FROM node", Integer.class);
}
Also used : MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockVisitor(org.opennms.netmgt.mock.MockVisitor) MockInterface(org.opennms.netmgt.mock.MockInterface) MockPathOutage(org.opennms.netmgt.mock.MockPathOutage) MockService(org.opennms.netmgt.mock.MockService) MockNode(org.opennms.netmgt.mock.MockNode)

Example 2 with MockInterface

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

the class MockDatabaseIT method testIFQuery.

public void testIFQuery() {
    Querier querier = new Querier(m_db, "select * from ipInterface") {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            int nodeId = rs.getInt("nodeId");
            String ipAddr = rs.getString("ipAddr");
            MockInterface iface = m_network.getInterface(nodeId, ipAddr);
            assertNotNull(iface);
            assertEquals(nodeId, iface.getNodeId());
            assertEquals(ipAddr, iface.getIpAddr());
        }
    };
    querier.execute();
    assertEquals(m_network.getInterfaceCount(), querier.getCount());
}
Also used : Querier(org.opennms.core.utils.Querier) MockInterface(org.opennms.netmgt.mock.MockInterface) ResultSet(java.sql.ResultSet)

Example 3 with MockInterface

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

the class PollerQueryManagerDaoIT 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 4 with MockInterface

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

the class PollerQueryManagerDaoIT method testPolling.

@Test
public void testPolling() throws Exception {
    m_pollerConfig.setNodeOutageProcessingEnabled(false);
    // create a poll anticipator
    PollAnticipator anticipator = new PollAnticipator();
    // register it with the interfaces services
    MockInterface iface = m_network.getInterface(1, "192.168.1.2");
    iface.addAnticipator(anticipator);
    //
    // first ensure that polls are working while it is up
    //
    // anticipate three polls on all the interfaces services
    anticipator.anticipateAllServices(iface);
    anticipator.anticipateAllServices(iface);
    anticipator.anticipateAllServices(iface);
    // start the poller
    startDaemons();
    // wait for the polls to occur while its up... 1 poll per second plus
    // overhead
    assertEquals(0, anticipator.waitForAnticipated(4500L).size());
}
Also used : PollAnticipator(org.opennms.netmgt.mock.PollAnticipator) MockInterface(org.opennms.netmgt.mock.MockInterface) Test(org.junit.Test)

Example 5 with MockInterface

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

the class PollerQueryManagerDaoIT method testInterfaceOutagesClosedOnDelete.

@Test
public void testInterfaceOutagesClosedOnDelete() {
    MockInterface element = m_network.getInterface(1, "192.168.1.1");
    testOutagesClosedOnDelete(element);
}
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