use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.
the class MockNetworkTest method testWaitForEvent.
public void testWaitForEvent() throws Throwable {
MockNode node = m_network.getNode(1);
final Event event1 = MockEventUtil.createNodeDownEvent("Test", node);
final Event event2 = MockEventUtil.createNodeDownEvent("Test", node);
final Event event3 = MockEventUtil.createNodeDownEvent("Test", m_network.getNode(2));
EventAnticipator anticipator = m_eventMgr.getEventAnticipator();
anticipator.anticipateEvent(event1);
anticipator.anticipateEvent(event3);
class EventSender extends Thread {
Throwable m_t = null;
public void assertSuccess() throws Throwable {
if (m_t != null)
throw m_t;
}
@Override
public void run() {
try {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
m_eventMgr.sendNow(event2);
m_eventMgr.sendNow(event2);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
m_eventMgr.sendNow(event3);
} catch (Throwable t) {
m_t = t;
}
}
}
;
EventSender eventSender = new EventSender();
eventSender.start();
eventSender.assertSuccess();
assertEquals(1, anticipator.waitForAnticipated(1500).size());
assertEquals(0, anticipator.waitForAnticipated(1000).size());
assertEquals(1, anticipator.getUnanticipatedEvents().size());
}
use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.
the class DragonWaveNodeSwitchingIT method testASetup.
@Test
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "192.168.255.22", resource = "classpath:/dw/walks/node3-walk.properties") })
public void testASetup() throws Exception {
final int nextNodeId = m_nodeDao.getNextNodeId();
final InetAddress iface = InetAddressUtils.addr("192.168.255.22");
final EventAnticipator anticipator = m_eventSubscriber.getEventAnticipator();
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).setService("SNMP").getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).setService("ICMP").getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.REINITIALIZE_PRIMARY_SNMP_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
importResource("classpath:/dw/import/dw_test_import.xml");
anticipator.verifyAnticipated(200000, 0, 0, 0, 0);
final OnmsNode onmsNode = m_nodeDao.findAll().get(0);
assertEquals(".1.3.6.1.4.1.7262.1", onmsNode.getSysObjectId());
}
use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.
the class RequisitionRestServiceIT method testImport.
@Test
public void testImport() throws Exception {
createRequisition();
EventAnticipator anticipator = m_eventProxy.getEventAnticipator();
sendRequest(PUT, "/requisitions/test/import", 202);
assertEquals(1, anticipator.getUnanticipatedEvents().size());
}
use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.
the class RequisitionRestServiceJsonIT method testImport.
@Test
public void testImport() throws Exception {
createRequisition();
EventAnticipator anticipator = m_eventProxy.getEventAnticipator();
sendRequest(PUT, "/requisitions/test/import", 202);
assertEquals(1, anticipator.getUnanticipatedEvents().size());
}
use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.
the class DiscoveryIntegrationIT method testDiscovery.
@Test
public void testDiscovery() throws Exception {
// Add a range of localhost IP addresses to ping
IncludeRange range = new IncludeRange();
range.setBegin("127.0.5.1");
range.setEnd("127.0.5.254");
range.setTimeout(5000l);
range.setRetries(0);
range.setLocation(CUSTOM_LOCATION);
DiscoveryConfiguration config = m_discoveryConfig.getConfiguration();
// Start immediately
config.setInitialSleepTime(0l);
// Discover 255 address ~= 10 seconds
config.setPacketsPerSecond(25.5);
// Add a discovery range to the config
config.clearIncludeRanges();
config.addIncludeRange(range);
// Don't actually save the config or we'll overwrite the
// opennms-base-assembly XML file
// m_discoveryConfig.saveConfiguration(config);
// m_discoveryConfig.reload();
// Anticipate newSuspect events for all of the addresses
EventAnticipator anticipator = m_eventIpcManager.getEventAnticipator();
StreamSupport.stream(m_discoveryConfig.getConfiguredAddresses().spliterator(), false).forEach(addr -> {
System.out.println("ANTICIPATING: " + str(addr.getAddress()));
Event event = new Event();
event.setUei(EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI);
event.setInterfaceAddress(addr.getAddress());
anticipator.anticipateEvent(event);
});
// Don't re-init Discovery or it will reload the
// DiscoveryConfigFactory and erase our changes to
// the config
// m_discovery.init();
m_discovery.start();
anticipator.waitForAnticipated(120000);
anticipator.verifyAnticipated();
anticipator.getAnticipatedEventsReceived().stream().forEach(eachEvent -> {
Assert.assertNotNull(eachEvent.getParm("location"));
Assert.assertEquals(CUSTOM_LOCATION, eachEvent.getParm("location").getValue().getContent());
});
m_discovery.stop();
}
Aggregations