Search in sources :

Example 1 with EventAnticipator

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());
}
Also used : Event(org.opennms.netmgt.xml.event.Event) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator)

Example 2 with EventAnticipator

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());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetAddress(java.net.InetAddress) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 3 with EventAnticipator

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());
}
Also used : EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test)

Example 4 with EventAnticipator

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());
}
Also used : EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test)

Example 5 with EventAnticipator

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();
}
Also used : IncludeRange(org.opennms.netmgt.config.discovery.IncludeRange) DiscoveryConfiguration(org.opennms.netmgt.config.discovery.DiscoveryConfiguration) Event(org.opennms.netmgt.xml.event.Event) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test)

Aggregations

EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)22 Test (org.junit.Test)18 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)12 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 Event (org.opennms.netmgt.xml.event.Event)7 InetAddress (java.net.InetAddress)6 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)4 Date (java.util.Date)2 DiscoveryConfiguration (org.opennms.netmgt.config.discovery.DiscoveryConfiguration)2 IncludeRange (org.opennms.netmgt.config.discovery.IncludeRange)2 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)2 Parm (org.opennms.netmgt.xml.event.Parm)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 BigInteger (java.math.BigInteger)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Before (org.junit.Before)1 JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)1 DiscoveryConfigFactory (org.opennms.netmgt.config.DiscoveryConfigFactory)1