use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PassiveStatusKeeperIT method testRestart.
@Test
public void testRestart() {
testSetStatus("localhost", "127.0.0.1", "PSV", PollStatus.up());
testSetStatus("localhost", "127.0.0.1", "PSV2", PollStatus.down());
MockService svc = m_network.getService(100, "127.0.0.1", "PSV2");
Event downEvent = svc.createDownEvent();
m_db.writeEvent(downEvent);
m_db.createOutage(svc, downEvent);
m_psk.stop();
m_psk.setEventManager(m_eventMgr);
m_psk.setDataSource(m_db);
m_psk.init();
m_psk.start();
assertEquals(PollStatus.up(), PassiveStatusKeeper.getInstance().getStatus("localhost", "127.0.0.1", "PSV"));
assertEquals(PollStatus.down(), PassiveStatusKeeper.getInstance().getStatus("localhost", "127.0.0.1", "PSV2"));
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerIT method testNoDuplicateOutagesWithUpDownDown.
/**
* Verifies that outages are properly opened and resolved
* when events arrive out of order.
*
* See NMS-7519 for details.
*/
@Test
public void testNoDuplicateOutagesWithUpDownDown() throws InterruptedException {
final MockService httpService = m_network.getService(2, "192.168.1.3", "HTTP");
final MockService smtpService = m_network.getService(2, "192.168.1.3", "SMTP");
// Start the poller
startDaemons();
// Starting with 0 outages
List<OnmsOutage> httpOutages = getOutages(httpService);
assertEquals(0, httpOutages.size());
// Halts all nodeLostService events until at least 2
// of them a queued.
//
// The event bus should receive the following sequence:
// nodeLostService
// nodeGainedService
// nodeLostService
//
// We're looking to reorder them as follows:
// nodeGainedService
// nodeLostService
// nodeLostService
QueueMultipleDownsHook hook = new QueueMultipleDownsHook(2);
m_eventMgr.setSendNowHook(hook);
// Verify that the initial latch count is 2
waitForHookCount(hook, 2);
// Take the HTTP service down
httpService.bringDown();
// Wait for the latch count to decrease
waitForHookCount(hook, 1);
m_eventMgr.getEventAnticipator().reset();
m_eventMgr.getEventAnticipator().anticipateEvent(httpService.createUpEvent());
// Bring the HTTP service back up even though the nodeLostService
// event is still pending
httpService.bringUp();
m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
// Take the HTTP service down again
httpService.bringDown();
// Wait for the latch count to decrease and send the queued events
waitForHookCount(hook, 0);
m_eventMgr.getEventAnticipator().reset();
m_eventMgr.getEventAnticipator().anticipateEvent(httpService.createUpEvent());
// Bring the HTTP service back online
httpService.bringUp();
m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
// We've succeeded in altering the order of events for the
// HTTP service. Now we make sure that outage processing
// continues to work as expeceted on a different service
m_eventMgr.setSendNowHook(null);
m_eventMgr.getEventAnticipator().reset();
m_eventMgr.getEventAnticipator().anticipateEvent(httpService.createUpEvent());
smtpService.bringDown();
m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
// Verifies that all of the outage fields are properly
// set for both outages affecting the HTTP service,
// even though the events we're send out of order
httpOutages = getOutages(httpService);
assertEquals(2, httpOutages.size());
assertNotNull(httpOutages.get(0).getIfRegainedService());
assertNotNull(httpOutages.get(0).getIfLostService());
assertNotNull(httpOutages.get(0).getIfRegainedService());
assertNotNull(httpOutages.get(0).getServiceRegainedEvent());
assertNotNull(httpOutages.get(1).getIfRegainedService());
assertNotNull(httpOutages.get(1).getIfLostService());
assertNotNull(httpOutages.get(1).getIfRegainedService());
assertNotNull(httpOutages.get(1).getServiceRegainedEvent());
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerIT method testServicesWithoutPackagesAreMarkedAsNotPolled.
/**
* Test for NMS-7426.
*/
@Test
public void testServicesWithoutPackagesAreMarkedAsNotPolled() {
MockService monitoredSvc = m_network.getService(5, "192.168.1.7", "SNMP");
MockService notMonitoredSvc = m_network.getService(5, "192.168.1.7", "NotMonitored");
OnmsMonitoredService notMonitored = m_monitoredServiceDao.get(notMonitoredSvc.getNodeId(), notMonitoredSvc.getAddress(), notMonitoredSvc.getSvcName());
// The status should be set initially set to active
assertEquals("A", notMonitored.getStatus());
// Start the poller
startDaemons();
// Take a service down, and wait for the event
// We do this to make ensure the nodes services we're in fact scheduled
anticipateDown(monitoredSvc);
monitoredSvc.bringDown();
verifyAnticipated(10000);
// The status should now be set to not monitored
notMonitored = m_monitoredServiceDao.get(notMonitoredSvc.getNodeId(), notMonitoredSvc.getAddress(), notMonitoredSvc.getSvcName());
assertEquals("N", notMonitored.getStatus());
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerIT method testNodeGainedServiceWhileNodeDownAndServiceDown.
@Test
public void testNodeGainedServiceWhileNodeDownAndServiceDown() {
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();
MockService newSvc = m_network.addService(4, "192.168.1.6", "SMTP");
m_db.writeService(newSvc);
newSvc.bringDown();
Event e = MockEventUtil.createNodeGainedServiceEvent("Test", newSvc);
m_eventMgr.sendEventToListeners(e);
sleep(5000);
System.err.println(m_db.getOutages());
verifyAnticipated(8000);
anticipateUp(node);
anticipateDown(svc, true);
newSvc.bringUp();
verifyAnticipated(5000);
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerIT 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);
}
Aggregations