Search in sources :

Example 51 with MockNode

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

the class NotifdIT method testMockNotificationInitialDelay.

@Test
public void testMockNotificationInitialDelay() throws Exception {
    m_destinationPathManager.getPath("NoEscalate").setInitialDelay("1800ms");
    MockNode node = m_network.getNode(1);
    Date downDate = new Date(new Date().getTime() + 1800);
    long finished = anticipateNotificationsForGroup("node 1 down.", "All services are down on node 1.", "InitialGroup", downDate, 0);
    m_eventMgr.sendEventToListeners(node.createDownEvent(downDate));
    verifyAnticipated(finished, 3000);
}
Also used : MockNode(org.opennms.netmgt.mock.MockNode) Date(java.util.Date) Test(org.junit.Test)

Example 52 with MockNode

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

the class PollablesIT method addDownServiceToDownNode.

private void addDownServiceToDownNode(int nodeId, String nodeLabel, String nodeLocation, String ipAddr, String existingSvcName, String newSvcName) {
    MockNode mNode = m_mockNetwork.getNode(nodeId);
    PollableService pExistingSvc = m_network.getService(nodeId, getInetAddress(ipAddr), existingSvcName);
    PollableInterface pIface = pExistingSvc.getInterface();
    PollableNode pNode = pExistingSvc.getNode();
    // before we start make sure the node is down
    anticipateDown(mNode);
    mNode.bringDown();
    pExistingSvc.doPoll();
    m_network.processStatusChange(new Date());
    verifyAnticipated();
    // ok the node is down.. here is the cause
    PollEvent nodeCause = pNode.getCause();
    // add a new mock service 
    MockService mSvc = m_mockNetwork.addService(nodeId, ipAddr, newSvcName);
    m_db.writeService(mSvc);
    // that is down
    mSvc.bringDown();
    // expect nothing since we already have node down event outstanding
    // simulate a nodeGainedService event
    PollableService pSvc = addServiceToNetwork(nodeId, nodeLabel, nodeLocation, ipAddr, newSvcName);
    assertNotNull(pSvc);
    // before the first poll everthing should have the node down cause
    assertElementHasCause(pSvc, nodeCause);
    assertElementHasCause(pExistingSvc, nodeCause);
    assertElementHasCause(pIface, nodeCause);
    assertElementHasCause(pNode, nodeCause);
    // and should be mored down
    assertDown(pSvc);
    assertDown(pExistingSvc);
    assertDown(pIface);
    assertDown(pNode);
    // now to the first poll
    pSvc.doPoll();
    // everything should still be down
    assertDown(pSvc);
    assertDown(pExistingSvc);
    assertDown(pIface);
    assertDown(pNode);
    m_network.processStatusChange(new Date());
    // and should have the same node down cause
    assertElementHasCause(pSvc, nodeCause);
    assertElementHasCause(pExistingSvc, nodeCause);
    assertElementHasCause(pIface, nodeCause);
    assertElementHasCause(pNode, nodeCause);
    // verify we've received no events
    verifyAnticipated();
}
Also used : MockService(org.opennms.netmgt.mock.MockService) MockNode(org.opennms.netmgt.mock.MockNode) Date(java.util.Date)

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