use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventIpcManagerDefaultImplTest method testSlowEventHandlerCausesDiscards.
public void testSlowEventHandlerCausesDiscards() throws InterruptedException {
AtomicInteger counter = new AtomicInteger();
AtomicInteger rejected = new AtomicInteger();
EventHandler handler = new EventHandler() {
@Override
public Runnable createRunnable(Log eventLog, boolean synchronous) {
return createRunnable(eventLog);
}
@Override
public Runnable createRunnable(Log eventLog) {
return new Runnable() {
@Override
public void run() {
try {
Thread.sleep(SLOW_EVENT_OPERATION_DELAY);
} catch (InterruptedException e) {
}
counter.incrementAndGet();
}
};
}
};
EventIpcManagerDefaultImpl manager = new EventIpcManagerDefaultImpl(m_registry);
manager.setEventHandler(handler);
manager.setHandlerPoolSize(1);
manager.setHandlerQueueLength(5);
manager.afterPropertiesSet();
//
for (int i = 0; i < 10; i++) {
EventBuilder bldr = new EventBuilder("uei.opennms.org/foo/" + i, "testDiscardWhenFullWithSlowEventListener");
Event event = bldr.getEvent();
try {
manager.sendNow(event);
} catch (RejectedExecutionException e) {
rejected.incrementAndGet();
}
}
await().pollInterval(1, TimeUnit.SECONDS).untilAtomic(counter, is(equalTo(6)));
await().pollInterval(1, TimeUnit.SECONDS).untilAtomic(rejected, is(equalTo(4)));
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventIpcManagerDefaultImplTest method testBroadcastNowSync.
public void testBroadcastNowSync() throws InterruptedException {
final AtomicInteger counter = new AtomicInteger();
final EventListener slowListener = new EventListener() {
@Override
public String getName() {
return "testBroadcastNowSync";
}
@Override
public void onEvent(Event event) {
try {
Thread.sleep(TimeUnit.SECONDS.toMillis(2));
} catch (InterruptedException e) {
}
counter.incrementAndGet();
}
};
EventIpcManagerDefaultImpl manager = new EventIpcManagerDefaultImpl(m_registry);
manager.setHandlerPoolSize(5);
DefaultEventHandlerImpl handler = new DefaultEventHandlerImpl(m_registry);
manager.setEventHandler(handler);
manager.afterPropertiesSet();
manager.addEventListener(slowListener);
EventBuilder bldr = new EventBuilder("uei.opennms.org/foo", "testBroadcastNowSync");
Event e = bldr.getEvent();
// Verify the initial state
assertEquals(0, counter.get());
// Broadcast synchronously - this should block until our event listener returns
manager.broadcastNow(e, true);
// broadcastNow() returned, so the counter should have been increased
assertEquals(1, counter.get());
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class BroadcastEventProcessorTest method testReload.
public void testReload() {
MockEventIpcManager eventIpcManager = new MockEventIpcManager();
BroadcastEventProcessor processor = new BroadcastEventProcessor(eventIpcManager, m_eventConfDao);
EventBuilder eventBuilder = new EventBuilder(EventConstants.EVENTSCONFIG_CHANGED_EVENT_UEI, "dunno");
// Expect a call to reload the EventConfDao
m_eventConfDao.reload();
m_mocks.replayAll();
processor.onEvent(eventBuilder.getEvent());
m_mocks.verifyAll();
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventIpcManagerDefaultImplTest method testAsyncVsSyncSendNow.
public void testAsyncVsSyncSendNow() throws InterruptedException {
ThreadRecordingEventHandler threadRecordingEventHandler = new ThreadRecordingEventHandler();
m_manager.setEventHandler(threadRecordingEventHandler);
EventBuilder bldr = new EventBuilder("uei.opennms.org/foo", "testAsyncVsSyncSendNow");
Event e = bldr.getEvent();
// Async: When invoking sendNow, the Runnable should be ran from thread other than the callers
m_manager.sendNow(e);
threadRecordingEventHandler.waitForEvent();
assertNotEquals(Thread.currentThread().getId(), threadRecordingEventHandler.getThreadId());
// Sync: When invoking sendNowSync, the Runnable should be ran from the callers thread
m_manager.sendNowSync(e);
assertEquals(Thread.currentThread().getId(), threadRecordingEventHandler.getThreadId());
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventUtilHibernateIT method testExpandParms.
@Test
@JUnitTemporaryDatabase
public void testExpandParms() {
String testString = "%uei%:%nodeid%:%nodelabel%:%nodelocation%";
/*
* Checking default location
*/
Event event1 = new EventBuilder("testUei", "testSource").setNodeid(1).getEvent();
String string1 = eventUtilDaoImpl.expandParms(testString, event1);
assertEquals("testUei:1:node1:Default", string1);
/*
* Checking custom location
*/
OnmsNode onmsNode = m_populator.getNodeDao().get(2);
onmsNode.setLocation(m_populator.getMonitoringLocationDao().get("RDU"));
m_populator.getNodeDao().update(onmsNode);
Event event2 = new EventBuilder("testUei", "testSource").setNodeid(2).getEvent();
String string2 = eventUtilDaoImpl.expandParms(testString, event2);
assertEquals("testUei:2:node2:RDU", string2);
}
Aggregations