use of org.opennms.netmgt.xml.event.Event 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.xml.event.Event in project opennms by OpenNMS.
the class MockNetworkTest method testEventListeners.
public void testEventListeners() {
Event sentEvent = MockEventUtil.createEvent("Test", EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, 1, "192.168.1.1", "NEW", null);
Event sentEvent2 = MockEventUtil.createEvent("Test", EventConstants.NODE_REGAINED_SERVICE_EVENT_UEI, 1, "192.168.1.1", "NEW", null);
class MockListener implements EventListener {
private Event receivedEvent;
@Override
public String getName() {
return "MockListener";
}
public Event getReceivedEvent() {
return receivedEvent;
}
@Override
public void onEvent(Event event) {
System.err.println("onEvent: " + event.getUei());
receivedEvent = event;
}
public void reset() {
receivedEvent = null;
}
}
;
MockListener listener = new MockListener();
m_eventMgr.addEventListener(listener, EventConstants.NODE_GAINED_SERVICE_EVENT_UEI);
m_eventMgr.sendEventToListeners(sentEvent);
assertTrue(EventUtils.eventsMatch(sentEvent, listener.getReceivedEvent()));
listener.reset();
m_eventMgr.sendEventToListeners(sentEvent2);
assertFalse(EventUtils.eventsMatch(sentEvent2, listener.getReceivedEvent()));
}
use of org.opennms.netmgt.xml.event.Event in project opennms by OpenNMS.
the class TransactionAwareEventForwarderIT method testTwoTransactions.
@Test
public void testTwoTransactions() {
m_transTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
Event event = sendEvent();
getEventAnticipator().anticipateEvent(event);
}
});
m_transTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
Event event = sendEvent();
getEventAnticipator().anticipateEvent(event);
}
});
}
use of org.opennms.netmgt.xml.event.Event in project opennms by OpenNMS.
the class TrapHandlerITCase method testV2EnterpriseIdAndGenericAndSpecificAndMatchWithVarbindsAndTC.
// FIXME: these exist to provide testing for the new Textual Convention feature
@Test
@DirtiesContext
public void testV2EnterpriseIdAndGenericAndSpecificAndMatchWithVarbindsAndTC() throws Exception {
SnmpValueFactory valueFactory = SnmpUtils.getValueFactory();
byte[] macAddr = new byte[] { (byte) 0x00, (byte) 0x14, (byte) 0xf1, (byte) 0xad, (byte) 0xa7, (byte) 0x50 };
String encoded = new String(Base64.encodeBase64(macAddr));
byte[] decodeBytes = Base64.decodeBase64(encoded.toCharArray());
assertByteArrayEquals(macAddr, decodeBytes);
LinkedHashMap<String, SnmpValue> varbinds = new LinkedHashMap<String, SnmpValue>();
varbinds.put(".1.3.6.1.4.1.14179.2.6.2.20.0", valueFactory.getOctetString(macAddr));
Collection<Event> events = anticipateAndSend(false, true, "uei.opennms.org/vendor/cisco/bsnAPNoiseProfileUpdatedToPass", "v2c", ".1.3.6.1.4.1.14179.2.6.3", 6, 38, varbinds);
boolean foundMacAddress = false;
// Assert that the MAC address varbind has been formatted into a colon-separated octet string
for (Event event : events) {
for (Parm parm : event.getParmCollection()) {
if (".1.3.6.1.4.1.14179.2.6.2.20.0".equals(parm.getParmName())) {
assertEquals("MAC address does not match", "00:14:F1:AD:A7:50", parm.getValue().getContent());
foundMacAddress = true;
}
}
}
assertTrue("Did not find expected MAC address parm", foundMacAddress);
}
use of org.opennms.netmgt.xml.event.Event in project opennms by OpenNMS.
the class TrapHandlerITCase method testInterfaceDeletedModifiesIpMgr.
@Test
@DirtiesContext
public void testInterfaceDeletedModifiesIpMgr() throws Exception {
// Put the default list of nodes in the database
m_dbPopulator.populateDatabase();
// Sync the managed interface cache
m_cache.dataSourceSync();
long nodeId = 0;
// Send an interfaceDeleted to clear the entry out of the cache
Event event = anticipateEvent(EventConstants.INTERFACE_DELETED_EVENT_UEI, m_ip, m_dbPopulator.getNode1().getId());
m_eventMgr.sendNow(event);
// Anticipate the trap and the newSuspect event
anticipateEvent("uei.opennms.org/default/trap", m_ip, nodeId);
anticipateEvent(EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI, m_ip, nodeId);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// do nothing
}
sendTrap("v1", null, 6, 1);
finishUp();
m_dbPopulator.resetDatabase();
m_cache.clear();
}
Aggregations