Пример #1
0
  public void testSimpleBroadcastDifferentPort() throws Exception {
    final InetAddress groupAddress = InetAddress.getByName(getUDPDiscoveryAddress());
    final int groupPort = getUDPDiscoveryPort();
    final int timeout = 500;

    bg =
        newBroadcast(
            RandomUtil.randomString(),
            RandomUtil.randomString(),
            null,
            -1,
            groupAddress,
            groupPort);

    bg.start();

    TransportConfiguration live1 = generateTC();

    bg.addConnector(live1);

    final int port2 = getUDPDiscoveryPort(1);

    dg =
        newDiscoveryGroup(
            RandomUtil.randomString(),
            RandomUtil.randomString(),
            null,
            groupAddress,
            port2,
            timeout);

    dg.start();

    verifyNonBroadcast(bg, dg);
  }
Пример #2
0
  // backup node becomes live
  public synchronized void activate() {
    if (backup) {
      backup = false;

      for (BroadcastGroup broadcastGroup : broadcastGroups.values()) {
        try {
          broadcastGroup.start();
          broadcastGroup.activate();
        } catch (Exception e) {
          log.warn("unable to start broadcast group " + broadcastGroup.getName(), e);
        }
      }

      for (ClusterConnection clusterConnection : clusterConnections.values()) {
        try {
          clusterConnection.activate();
        } catch (Exception e) {
          log.warn("unable to start cluster connection " + clusterConnection.getName(), e);
        }
      }

      for (Bridge bridge : bridges.values()) {
        try {
          bridge.start();
        } catch (Exception e) {
          log.warn("unable to start bridge " + bridge.getName(), e);
        }
      }
    }
  }
Пример #3
0
  public synchronized void start() throws Exception {
    if (started) {
      return;
    }

    for (BroadcastGroup group : broadcastGroups.values()) {
      if (!backup) {
        group.start();
      }
    }

    for (ClusterConnection conn : clusterConnections.values()) {
      conn.start();
      if (backup && configuration.isSharedStore()) {
        conn.informTopology();
        conn.announceBackup();
      }
    }

    for (BridgeConfiguration config : configuration.getBridgeConfigurations()) {
      deployBridge(config, !backup);
    }

    started = true;
  }
Пример #4
0
  public void testIgnoreTrafficFromOwnNode() throws Exception {
    final InetAddress groupAddress = InetAddress.getByName(address1);
    final int groupPort = getUDPDiscoveryPort();
    final int timeout = 500;

    String nodeID = RandomUtil.randomString();

    bg = newBroadcast(nodeID, RandomUtil.randomString(), null, -1, groupAddress, groupPort);

    bg.start();

    TransportConfiguration live1 = generateTC();

    bg.addConnector(live1);

    dg =
        newDiscoveryGroup(
            nodeID, RandomUtil.randomString(), null, groupAddress, groupPort, timeout);

    dg.start();

    verifyNonBroadcast(bg, dg);
    List<DiscoveryEntry> entries = dg.getDiscoveryEntries();

    Assert.assertNotNull(entries);

    Assert.assertEquals(0, entries.size());
  }
Пример #5
0
  public void testSimpleBroadcastJGropus() throws Exception {
    final String nodeID = RandomUtil.randomString();

    bg =
        new BroadcastGroupImpl(
            new FakeNodeManager(nodeID),
            "broadcast",
            100,
            null,
            new JGroupsBroadcastGroupConfiguration("test-jgroups-file_ping.xml", "tst")
                .createBroadcastEndpointFactory());

    bg.start();

    TransportConfiguration live1 = generateTC();

    bg.addConnector(live1);

    dg =
        new DiscoveryGroup(
            nodeID + "1",
            "broadcast",
            5000l,
            new JGroupsBroadcastGroupConfiguration("test-jgroups-file_ping.xml", "tst")
                .createBroadcastEndpointFactory(),
            null);

    dg.start();

    verifyBroadcast(bg, dg);
    List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
  }
Пример #6
0
  public void testDiscoveryListenersCalled() throws Exception {
    final InetAddress groupAddress = InetAddress.getByName(address1);
    final int groupPort = getUDPDiscoveryPort();
    final int timeout = 500;

    String nodeID = RandomUtil.randomString();

    bg = newBroadcast(nodeID, RandomUtil.randomString(), null, -1, groupAddress, groupPort);

    bg.start();

    TransportConfiguration live1 = generateTC();

    bg.addConnector(live1);

    dg =
        newDiscoveryGroup(
            RandomUtil.randomString(),
            RandomUtil.randomString(),
            null,
            groupAddress,
            groupPort,
            timeout);

    MyListener listener1 = new MyListener();
    MyListener listener2 = new MyListener();
    MyListener listener3 = new MyListener();

    dg.registerListener(listener1);
    dg.registerListener(listener2);
    dg.registerListener(listener3);

    dg.start();

    verifyBroadcast(bg, dg);

    Assert.assertTrue(listener1.called);
    Assert.assertTrue(listener2.called);
    Assert.assertTrue(listener3.called);

    listener1.called = false;
    listener2.called = false;
    listener3.called = false;

    verifyBroadcast(bg, dg);

    // Won't be called since connectors haven't changed
    Assert.assertFalse(listener1.called);
    Assert.assertFalse(listener2.called);
    Assert.assertFalse(listener3.called);
  }
Пример #7
0
  public void testSimpleBroadcastWithStopStartDiscoveryGroup() throws Exception {
    final InetAddress groupAddress = InetAddress.getByName(address1);
    final int groupPort = getUDPDiscoveryPort();
    final int timeout = 500;

    final String nodeID = RandomUtil.randomString();

    bg = newBroadcast(nodeID, RandomUtil.randomString(), null, -1, groupAddress, groupPort);

    bg.start();

    TransportConfiguration live1 = generateTC();

    bg.addConnector(live1);

    dg =
        newDiscoveryGroup(
            RandomUtil.randomString(),
            RandomUtil.randomString(),
            null,
            groupAddress,
            groupPort,
            timeout);

    dg.start();

    verifyBroadcast(bg, dg);
    List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);

    bg.stop();

    dg.stop();

    dg.start();

    bg.start();

    verifyBroadcast(bg, dg);
    entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
  }
Пример #8
0
  public void stop() throws Exception {
    synchronized (this) {
      if (!started) {
        return;
      }

      if (clustered) {
        for (BroadcastGroup group : broadcastGroups.values()) {
          group.stop();
          managementService.unregisterBroadcastGroup(group.getName());
        }

        broadcastGroups.clear();

        for (ClusterConnection clusterConnection : clusterConnections.values()) {
          clusterConnection.stop();
          managementService.unregisterCluster(clusterConnection.getName().toString());
        }
      }

      for (Bridge bridge : bridges.values()) {
        bridge.stop();
        managementService.unregisterBridge(bridge.getName().toString());
      }

      bridges.clear();
    }

    for (ServerLocatorInternal clusterLocator : clusterLocators) {
      try {
        clusterLocator.close();
      } catch (Exception e) {
        log.warn(
            "Error closing serverLocator=" + clusterLocator + ", message=" + e.getMessage(), e);
      }
    }
    clusterLocators.clear();
    started = false;

    clearClusterConnections();
  }
Пример #9
0
  public void testBroadcastGroupNotifications() throws Exception {
    SimpleNotificationService notifService = new SimpleNotificationService();
    SimpleNotificationService.Listener notifListener = new SimpleNotificationService.Listener();
    notifService.addNotificationListener(notifListener);

    final InetAddress groupAddress = InetAddress.getByName(address1);
    final int groupPort = getUDPDiscoveryPort();

    bg =
        newBroadcast(
            RandomUtil.randomString(),
            RandomUtil.randomString(),
            null,
            -1,
            groupAddress,
            groupPort);

    bg.setNotificationService(notifService);

    Assert.assertEquals(0, notifListener.getNotifications().size());

    bg.start();

    Assert.assertEquals(1, notifListener.getNotifications().size());
    Notification notif = notifListener.getNotifications().get(0);
    Assert.assertEquals(NotificationType.BROADCAST_GROUP_STARTED, notif.getType());
    Assert.assertEquals(
        bg.getName(),
        notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());

    bg.stop();

    Assert.assertEquals(2, notifListener.getNotifications().size());
    notif = notifListener.getNotifications().get(1);
    Assert.assertEquals(NotificationType.BROADCAST_GROUP_STOPPED, notif.getType());
    Assert.assertEquals(
        bg.getName(),
        notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
  }
Пример #10
0
  public void testSimpleBroadcast() throws Exception {
    final InetAddress groupAddress = InetAddress.getByName(address1);
    final int groupPort = getUDPDiscoveryPort();
    final int timeout = 500;

    final String nodeID = RandomUtil.randomString();

    bg =
        new BroadcastGroupImpl(
            new FakeNodeManager(nodeID),
            RandomUtil.randomString(),
            0,
            null,
            new UDPBroadcastGroupConfiguration(address1, groupPort, null, -1)
                .createBroadcastEndpointFactory());

    bg.start();

    TransportConfiguration live1 = generateTC();

    bg.addConnector(live1);

    dg =
        newDiscoveryGroup(
            RandomUtil.randomString(),
            RandomUtil.randomString(),
            null,
            groupAddress,
            groupPort,
            timeout);

    dg.start();

    verifyBroadcast(bg, dg);

    List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
  }
Пример #11
0
  public void testMultipleDiscoveryGroups() throws Exception {
    final InetAddress groupAddress = InetAddress.getByName(address1);
    final int groupPort = getUDPDiscoveryPort();
    final int timeout = 500;

    String nodeID = RandomUtil.randomString();

    bg = newBroadcast(nodeID, RandomUtil.randomString(), null, -1, groupAddress, groupPort);

    bg.start();

    TransportConfiguration live1 = generateTC();

    bg.addConnector(live1);

    dg1 =
        newDiscoveryGroup(
            RandomUtil.randomString(),
            RandomUtil.randomString(),
            null,
            groupAddress,
            groupPort,
            timeout);

    dg2 =
        newDiscoveryGroup(
            RandomUtil.randomString(),
            RandomUtil.randomString(),
            null,
            groupAddress,
            groupPort,
            timeout);

    dg3 =
        newDiscoveryGroup(
            RandomUtil.randomString(),
            RandomUtil.randomString(),
            null,
            groupAddress,
            groupPort,
            timeout);

    dg1.start();
    dg2.start();
    dg3.start();

    bg.broadcastConnectors();

    boolean ok = dg1.waitForBroadcast(1000);
    Assert.assertTrue(ok);
    List<DiscoveryEntry> entries = dg1.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);

    ok = dg2.waitForBroadcast(1000);
    Assert.assertTrue(ok);
    entries = dg2.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);

    ok = dg3.waitForBroadcast(1000);
    Assert.assertTrue(ok);
    entries = dg3.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);

    bg.stop();

    dg1.stop();
    dg2.stop();
    dg3.stop();
  }
Пример #12
0
  public void testConnectorsUpdatedMultipleBroadcasters() throws Exception {
    final InetAddress groupAddress = InetAddress.getByName(address1);
    final int groupPort = getUDPDiscoveryPort();
    final int timeout = 500;

    String node1 = RandomUtil.randomString();
    String node2 = RandomUtil.randomString();
    String node3 = RandomUtil.randomString();

    bg1 = newBroadcast(node1, RandomUtil.randomString(), null, -1, groupAddress, groupPort);
    bg1.start();

    bg2 = newBroadcast(node2, RandomUtil.randomString(), null, -1, groupAddress, groupPort);
    bg2.start();

    bg3 = newBroadcast(node3, RandomUtil.randomString(), null, -1, groupAddress, groupPort);
    bg3.start();

    TransportConfiguration live1 = generateTC();
    bg1.addConnector(live1);

    TransportConfiguration live2 = generateTC();
    bg2.addConnector(live2);

    TransportConfiguration live3 = generateTC();
    bg3.addConnector(live3);

    dg =
        newDiscoveryGroup(
            RandomUtil.randomString(),
            RandomUtil.randomString(),
            null,
            groupAddress,
            groupPort,
            timeout);

    MyListener listener1 = new MyListener();
    dg.registerListener(listener1);
    MyListener listener2 = new MyListener();
    dg.registerListener(listener2);

    dg.start();

    verifyBroadcast(bg1, dg);
    List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
    Assert.assertTrue(listener1.called);
    Assert.assertTrue(listener2.called);
    listener1.called = false;
    listener2.called = false;

    verifyBroadcast(bg2, dg);
    entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1, live2), entries);
    Assert.assertTrue(listener1.called);
    Assert.assertTrue(listener2.called);
    listener1.called = false;
    listener2.called = false;

    verifyBroadcast(bg3, dg);
    entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1, live2, live3), entries);
    Assert.assertTrue(listener1.called);
    Assert.assertTrue(listener2.called);
    listener1.called = false;
    listener2.called = false;

    verifyBroadcast(bg1, dg);
    entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1, live2, live3), entries);
    Assert.assertFalse(listener1.called);
    Assert.assertFalse(listener2.called);
    listener1.called = false;
    listener2.called = false;

    verifyBroadcast(bg2, dg);
    entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1, live2, live3), entries);
    Assert.assertFalse(listener1.called);
    Assert.assertFalse(listener2.called);
    listener1.called = false;
    listener2.called = false;

    verifyBroadcast(bg3, dg);
    entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1, live2, live3), entries);
    Assert.assertFalse(listener1.called);
    Assert.assertFalse(listener2.called);
    listener1.called = false;
    listener2.called = false;

    bg2.removeConnector(live2);
    verifyBroadcast(bg2, dg);

    // Connector2 should still be there since not timed out yet

    entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1, live2, live3), entries);
    Assert.assertFalse(listener1.called);
    Assert.assertFalse(listener2.called);
    listener1.called = false;
    listener2.called = false;

    Thread.sleep(timeout * 2);

    bg1.broadcastConnectors();
    boolean ok = dg.waitForBroadcast(1000);
    bg2.broadcastConnectors();
    ok = dg.waitForBroadcast(1000);
    bg3.broadcastConnectors();
    ok = dg.waitForBroadcast(1000);

    entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1, live3), entries);
    Assert.assertTrue(listener1.called);
    Assert.assertTrue(listener2.called);
    listener1.called = false;
    listener2.called = false;

    bg1.removeConnector(live1);
    bg3.removeConnector(live3);

    Thread.sleep(timeout * 2);

    bg1.broadcastConnectors();
    ok = dg.waitForBroadcast(1000);
    bg2.broadcastConnectors();
    ok = dg.waitForBroadcast(1000);
    bg3.broadcastConnectors();
    ok = dg.waitForBroadcast(1000);

    entries = dg.getDiscoveryEntries();
    Assert.assertNotNull(entries);
    Assert.assertEquals(0, entries.size());
    Assert.assertTrue(listener1.called);
    Assert.assertTrue(listener2.called);
    listener1.called = false;
    listener2.called = false;

    bg1.broadcastConnectors();
    ok = dg.waitForBroadcast(1000);
    bg2.broadcastConnectors();
    ok = dg.waitForBroadcast(1000);
    bg3.broadcastConnectors();
    ok = dg.waitForBroadcast(1000);

    entries = dg.getDiscoveryEntries();
    Assert.assertNotNull(entries);
    Assert.assertEquals(0, entries.size());
    Assert.assertFalse(listener1.called);
    Assert.assertFalse(listener2.called);
  }
Пример #13
0
 /**
  * @param discoveryGroup
  * @throws Exception
  */
 private static void verifyNonBroadcast(
     BroadcastGroup broadcastGroup, DiscoveryGroup discoveryGroup) throws Exception {
   broadcastGroup.broadcastConnectors();
   Assert.assertFalse("NO broadcast received", discoveryGroup.waitForBroadcast(2000));
 }
Пример #14
0
  public void testMultipleGroups() throws Exception {
    final int groupPort1 = getUDPDiscoveryPort();

    final int groupPort2 = getUDPDiscoveryPort(1);

    final int groupPort3 = getUDPDiscoveryPort(2);

    final InetAddress groupAddress1 = InetAddress.getByName(address1);

    final InetAddress groupAddress2 = InetAddress.getByName(address2);

    final InetAddress groupAddress3 = InetAddress.getByName(address3);

    final int timeout = 5000;

    String node1 = UUIDGenerator.getInstance().generateStringUUID();

    String node2 = UUIDGenerator.getInstance().generateStringUUID();

    String node3 = UUIDGenerator.getInstance().generateStringUUID();

    bg1 = newBroadcast(node1, RandomUtil.randomString(), null, -1, groupAddress1, groupPort1);

    bg2 = newBroadcast(node2, RandomUtil.randomString(), null, -1, groupAddress2, groupPort2);

    bg3 = newBroadcast(node3, RandomUtil.randomString(), null, -1, groupAddress3, groupPort3);

    bg2.start();
    bg1.start();
    bg3.start();

    TransportConfiguration live1 = generateTC("live1");

    TransportConfiguration live2 = generateTC("live2");

    TransportConfiguration live3 = generateTC("live3");

    bg1.addConnector(live1);
    bg2.addConnector(live2);
    bg3.addConnector(live3);

    dg1 =
        newDiscoveryGroup(
            "group-1::" + RandomUtil.randomString(),
            "group-1::" + RandomUtil.randomString(),
            null,
            groupAddress1,
            groupPort1,
            timeout);
    dg1.start();

    dg2 =
        newDiscoveryGroup(
            "group-2::" + RandomUtil.randomString(),
            "group-2::" + RandomUtil.randomString(),
            null,
            groupAddress2,
            groupPort2,
            timeout);
    dg2.start();

    dg3 =
        newDiscoveryGroup(
            "group-3::" + RandomUtil.randomString(),
            "group-3::" + RandomUtil.randomString(),
            null,
            groupAddress3,
            groupPort3,
            timeout);
    dg3.start();

    bg1.broadcastConnectors();

    bg2.broadcastConnectors();

    bg3.broadcastConnectors();

    boolean ok = dg1.waitForBroadcast(timeout);
    Assert.assertTrue(ok);
    List<DiscoveryEntry> entries = dg1.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);

    ok = dg2.waitForBroadcast(timeout);
    Assert.assertTrue(ok);
    entries = dg2.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live2), entries);

    ok = dg3.waitForBroadcast(timeout);
    Assert.assertTrue(ok);
    entries = dg3.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live3), entries);
  }
Пример #15
0
  public void testSimpleBroadcastSpecificNIC() throws Exception {
    final InetAddress groupAddress = InetAddress.getByName(address1);
    final int groupPort = getUDPDiscoveryPort();
    final int timeout = 500;

    final String nodeID = RandomUtil.randomString();

    // We need to choose a real NIC on the local machine - note this will silently pass if the
    // machine
    // has no usable NIC!

    Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();

    InetAddress localAddress = null;

    outer:
    while (networkInterfaces.hasMoreElements()) {
      NetworkInterface networkInterface = networkInterfaces.nextElement();
      if (networkInterface.isLoopback()
          || networkInterface.isVirtual()
          || !networkInterface.isUp()
          || !networkInterface.supportsMulticast()) {
        continue;
      }

      Enumeration<InetAddress> en = networkInterface.getInetAddresses();

      while (en.hasMoreElements()) {
        InetAddress ia = en.nextElement();

        if (ia.getAddress().length == 4) {
          localAddress = ia;

          break outer;
        }
      }
    }

    if (localAddress == null) {
      log.warn("Can't find address to use");

      return;
    }

    log.info("Local address is " + localAddress);

    bg =
        newBroadcast(
            nodeID, RandomUtil.randomString(), localAddress, 6552, groupAddress, groupPort);

    bg.start();

    TransportConfiguration live1 = generateTC();

    bg.addConnector(live1);

    dg =
        newDiscoveryGroup(
            RandomUtil.randomString(),
            RandomUtil.randomString(),
            localAddress,
            groupAddress,
            groupPort,
            timeout);

    dg.start();

    verifyBroadcast(bg, dg);

    List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
  }