@Override public void visitService(MockService svc) { anticipatePoll(svc); } };
/** * <p>poll</p> * * @return a {@link org.opennms.netmgt.poller.PollStatus} object. */ public PollStatus poll() { m_pollCount++; for (PollAnticipator trigger : m_triggers) { trigger.poll(this); } return getPollStatus(); }
/** * Waits for millis milliseconds for the anticipated polls to come. If they * all come in before the timeout return an empty list. Otherwise return a * read-only list of the services that were anticipated but not received. * * @param millis a long. * @return a {@link java.util.Collection} object. */ public synchronized Collection<MockService> waitForAnticipated(long millis) { long start = System.currentTimeMillis(); long now = start; while ((now - start) < millis) { if (m_anticipatedPolls.isEmpty()) { return new ArrayList<MockService>(0); } waitFor(millis); now = System.currentTimeMillis(); } return Collections.unmodifiableCollection(m_anticipatedPolls); }
public void testWaitForPoll() throws Throwable { final PollAnticipator anticipator = new PollAnticipator(); iface.addAnticipator(anticipator); anticipator.anticipateAllServices(smtpService); anticipator.anticipateAllServices(icmpService); anticipator.anticipateAllServices(iface); assertEquals(0, anticipator.waitForAnticipated(0L).size()); assertEquals(1, anticipator.unanticipatedPolls().size()); anticipator.reset(); anticipator.anticipateAllServices(smtpService); anticipator.anticipateAllServices(icmpService); anticipator.anticipateAllServices(iface); anticipator.anticipateAllServices(icmpService); pollerThread.start(); assertEquals(0, anticipator.waitForAnticipated(3000L).size()); assertEquals(0, anticipator.unanticipatedPolls().size());
@Test public void testPolling() throws Exception { m_pollerConfig.setNodeOutageProcessingEnabled(false); // create a poll anticipator PollAnticipator anticipator = new PollAnticipator(); // register it with the interfaces services MockInterface iface = m_network.getInterface(1, "192.168.1.2"); iface.addAnticipator(anticipator); // // first ensure that polls are working while it is up // // anticipate three polls on all the interfaces services anticipator.anticipateAllServices(iface); anticipator.anticipateAllServices(iface); anticipator.anticipateAllServices(iface); // start the poller startDaemons(); // wait for the polls to occur while its up... 1 poll per second plus overhead assertEquals(0, anticipator.waitForAnticipated(4500L).size()); }
PollAnticipator anticipator = new PollAnticipator(); svc1.addAnticipator(anticipator); anticipator.anticipateAllServices(svc1); for (MockService service : anticipator.waitForAnticipated(10000)) { didNotOccur.append(service.toString()); for (MockService service : anticipator.unanticipatedPolls()) { unanticipatedStuff.append(service.toString());
@Test public void testPolling() throws Exception { m_pollerConfig.setNodeOutageProcessingEnabled(false); // create a poll anticipator PollAnticipator anticipator = new PollAnticipator(); // register it with the interfaces services MockInterface iface = m_network.getInterface(1, "192.168.1.2"); iface.addAnticipator(anticipator); // // first ensure that polls are working while it is up // // anticipate three polls on all the interfaces services anticipator.anticipateAllServices(iface); anticipator.anticipateAllServices(iface); anticipator.anticipateAllServices(iface); // start the poller startDaemons(); // wait for the polls to occur while its up... 1 poll per second plus // overhead assertEquals(0, anticipator.waitForAnticipated(4500L).size()); }
PollAnticipator anticipator = new PollAnticipator(); svc1.addAnticipator(anticipator); anticipator.anticipateAllServices(svc1); for (MockService service : anticipator.waitForAnticipated(10000)) { didNotOccur.append(service.toString()); for (MockService service : anticipator.unanticipatedPolls()) { unanticipatedStuff.append(service.toString());
private void testElementDeleted(MockElement element) { Event deleteEvent = element.createDeleteEvent(); m_pollerConfig.setNodeOutageProcessingEnabled(false); PollAnticipator poll = new PollAnticipator(); element.addAnticipator(poll); poll.anticipateAllServices(element); startDaemons(); // wait til after the first poll of the services poll.waitForAnticipated(1000L); // now delete the node and send a nodeDeleted event m_network.removeElement(element); m_eventMgr.sendEventToListeners(deleteEvent); // reset the poll count and wait to see if any polls on the removed // element happened m_network.resetInvalidPollCount(); // now ensure that no invalid polls have occurred sleep(3000); assertEquals("Received a poll for an element that doesn't exist", 0, m_network.getInvalidPollCount()); }
private void testElementDeleted(MockElement element) { Event deleteEvent = element.createDeleteEvent(); m_pollerConfig.setNodeOutageProcessingEnabled(false); PollAnticipator poll = new PollAnticipator(); element.addAnticipator(poll); poll.anticipateAllServices(element); startDaemons(); // wait til after the first poll of the services poll.waitForAnticipated(1000L); // now delete the node and send a nodeDeleted event m_network.removeElement(element); m_eventMgr.sendEventToListeners(deleteEvent); // reset the poll count and wait to see if any polls on the removed // element happened m_network.resetInvalidPollCount(); // now ensure that no invalid polls have occurred sleep(3000); assertEquals("Received a poll for an element that doesn't exist", 0, m_network.getInvalidPollCount()); }
@Test public void testNodeLabelChanged() { MockNode element = m_network.getNode(1); String newLabel = "NEW LABEL"; Event event = element.createNodeLabelChangedEvent(newLabel); m_pollerConfig.setNodeOutageProcessingEnabled(false); PollAnticipator poll = new PollAnticipator(); element.addAnticipator(poll); poll.anticipateAllServices(element); startDaemons(); // wait until after the first poll of the services poll.waitForAnticipated(1000L); assertEquals("Router", m_poller.getNetwork().getNode(1).getNodeLabel()); element.setLabel(newLabel); m_eventMgr.sendEventToListeners(event); assertEquals(newLabel, m_poller.getNetwork().getNode(1).getNodeLabel()); }
@Test public void testNodeLabelChanged() { MockNode element = m_network.getNode(1); String newLabel = "NEW LABEL"; Event event = element.createNodeLabelChangedEvent(newLabel); m_pollerConfig.setNodeOutageProcessingEnabled(false); PollAnticipator poll = new PollAnticipator(); element.addAnticipator(poll); poll.anticipateAllServices(element); startDaemons(); // wait until after the first poll of the services poll.waitForAnticipated(1000L); assertEquals("Router", m_poller.getNetwork().getNode(1).getNodeLabel()); // now delete the node and send a nodeDeleted event element.setLabel(newLabel); m_eventMgr.sendEventToListeners(event); assertEquals(newLabel, m_poller.getNetwork().getNode(1).getNodeLabel()); }