use of org.opennms.netmgt.mock.MockInterface in project opennms by OpenNMS.
the class PollerQueryManagerDaoIT method testReparentCausesStatusChange.
// test open outages for unmanaged services
@Test
public void testReparentCausesStatusChange() {
m_pollerConfig.setNodeOutageProcessingEnabled(true);
MockNode node1 = m_network.getNode(1);
MockNode node2 = m_network.getNode(2);
MockInterface dotOne = m_network.getInterface(1, "192.168.1.1");
MockInterface dotTwo = m_network.getInterface(1, "192.168.1.2");
MockInterface dotThree = m_network.getInterface(2, "192.168.1.3");
//
// Plan to bring down both nodes except the reparented interface
// the node owning the interface should be up while the other is down
// after reparenting we should got the old owner go down while the other
// comes up.
//
anticipateDown(node2);
anticipateDown(dotOne);
// bring down both nodes but bring iface back up
node1.bringDown();
node2.bringDown();
dotTwo.bringUp();
Event reparentEvent = MockEventUtil.createReparentEvent("Test", "192.168.1.2", 1, 2);
startDaemons();
verifyAnticipated(2000);
m_db.reparentInterface(dotTwo.getIpAddr(), dotTwo.getNodeId(), node2.getNodeId());
dotTwo.moveTo(node2);
resetAnticipated();
anticipateDown(node1, true);
anticipateUp(node2, true);
anticipateDown(dotThree, true);
m_eventMgr.sendEventToListeners(reparentEvent);
verifyAnticipated(20000);
}
use of org.opennms.netmgt.mock.MockInterface in project opennms by OpenNMS.
the class PollerQueryManagerDaoIT method testPolling.
@Test
public void testPolling() throws Exception {
m_pollerConfig.setNodeOutageProcessingEnabled(false);
// create a poll anticipator
PollAnticipator anticipator = new PollAnticipator();
// register it with the interfaces services
MockInterface iface = m_network.getInterface(1, "192.168.1.2");
iface.addAnticipator(anticipator);
//
// first ensure that polls are working while it is up
//
// anticipate three polls on all the interfaces services
anticipator.anticipateAllServices(iface);
anticipator.anticipateAllServices(iface);
anticipator.anticipateAllServices(iface);
// start the poller
startDaemons();
// wait for the polls to occur while its up... 1 poll per second plus
// overhead
assertEquals(0, anticipator.waitForAnticipated(4500L).size());
}
use of org.opennms.netmgt.mock.MockInterface in project opennms by OpenNMS.
the class NotifdIT method testRebuildParameterMap.
@Test
public void testRebuildParameterMap() throws Exception {
MockInterface iface = m_network.getInterface(1, "192.168.1.1");
Date downDate = new Date();
anticipateNotificationsForGroup("interface 192.168.1.1 down.", "All services are down on interface 192.168.1.1", "InitialGroup", downDate, 0);
// bring node down now
Event event = iface.createDownEvent(downDate);
m_eventMgr.sendEventToListeners(event);
sleep(1000);
Collection<Integer> notifIds = m_db.findNoticesForEvent(event);
Notification[] notification = m_notificationManager.getNotifForEvent(event);
int index = 0;
for (Integer notifId : notifIds) {
Map<String, String> originalMap = m_eventProcessor.buildParameterMap(notification[index], event, notifId.intValue());
Map<String, String> resolutionMap = new HashMap<String, String>(originalMap);
resolutionMap.put(NotificationManager.PARAM_SUBJECT, "RESOLVED: " + resolutionMap.get(NotificationManager.PARAM_SUBJECT));
resolutionMap.put(NotificationManager.PARAM_TEXT_MSG, "RESOLVED: " + resolutionMap.get(NotificationManager.PARAM_TEXT_MSG));
resolutionMap.put(NotificationManager.PARAM_NUM_MSG, "RESOLVED: " + resolutionMap.get(NotificationManager.PARAM_NUM_MSG));
Map<String, String> rebuiltMap = m_notifd.getBroadcastEventProcessor().rebuildParameterMap(notifId.intValue(), "RESOLVED: ", m_notifd.getConfigManager().getConfiguration().getNumericSkipResolutionPrefix());
assertEquals(resolutionMap, rebuiltMap);
index++;
}
}
use of org.opennms.netmgt.mock.MockInterface in project opennms by OpenNMS.
the class NotifdIT method testBug731.
/**
* see http://bugzilla.opennms.org/cgi-bin/bugzilla/show_bug.cgi?id=731
* @throws Exception
*/
@Test
public void testBug731() throws Exception {
MockInterface iface = m_network.getInterface(1, "192.168.1.1");
Date downDate = new Date();
anticipateNotificationsForGroup("interface 192.168.1.1 down.", "All services are down on interface 192.168.1.1, dot1 interface alias.", "InitialGroup", downDate, 0);
// bring node down now
Event event = iface.createDownEvent(downDate);
m_eventMgr.sendEventToListeners(event);
sleep(1000);
Date date = new Date();
Event upEvent = iface.createUpEvent(date);
anticipateNotificationsForGroup("RESOLVED: interface 192.168.1.1 down.", "RESOLVED: All services are down on interface 192.168.1.1, dot1 interface alias.", "InitialGroup", date, 0);
long endTime = anticipateNotificationsForGroup("interface 192.168.1.1 up.", "The interface which was previously down is now up.", "UpGroup", date, 0);
m_eventMgr.sendEventToListeners(upEvent);
verifyAnticipated(endTime, 1000, 5000);
}
use of org.opennms.netmgt.mock.MockInterface in project opennms by OpenNMS.
the class PollerIT method sendNodeGainedServices.
private void sendNodeGainedServices(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);
}
Aggregations