use of org.opennms.netmgt.poller.mock.MockScheduler in project opennms by OpenNMS.
the class PollablesIT method setUp.
@Before
public void setUp() throws Exception {
DaoTestConfigBean bean = new DaoTestConfigBean();
bean.afterPropertiesSet();
MockUtil.println("------------ Begin Test --------------------------");
MockLogAppender.setupLogging();
m_lockCount = 0;
m_mockNetwork = new MockNetwork();
m_mockNetwork.addNode(1, "Router");
m_mockNetwork.addInterface("192.168.1.1");
m_mockNetwork.addService("ICMP");
m_mockNetwork.addService("SMTP");
m_mockNetwork.addInterface("192.168.1.2");
m_mockNetwork.addService("ICMP");
m_mockNetwork.addService("SMTP");
m_mockNetwork.addNode(2, "Server");
m_mockNetwork.addInterface("192.168.1.3");
m_mockNetwork.addService("ICMP");
m_mockNetwork.addService("HTTP");
m_mockNetwork.addNode(3, "Firewall");
m_mockNetwork.addInterface("192.168.1.4");
m_mockNetwork.addService("SMTP");
m_mockNetwork.addService("HTTP");
m_mockNetwork.addInterface("192.168.1.5");
m_mockNetwork.addService("SMTP");
m_mockNetwork.addService("SNMP");
m_db = new MockDatabase();
m_db.populate(m_mockNetwork);
m_outageAnticipator = new OutageAnticipator(m_db);
m_eventMgr = new MockEventIpcManager();
m_eventMgr.setEventWriter(m_db);
m_eventMgr.addEventListener(m_outageAnticipator);
m_pollContext = new MockPollContext();
m_pollContext.setDatabase(m_db);
m_pollContext.setCriticalServiceName("ICMP");
m_pollContext.setNodeProcessingEnabled(true);
m_pollContext.setPollingAllIfCritServiceUndefined(true);
m_pollContext.setServiceUnresponsiveEnabled(true);
m_pollContext.setEventMgr(m_eventMgr);
m_pollContext.setMockNetwork(m_mockNetwork);
m_pollerConfig = new MockPollerConfig(m_mockNetwork);
m_pollerConfig.setNodeOutageProcessingEnabled(true);
m_pollerConfig.setCriticalService("ICMP");
m_pollerConfig.addPackage("TestPackage");
m_pollerConfig.addDowntime(100L, 0L, 500L, false);
m_pollerConfig.addDowntime(200L, 500L, 1500L, false);
m_pollerConfig.addDowntime(500L, 1500L, -1L, true);
m_pollerConfig.setDefaultPollInterval(1000L);
m_pollerConfig.populatePackage(m_mockNetwork);
m_pollerConfig.addPackage("TestPkg2");
m_pollerConfig.addDowntime(500L, 0L, 1000L, false);
m_pollerConfig.addDowntime(500L, 1000L, -1L, true);
m_pollerConfig.setDefaultPollInterval(2000L);
m_pollerConfig.addService(m_mockNetwork.getService(2, "192.168.1.3", "HTTP"));
m_timer = new MockTimer();
m_scheduler = new MockScheduler(m_timer);
m_network = createPollableNetwork(m_db, m_scheduler, m_pollerConfig, m_pollerConfig, m_pollContext);
// set members to make the tests easier
mNode1 = m_mockNetwork.getNode(1);
mDot1 = mNode1.getInterface("192.168.1.1");
mDot1Smtp = mDot1.getService("SMTP");
mDot1Icmp = mDot1.getService("ICMP");
mDot2 = mNode1.getInterface("192.168.1.2");
mDot2Icmp = mDot2.getService("ICMP");
mNode2 = m_mockNetwork.getNode(2);
mDot3 = mNode2.getInterface("192.168.1.3");
mDot3Http = mDot3.getService("HTTP");
mNode3 = m_mockNetwork.getNode(3);
mDot4 = mNode3.getInterface("192.168.1.4");
mDot4Smtp = mDot4.getService("SMTP");
mDot4Http = mDot4.getService("HTTP");
assignPollableMembers(m_network);
}
use of org.opennms.netmgt.poller.mock.MockScheduler in project opennms by OpenNMS.
the class ScheduleTest method setUp.
/*
* @see TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
MockLogAppender.setupLogging();
m_schedulable = new MockSchedulable();
m_scheduler = new MockScheduler();
m_interval = new MockInterval(m_scheduler, 1000L);
m_sched = new Schedule(m_schedulable, m_interval, m_scheduler);
}
use of org.opennms.netmgt.poller.mock.MockScheduler in project opennms by OpenNMS.
the class CollectdTest method setUp.
@Before
public void setUp() throws Exception {
EventIpcManager m_eventIpcManager;
NodeDao m_nodeDao;
MockLogAppender.setupLogging();
Resource threshdResource = new ClassPathResource("/etc/thresholds.xml");
File homeDir = threshdResource.getFile().getParentFile().getParentFile();
System.setProperty("opennms.home", homeDir.getAbsolutePath());
// Test setup
m_eventIpcManager = m_easyMockUtils.createMock(EventIpcManager.class);
EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
m_nodeDao = m_easyMockUtils.createMock(NodeDao.class);
m_ipIfDao = m_easyMockUtils.createMock(IpInterfaceDao.class);
m_scheduler = new MockScheduler();
m_eventIpcManager.addEventListener(isA(EventListener.class));
expectLastCall().anyTimes();
m_eventIpcManager.addEventListener(isA(EventListener.class), isACollection(String.class));
expectLastCall().anyTimes();
m_eventIpcManager.addEventListener(isA(EventListener.class), isA(String.class));
expectLastCall().anyTimes();
m_eventIpcManager.removeEventListener(isA(EventListener.class));
expectLastCall().anyTimes();
// Mock the FilterDao without using EasyMockUtils so that it can be verified separately
m_filterDao = EasyMock.createMock(FilterDao.class);
List<InetAddress> allIps = new ArrayList<InetAddress>();
allIps.add(addr("192.168.1.1"));
allIps.add(addr("192.168.1.2"));
allIps.add(addr("192.168.1.3"));
allIps.add(addr("192.168.1.4"));
allIps.add(addr("192.168.1.5"));
expect(m_filterDao.getActiveIPAddressList("IPADDR IPLIKE *.*.*.*")).andReturn(allIps).anyTimes();
expect(m_filterDao.getActiveIPAddressList("IPADDR IPLIKE 1.1.1.1")).andReturn(new ArrayList<InetAddress>(0)).anyTimes();
EasyMock.replay(m_filterDao);
FilterDaoFactory.setInstance(m_filterDao);
// This call will also ensure that the poll-outages.xml file can parse IPv4
// and IPv6 addresses.
Resource resource = new ClassPathResource("etc/poll-outages.xml");
PollOutagesConfigFactory factory = new PollOutagesConfigFactory(resource);
factory.afterPropertiesSet();
PollOutagesConfigFactory.setInstance(factory);
final MockTransactionTemplate transTemplate = new MockTransactionTemplate();
transTemplate.afterPropertiesSet();
m_collectd = new Collectd();
m_collectd.setEventIpcManager(m_eventIpcManager);
m_collectd.setNodeDao(m_nodeDao);
m_collectd.setIpInterfaceDao(m_ipIfDao);
m_collectd.setFilterDao(m_filterDao);
m_collectd.setScheduler(m_scheduler);
m_collectd.setTransactionTemplate(transTemplate);
m_collectd.setPersisterFactory(new MockPersisterFactory());
m_collectd.setServiceCollectorRegistry(new DefaultServiceCollectorRegistry());
m_collectd.setLocationAwareCollectorClient(CollectorTestUtils.createLocationAwareCollectorClient());
ThresholdingConfigFactory.setInstance(new ThresholdingConfigFactory(ConfigurationTestUtils.getInputStreamForConfigFile("thresholds.xml")));
}
Aggregations