Search in sources :

Example 36 with MockService

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

the class PollerQueryManagerDaoIT method testBug709.

@Test
public void testBug709() {
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    MockNode node = m_network.getNode(2);
    MockService icmpService = m_network.getService(2, "192.168.1.3", "ICMP");
    MockService httpService = m_network.getService(2, "192.168.1.3", "HTTP");
    // start the poller
    startDaemons();
    // 
    // Bring Down the HTTP service and expect nodeLostService Event
    // 
    resetAnticipated();
    anticipateDown(httpService);
    // bring down the HTTP service
    httpService.bringDown();
    verifyAnticipated(10000);
    // 
    // Bring Down the ICMP (on the only interface on the node) now expect
    // nodeDown
    // only.
    // 
    resetAnticipated();
    anticipateDown(node);
    // bring down the ICMP service
    icmpService.bringDown();
    // make sure the down events are received
    // verifyAnticipated(10000);
    sleep(5000);
    // 
    // Bring up both the node and the httpService at the same time. Expect
    // both a nodeUp and a nodeRegainedService
    // 
    resetAnticipated();
    // the order matters here
    anticipateUp(httpService);
    anticipateUp(node);
    // bring up all the services on the node
    node.bringUp();
    // make sure the down events are received
    verifyAnticipated(10000);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Example 37 with MockService

use of org.opennms.netmgt.mock.MockService 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<>();
    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);
    final StringBuilder didNotOccur = new StringBuilder();
    for (MockService service : anticipator.waitForAnticipated(10000)) {
        didNotOccur.append(service.toString());
    }
    final StringBuilder unanticipatedStuff = new StringBuilder();
    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 38 with MockService

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

the class PollerQueryManagerDaoIT method testNullInterfaceOnNodeDown.

// public void testDemandPollService() {
// DemandPoll demandPoll = new DemandPoll();
// demandPoll.setDescription("Test Poll");
// demandPoll.setRequestTime(new Date());
// demandPoll.setUserName("admin");
// 
// m_demandPollDao.save(demandPoll);
// 
// assertNotNull(demandPoll.getId());
// 
// MockService httpService = m_network
// .getService(2, "192.168.1.3", "HTTP");
// Event demandPollEvent = httpService.createDemandPollEvent(demandPoll.getId());
// 
// }
@Test
public void testNullInterfaceOnNodeDown() {
    // NODE processing = true;
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    MockNode node = m_network.getNode(2);
    MockService icmpService = m_network.getService(2, "192.168.1.3", "ICMP");
    MockService smtpService = m_network.getService(2, "192.168.1.3", "SMTP");
    MockService snmpService = m_network.getService(2, "192.168.1.3", "SNMP");
    // start the poller
    startDaemons();
    anticipateDown(node);
    icmpService.bringDown();
    smtpService.bringDown();
    snmpService.bringDown();
    verifyAnticipated(10000);
    // node is down at this point
    boolean foundNodeDown = false;
    for (final Event event : m_eventMgr.getEventAnticipator().getAnticipatedEventsReceived()) {
        if (EventConstants.NODE_DOWN_EVENT_UEI.equals(event.getUei())) {
            foundNodeDown = true;
            assertNull(event.getInterfaceAddress());
        }
    }
    assertTrue(foundNodeDown);
}
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 39 with MockService

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

the class MockDatabaseIT method testOutage.

public void testOutage() {
    final MockService svc = m_network.getService(1, "192.168.1.1", "ICMP");
    Event svcLostEvent = MockEventUtil.createNodeLostServiceEvent("TEST", svc);
    m_db.writeEvent(svcLostEvent);
    m_db.createOutage(svc, svcLostEvent);
    assertEquals(1, m_db.countOutagesForService(svc));
    Querier querier = new Querier(m_db, "select node.nodeid as nodeid, ipinterface.ipaddr as ipaddr, ifservices.serviceid as serviceid from outages, ifservices, ipinterface, node where outages.ifserviceid = ifservices.id and ifservices.ipinterfaceid = ipinterface.id and ipinterface.nodeid = node.nodeid") {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            int nodeId = rs.getInt("nodeId");
            String ipAddr = rs.getString("ipAddr");
            int serviceId = rs.getInt("serviceId");
            assertEquals(nodeId, svc.getNodeId());
            assertEquals(ipAddr, svc.getIpAddr());
            assertEquals(serviceId, svc.getSvcId());
        }
    };
    querier.execute();
    assertEquals(1, querier.getCount());
}
Also used : Querier(org.opennms.core.utils.Querier) ResultSet(java.sql.ResultSet) MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event)

Example 40 with MockService

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

the class MockDatabaseIT method testSetServiceStatus.

public void testSetServiceStatus() {
    MockService svc = m_network.getService(1, "192.168.1.1", "SMTP");
    assertEquals('A', m_db.getServiceStatus(svc));
    m_db.setServiceStatus(svc, 'U');
    assertEquals('U', m_db.getServiceStatus(svc));
}
Also used : MockService(org.opennms.netmgt.mock.MockService)

Aggregations

MockService (org.opennms.netmgt.mock.MockService)59 Test (org.junit.Test)36 Event (org.opennms.netmgt.xml.event.Event)19 MockNode (org.opennms.netmgt.mock.MockNode)16 MockVisitor (org.opennms.netmgt.mock.MockVisitor)14 MockVisitorAdapter (org.opennms.netmgt.mock.MockVisitorAdapter)14 Date (java.util.Date)8 MockInterface (org.opennms.netmgt.mock.MockInterface)8 Timestamp (java.sql.Timestamp)3 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)3 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Ignore (org.junit.Ignore)2 Querier (org.opennms.core.utils.Querier)2 PollAnticipator (org.opennms.netmgt.mock.PollAnticipator)2 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)1 LocationAwarePingClient (org.opennms.netmgt.icmp.proxy.LocationAwarePingClient)1 MockNetwork (org.opennms.netmgt.mock.MockNetwork)1