Search in sources :

Example 76 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class EventIpcManagerDefaultImplTest method testAddEventListenerAndBroadcast.

public void testAddEventListenerAndBroadcast() throws Exception {
    EventBuilder bldr = new EventBuilder(null, "testAddEventListenerAndBroadcast");
    Event event = bldr.getEvent();
    m_mocks.replayAll();
    m_manager.addEventListener(m_listener);
    m_manager.broadcastNow(event, false);
    Thread.sleep(100);
    m_mocks.verifyAll();
    assertTrue("could not remove broadcasted event--did it make it?", m_listener.getEvents().remove(event));
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event)

Example 77 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class EventIpcManagerDefaultImplTest method testAddEventListenerTwoArgumentStringWithUeiPartTooMuchAndBroadcast.

public void testAddEventListenerTwoArgumentStringWithUeiPartTooMuchAndBroadcast() throws Exception {
    EventBuilder bldr = new EventBuilder("uei.opennms.org/foo", "testAddEventListenerTwoArgumentStringWithUeiPartTooMuchAndBroadcast");
    Event e = bldr.getEvent();
    m_mocks.replayAll();
    m_manager.addEventListener(m_listener, "uei.opennms.org/*");
    m_manager.broadcastNow(e, false);
    Thread.sleep(100);
    m_mocks.verifyAll();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event)

Example 78 with EventBuilder

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

Example 79 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class EventIpcManagerDefaultImplTest method testBroadcastWithNoListeners.

public void testBroadcastWithNoListeners() throws Exception {
    EventBuilder bldr = new EventBuilder(null, "testBroadcastWithNoListeners");
    m_mocks.replayAll();
    m_manager.broadcastNow(bldr.getEvent(), false);
    Thread.sleep(100);
    m_mocks.verifyAll();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

Example 80 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class EventIpcManagerDefaultImplTest method testAddEventListenerTwoArgumentStringWithUeiPartTooLittleAndBroadcast.

public void testAddEventListenerTwoArgumentStringWithUeiPartTooLittleAndBroadcast() throws Exception {
    EventBuilder bldr = new EventBuilder("uei.opennms.org/foo", "testAddEventListenerTwoArgumentStringWithUeiPartTooLittleAndBroadcast");
    Event e = bldr.getEvent();
    m_mocks.replayAll();
    m_manager.addEventListener(m_listener, "uei.opennms.org");
    m_manager.broadcastNow(e, false);
    Thread.sleep(100);
    m_mocks.verifyAll();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event)

Aggregations

EventBuilder (org.opennms.netmgt.model.events.EventBuilder)305 Test (org.junit.Test)88 Event (org.opennms.netmgt.xml.event.Event)84 Date (java.util.Date)22 OnmsNode (org.opennms.netmgt.model.OnmsNode)17 InetAddress (java.net.InetAddress)16 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)15 AlarmData (org.opennms.netmgt.xml.event.AlarmData)14 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)12 ServletException (javax.servlet.ServletException)9 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)9 Parm (org.opennms.netmgt.xml.event.Parm)9 Event (org.opennms.netmgt.xml.eventconf.Event)9 File (java.io.File)8 ArrayList (java.util.ArrayList)8 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)7 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)7 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 SyntaxToEvent (org.opennms.netmgt.model.events.snmp.SyntaxToEvent)7 Transactional (org.springframework.transaction.annotation.Transactional)6