Search in sources :

Example 6 with PollAnticipator

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

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

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

the class PollerQueryManagerDaoIT method testElementDeleted.

// Test harness that tests any type of node, interface or element.
private void testElementDeleted(MockElement element) {
    Event deleteEvent = element.createDeleteEvent();
    m_pollerConfig.setNodeOutageProcessingEnabled(false);
    PollAnticipator poll = new PollAnticipator();
    element.addAnticipator(poll);
    poll.anticipateAllServices(element);
    startDaemons();
    // wait til after the first poll of the services
    poll.waitForAnticipated(1000L);
    // now delete the node and send a nodeDeleted event
    m_network.removeElement(element);
    m_eventMgr.sendEventToListeners(deleteEvent);
    // reset the poll count and wait to see if any polls on the removed
    // element happened
    m_network.resetInvalidPollCount();
    // now ensure that no invalid polls have occurred
    sleep(3000);
    assertEquals("Received a poll for an element that doesn't exist", 0, m_network.getInvalidPollCount());
}
Also used : PollAnticipator(org.opennms.netmgt.mock.PollAnticipator) Event(org.opennms.netmgt.xml.event.Event)

Aggregations

PollAnticipator (org.opennms.netmgt.mock.PollAnticipator)8 Event (org.opennms.netmgt.xml.event.Event)6 Test (org.junit.Test)4 MockInterface (org.opennms.netmgt.mock.MockInterface)4 MockNode (org.opennms.netmgt.mock.MockNode)4 ArrayList (java.util.ArrayList)2 MockService (org.opennms.netmgt.mock.MockService)2 MockVisitor (org.opennms.netmgt.mock.MockVisitor)2 MockVisitorAdapter (org.opennms.netmgt.mock.MockVisitorAdapter)2