Esempio n. 1
0
  public void register(String zoodiscoveryServerIp)
      throws ContainerCreateException, ContainerConnectException {
    IContainerFactory containerFactory = ContainerFactory.getDefault();
    containerFactory.createContainer(DEFAULT_CONTAINER_TYPE);

    zooContainer = containerFactory.createContainer("ecf.discovery.zoodiscovery");

    if (zooContainer.getConnectedID() == null) {
      ID target =
          zooContainer
              .getConnectNamespace()
              .createInstance(
                  new String[] {"zoodiscovery.flavor.centralized=" + zoodiscoveryServerIp});
      zooContainer.connect(target, null);
      logger.info("ZooDiscovery connected");
    } else {
      logger.warn(
          "ZooDiscovery already connected: " + zooContainer.getConnectedID().toExternalForm());
    }
  }
  protected void addServiceListener(TestServiceListener serviceListener) {
    discoveryLocator.addServiceListener(serviceListener);
    addListenerRegisterAndWait(serviceListener, serviceInfo);
    discoveryLocator.removeServiceListener(serviceListener);

    // make sure we use a live container;
    final IContainer ic = (IContainer) serviceListener.getLocator();
    assertTrue(ic.getConnectedID() != null);

    // check if we received correct amount of events
    final IContainerEvent[] events = serviceListener.getEvent();
    assertNotNull("Test listener didn't receive any discovery events.", events);
    assertEquals(
        "Test listener received unexpected amount of discovery events: \n\t"
            + Arrays.asList(events),
        eventsToExpect,
        events.length);

    final List origContainers = new ArrayList();
    for (int i = 0; i < events.length; i++) {
      final CompositeServiceContainerEvent event = (CompositeServiceContainerEvent) events[i];

      // check if the local container is hidden correctly
      final ID localContainerId = event.getLocalContainerID();
      final ID connectedId = container.getConnectedID();
      assertEquals(localContainerId, connectedId);

      // check the IServiceInfo for correct fields/properties
      final IServiceInfo serviceInfo2 = ((IServiceEvent) event).getServiceInfo();
      assertTrue(
          "IServiceInfo should match, expected:\n\t" + serviceInfo + " but was \n\t" + serviceInfo2,
          comparator.compare(serviceInfo2, serviceInfo) == 0);

      // add the underlying discovery container the the result set
      origContainers.add(event.getOriginalLocalContainerID());
    }
    // check that all underlying containers fired an event
    assertEquals(
        "A nested container didn't send an event, but another multiple.",
        eventsToExpect,
        origContainers.size());
  }