Search in sources :

Example 6 with MockPollerConfig

use of org.opennms.netmgt.mock.MockPollerConfig in project opennms by OpenNMS.

the class NotificationsITCase method setUp.

protected void setUp() throws Exception {
    MockUtil.println("################# Running Test ################");
    DaoTestConfigBean bean = new DaoTestConfigBean();
    bean.afterPropertiesSet();
    MockLogAppender.setupLogging();
    m_network = createMockNetwork();
    m_db.populate(m_network);
    DataSourceFactory.setInstance(m_db);
    m_eventMgr = new MockEventIpcManager();
    m_eventMgr.setEventWriter(m_db);
    m_notifdConfig = new MockNotifdConfigManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifd-configuration.xml"));
    m_notifdConfig.setNextNotifIdSql(m_db.getNextNotifIdSql());
    m_notifdConfig.setNextUserNotifIdSql(m_db.getNextUserNotifIdSql());
    m_groupManager = createGroupManager();
    m_userManager = createUserManager(m_groupManager);
    m_destinationPathManager = new MockDestinationPathManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "destination-paths.xml"));
    m_notificationCommandManger = new MockNotificationCommandManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notification-commands.xml"));
    m_notificationManager = new MockNotificationManager(m_notifdConfig, m_db, ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifications.xml"));
    m_pollOutagesConfigManager = new MockPollerConfig(m_network);
    m_anticipator = new NotificationAnticipator();
    MockNotificationStrategy.setAnticipator(m_anticipator);
    m_notifd.setConfigManager(m_notifdConfig);
    m_eventProcessor.setEventManager(m_eventMgr);
    m_eventProcessor.setNotifdConfigManager(m_notifdConfig);
    m_eventProcessor.setGroupManager(m_groupManager);
    m_eventProcessor.setUserManager(m_userManager);
    m_eventProcessor.setDestinationPathManager(m_destinationPathManager);
    m_eventProcessor.setNotificationCommandManager(m_notificationCommandManger);
    m_eventProcessor.setNotificationManager(m_notificationManager);
    m_eventProcessor.setPollOutagesConfigManager(m_pollOutagesConfigManager);
    m_notifd.init();
    m_notifd.start();
    //        Date downDate = new Date();
    //        anticipateNotificationsForGroup("node 2 down.", "All services are down on node 2.", "InitialGroup", downDate, 0);
    //    
    //        //bring node down now
    //        m_eventMgr.sendEventToListeners(m_network.getNode(2).createDownEvent(downDate));
    //    
    //        m_anticipator.waitForAnticipated(2000);
    //        
    //        m_anticipator.reset();
    MockUtil.println("################ Finish Setup ################");
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) MockNotificationManager(org.opennms.netmgt.config.mock.MockNotificationManager) MockDestinationPathManager(org.opennms.netmgt.config.mock.MockDestinationPathManager) MockNotifdConfigManager(org.opennms.netmgt.config.mock.MockNotifdConfigManager) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) NotificationAnticipator(org.opennms.netmgt.mock.NotificationAnticipator) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) MockNotificationCommandManager(org.opennms.netmgt.config.mock.MockNotificationCommandManager)

Example 7 with MockPollerConfig

use of org.opennms.netmgt.mock.MockPollerConfig in project opennms by OpenNMS.

the class LatencyStoringServiceMonitorAdaptorPersistenceTest method persistAndVerifyLatencySamples.

private void persistAndVerifyLatencySamples(String locationName, Path pathToResourceInResponseTime) throws Exception {
    PollStatus pollStatus = PollStatus.get(PollStatus.SERVICE_AVAILABLE, 42.1);
    // For the purposes of this test, it's important the attributes are not added in lexicographical order
    Map<String, Number> props = new LinkedHashMap<String, Number>(pollStatus.getProperties());
    props.put("ping1", Integer.valueOf(1));
    props.put("loss", Integer.valueOf(2));
    props.put("median", Integer.valueOf(3));
    pollStatus.setProperties(props);
    ServiceMonitor serviceMonitor = new FixedServiceMonitor(pollStatus);
    Package pkg = new Package();
    MockNetwork mockNetwork = new MockNetwork();
    mockNetwork.createStandardNetwork();
    MockPollerConfig pollerConfig = new MockPollerConfig(mockNetwork);
    pollerConfig.setRRAList(pkg, Lists.newArrayList("RRA:AVERAGE:0.5:1:2016"));
    LatencyStoringServiceMonitorAdaptor lssma = new LatencyStoringServiceMonitorAdaptor(pollerConfig, pkg, m_persisterFactory, m_resourceStorageDao);
    MonitoredService monitoredService = new MockMonitoredService(3, "Firewall", locationName, InetAddress.getByName("192.168.1.5"), "SMTP");
    Map<String, Object> params = Maps.newHashMap();
    params.put("rrd-repository", getResponseTimeRoot().getAbsolutePath());
    params.put("rrd-base-name", "smtp-base");
    EasyMock.expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".jrb").atLeastOnce();
    m_rrdStrategy.createDefinition(EasyMock.eq("192.168.1.5"), EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime).toString()), EasyMock.eq("smtp-base"), EasyMock.anyInt(), EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall().andReturn(null).once();
    m_rrdStrategy.createFile(EasyMock.anyObject());
    EasyMock.expectLastCall().once();
    m_rrdStrategy.openFile(EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime.resolve("smtp-base.jrb")).toString()));
    EasyMock.expectLastCall().andReturn(null).once();
    // This is the important bit, the order of the values should match the order there were inserted above
    m_rrdStrategy.updateFile(EasyMock.isNull(), EasyMock.eq("192.168.1.5"), EasyMock.endsWith(":42.1:1:2:3"));
    EasyMock.expectLastCall().once();
    EasyMock.replay(m_rrdStrategy);
    // Trigger the poll
    lssma.handlePollResult(monitoredService, params, serviceMonitor.poll(monitoredService, params));
    // Verify
    EasyMock.verify(m_rrdStrategy);
    // Reset
    EasyMock.reset(m_rrdStrategy);
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) LinkedHashMap(java.util.LinkedHashMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) AbstractServiceMonitor(org.opennms.netmgt.poller.support.AbstractServiceMonitor) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Package(org.opennms.netmgt.config.poller.Package)

Aggregations

MockPollerConfig (org.opennms.netmgt.mock.MockPollerConfig)7 MockNetwork (org.opennms.netmgt.mock.MockNetwork)6 Before (org.junit.Before)5 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)5 OutageAnticipator (org.opennms.netmgt.mock.OutageAnticipator)4 LocationAwarePingClient (org.opennms.netmgt.icmp.proxy.LocationAwarePingClient)3 PollableNetwork (org.opennms.netmgt.poller.pollables.PollableNetwork)3 DaoTestConfigBean (org.opennms.test.DaoTestConfigBean)2 LinkedHashMap (java.util.LinkedHashMap)1 MockDatabase (org.opennms.core.test.db.MockDatabase)1 MockDestinationPathManager (org.opennms.netmgt.config.mock.MockDestinationPathManager)1 MockNotifdConfigManager (org.opennms.netmgt.config.mock.MockNotifdConfigManager)1 MockNotificationCommandManager (org.opennms.netmgt.config.mock.MockNotificationCommandManager)1 MockNotificationManager (org.opennms.netmgt.config.mock.MockNotificationManager)1 Package (org.opennms.netmgt.config.poller.Package)1 MockService (org.opennms.netmgt.mock.MockService)1 NotificationAnticipator (org.opennms.netmgt.mock.NotificationAnticipator)1 MonitoredService (org.opennms.netmgt.poller.MonitoredService)1 PollStatus (org.opennms.netmgt.poller.PollStatus)1 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)1