use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerIT method closesOpenOutagesWithNoSvcLostEventIdOnRestart.
/**
* Test for NMS-7585
*/
@Test
public void closesOpenOutagesWithNoSvcLostEventIdOnRestart() {
MockNode node = m_network.getNode(2);
MockService criticalService = m_network.getService(2, "192.168.1.3", "ICMP");
// Bring the critical service down
anticipateDown(node);
criticalService.bringDown();
// Start the poller
startDaemons();
// Verify
verifyAnticipated(10000);
// Stop the poller
stopDaemons();
// Remove the reference to the lost service event from all of the outages,
// and let's pretend that they weren't even there in the first place
Set<Integer> outageIds = new HashSet<Integer>();
for (OnmsOutage outage : m_outageDao.findAll()) {
outage.setServiceLostEvent(null);
m_outageDao.update(outage);
outageIds.add(outage.getId());
}
m_outageDao.flush();
// We should get another node down
m_eventMgr.getEventAnticipator().anticipateEvent(node.createDownEvent());
// (Re)start the poller
startDaemons();
// Verify
m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
// Wait for the outages to be populated (this happen after
// the down event is sent)
sleep(1000);
for (OnmsOutage outage : m_outageDao.findAll()) {
if (outageIds.contains(outage.getId())) {
// Outages in our list should be closed with
// no svcRegainedEvent
assertNotNull(outage.getIfRegainedService());
assertNull(outage.getServiceRegainedEvent());
} else {
// Other outages should be open
assertNull(outage.getIfRegainedService());
}
}
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerIT method testSuspendPollingResumeService.
@Test(timeout = 30000)
public void testSuspendPollingResumeService() {
MockService svc = m_network.getService(1, "192.168.1.2", "SMTP");
assertTrue(svc.getPollCount() < 1);
startDaemons();
while (svc.getPollCount() < 1) {
sleep(500);
}
assertTrue(0 < svc.getPollCount());
m_eventMgr.sendEventToListeners(MockEventUtil.createSuspendPollingServiceEvent("Test", svc));
svc.resetPollCount();
for (int i = 0; i < 10; i++) {
// Make sure that the count remains at zero
assertEquals(0, svc.getPollCount());
sleep(500);
}
m_eventMgr.sendEventToListeners(MockEventUtil.createResumePollingServiceEvent("Test", svc));
while (svc.getPollCount() < 1) {
sleep(500);
}
assertTrue(0 < svc.getPollCount());
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerQueryManagerDaoIT method testNodeGainedServiceWhileNodeDownAndServiceUp.
@Test
public void testNodeGainedServiceWhileNodeDownAndServiceUp() {
startDaemons();
MockNode node = m_network.getNode(4);
MockService svc = m_network.getService(4, "192.168.1.6", "SNMP");
anticipateDown(node);
node.bringDown();
verifyAnticipated(5000);
resetAnticipated();
anticipateUp(node);
anticipateDown(svc, true);
MockService newSvc = m_network.addService(4, "192.168.1.6", "SMTP");
m_db.writeService(newSvc);
Event e = MockEventUtil.createNodeGainedServiceEvent("Test", newSvc);
m_eventMgr.sendEventToListeners(e);
sleep(5000);
System.err.println(m_db.getOutages());
verifyAnticipated(8000);
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerIT method testServiceOutagesClosedOnDelete.
@Test
public void testServiceOutagesClosedOnDelete() {
MockService element = m_network.getService(1, "192.168.1.1", "SMTP");
testOutagesClosedOnDelete(element);
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerIT method testUnmangedWithOpenOutageAtStartup.
// test open outages for unmanaged services
@Test
public void testUnmangedWithOpenOutageAtStartup() {
// before we start we need to initialize the database
// create an outage for the service
MockService svc = m_network.getService(1, "192.168.1.1", "SMTP");
MockInterface iface = m_network.getInterface(1, "192.168.1.2");
Event svcLostEvent = MockEventUtil.createNodeLostServiceEvent("Test", svc);
m_db.writeEvent(svcLostEvent);
createOutages(svc, svcLostEvent);
Event ifaceDownEvent = MockEventUtil.createInterfaceDownEvent("Test", iface);
m_db.writeEvent(ifaceDownEvent);
createOutages(iface, ifaceDownEvent);
// mark the service as unmanaged
m_db.setServiceStatus(svc, 'U');
m_db.setInterfaceStatus(iface, 'U');
// assert that we have an open outage
assertEquals(1, m_db.countOpenOutagesForService(svc));
assertEquals(1, m_db.countOutagesForService(svc));
assertEquals(iface.getServices().size(), m_db.countOutagesForInterface(iface));
assertEquals(iface.getServices().size(), m_db.countOpenOutagesForInterface(iface));
startDaemons();
// assert that we have no open outages
assertEquals(0, m_db.countOpenOutagesForService(svc));
assertEquals(1, m_db.countOutagesForService(svc));
assertEquals(0, m_db.countOpenOutagesForInterface(iface));
assertEquals(iface.getServices().size(), m_db.countOutagesForInterface(iface));
}
Aggregations