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);
}
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);
}
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);
}
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());
}
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));
}
Aggregations