コード例 #1
0
  @Test
  public void testNodeGainedServiceWhileNodeDownAndServiceUp() {

    startDaemons();

    MockNode node = m_network.getNode(4);
    MockService svc = m_network.getService(4, "192.168.1.6", "SNMP");

    anticipateDown(node);

    node.bringDown();

    verifyAnticipated(5000);

    resetAnticipated();

    anticipateUp(node);
    anticipateDown(svc, true);

    MockService newSvc = m_network.addService(4, "192.168.1.6", "SMTP");

    m_db.writeService(newSvc);

    Event e = MockEventUtil.createNodeGainedServiceEvent("Test", newSvc);
    m_eventMgr.sendEventToListeners(e);

    sleep(5000);
    System.err.println(m_db.getOutages());

    verifyAnticipated(8000);
  }
コード例 #2
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);
  }