Search in sources :

Example 1 with EventHandler

use of org.opennms.netmgt.events.api.EventHandler 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)));
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Log(org.opennms.netmgt.xml.event.Log) EventHandler(org.opennms.netmgt.events.api.EventHandler) Event(org.opennms.netmgt.xml.event.Event) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 EventHandler (org.opennms.netmgt.events.api.EventHandler)1 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)1 Event (org.opennms.netmgt.xml.event.Event)1 Log (org.opennms.netmgt.xml.event.Log)1