コード例 #1
0
  @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());
  }
コード例 #2
0
  // Test harness that tests any type of node, interface or element.
  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());
  }
コード例 #3
0
  // nodeLabelChanged: EventConstants.NODE_LABEL_CHANGED_EVENT_UEI
  @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());
  }
コード例 #4
0
  private void testSendNodeGainedServices(
      int nodeid, String nodeLabel, String ipAddr, String... svcNames) {
    assertNotNull(svcNames);
    assertTrue(svcNames.length > 0);

    MockNode node = m_network.addNode(nodeid, nodeLabel);
    m_db.writeNode(node);
    MockInterface iface = m_network.addInterface(nodeid, ipAddr);
    m_db.writeInterface(iface);

    List<MockService> services = new ArrayList<MockService>();
    for (String svcName : svcNames) {
      MockService svc = m_network.addService(nodeid, ipAddr, svcName);
      m_db.writeService(svc);
      m_pollerConfig.addService(svc);
      services.add(svc);
    }

    MockVisitor gainSvcSender =
        new MockVisitorAdapter() {
          public void visitService(MockService svc) {
            Event event = MockEventUtil.createNodeGainedServiceEvent("Test", svc);
            m_eventMgr.sendEventToListeners(event);
          }
        };
    node.visit(gainSvcSender);

    MockService svc1 = services.get(0);

    PollAnticipator anticipator = new PollAnticipator();
    svc1.addAnticipator(anticipator);

    anticipator.anticipateAllServices(svc1);

    StringBuffer didNotOccur = new StringBuffer();
    for (MockService service : anticipator.waitForAnticipated(10000)) {
      didNotOccur.append(service.toString());
    }
    StringBuffer unanticipatedStuff = new StringBuffer();
    for (MockService service : anticipator.unanticipatedPolls()) {
      unanticipatedStuff.append(service.toString());
    }

    assertEquals(unanticipatedStuff.toString(), "", didNotOccur.toString());

    anticipateDown(svc1);

    svc1.bringDown();

    verifyAnticipated(10000);
  }