Package org.hornetq.core.cluster

Examples of org.hornetq.core.cluster.DiscoveryGroup


      TransportConfiguration live1 = generateTC();

      bg.addConnector(live1);

      DiscoveryGroup dg = new DiscoveryGroupImpl(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();

      bg.broadcastConnectors();
      boolean ok = dg.waitForBroadcast(1000);
      Assert.assertTrue(ok);

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

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

      bg.broadcastConnectors();
      ok = dg.waitForBroadcast(1000);
      Assert.assertTrue(ok);

      // Won't be called since connectors haven't changed
      Assert.assertFalse(listener1.called);
      Assert.assertFalse(listener2.called);
      Assert.assertFalse(listener3.called);

      bg.stop();

      dg.stop();
   }
View Full Code Here


      bg2.addConnector(live2);

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

      DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
                                                 RandomUtil.randomString(),
                                                 null,
                                                 groupAddress,
                                                 groupPort,
                                                 timeout);

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

      dg.start();

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

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

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

      bg1.broadcastConnectors();
      ok = dg.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      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.broadcastConnectors();
      ok = dg.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      entries = dg.getDiscoveryEntries();
      assertEqualsDiscoveryEntries(Arrays.asList(live1, live2, live3), entries);
      Assert.assertFalse(listener1.called);
      Assert.assertFalse(listener2.called);
      listener1.called = false;
      listener2.called = false;

      bg3.broadcastConnectors();
      ok = dg.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      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);
      bg2.broadcastConnectors();
      ok = dg.waitForBroadcast(1000);
      Assert.assertTrue(ok);

      // 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);

      bg1.broadcastConnectors();
      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);

      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);

      bg1.stop();
      bg2.stop();
      bg3.stop();

      dg.stop();
   }
View Full Code Here

      TransportConfiguration live1 = generateTC();

      bg.addConnector(live1);

      DiscoveryGroup dg1 = new DiscoveryGroupImpl(RandomUtil.randomString(),
                                                  RandomUtil.randomString(),
                                                  null,
                                                  groupAddress,
                                                  groupPort,
                                                  timeout);

      DiscoveryGroup dg2 = new DiscoveryGroupImpl(RandomUtil.randomString(),
                                                  RandomUtil.randomString(),
                                                  null,
                                                  groupAddress,
                                                  groupPort,
                                                  timeout);

      DiscoveryGroup dg3 = new DiscoveryGroupImpl(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();
   }
View Full Code Here

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

      DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
                                                 RandomUtil.randomString(),
                                                 null,
                                                 groupAddress,
                                                 groupPort,
                                                 timeout);
      dg.setNotificationService(notifService);

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

      dg.start();

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

      dg.stop();

      Assert.assertEquals(2, notifListener.getNotifications().size());
      notif = notifListener.getNotifications().get(1);
      Assert.assertEquals(NotificationType.DISCOVERY_GROUP_STOPPED, notif.getType());
      Assert.assertEquals(dg.getName(), notif.getProperties()
                                             .getSimpleStringProperty(new SimpleString("name"))
                                             .toString());
   }
View Full Code Here

      Pair<TransportConfiguration, TransportConfiguration> connectorPair = new Pair<TransportConfiguration, TransportConfiguration>(live1,
                                                                                                                                    backup1);

      bg.addConnectorPair(connectorPair);

      DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
                                                 RandomUtil.randomString(),
                                                 null,
                                                 groupAddress,
                                                 groupPort,
                                                 timeout);

      dg.start();

      bg.broadcastConnectors();

      boolean ok = dg.waitForBroadcast(1000);

      Assert.assertTrue(ok);

      Map<String, DiscoveryEntry> entryMap = dg.getDiscoveryEntryMap();

      Assert.assertNotNull(entryMap);

      Assert.assertEquals(1, entryMap.size());

      DiscoveryEntry entry = entryMap.get(nodeID);

      Assert.assertNotNull(entry);

      Assert.assertEquals(connectorPair, entry.getConnectorPair());

      bg.stop();

      dg.stop();

   }
View Full Code Here

      Pair<TransportConfiguration, TransportConfiguration> connectorPair = new Pair<TransportConfiguration, TransportConfiguration>(live1,
                                                                                                                                    backup1);

      bg.addConnectorPair(connectorPair);

      DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
                                                 RandomUtil.randomString(),
                                                 localAddress,
                                                 groupAddress,
                                                 groupPort,
                                                 timeout);

      dg.start();

      bg.broadcastConnectors();

      boolean ok = dg.waitForBroadcast(1000);

      Assert.assertTrue(ok);

      Map<String, DiscoveryEntry> entryMap = dg.getDiscoveryEntryMap();

      Assert.assertNotNull(entryMap);

      Assert.assertEquals(1, entryMap.size());

      DiscoveryEntry entry = entryMap.get(nodeID);

      Assert.assertNotNull(entry);

      Assert.assertEquals(connectorPair, entry.getConnectorPair());

      bg.stop();

      dg.stop();

   }
View Full Code Here

      Pair<TransportConfiguration, TransportConfiguration> connectorPair = new Pair<TransportConfiguration, TransportConfiguration>(live1,
                                                                                                                                    backup1);

      bg.addConnectorPair(connectorPair);

      DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
                                                 RandomUtil.randomString(),
                                                 null,
                                                 groupAddress,
                                                 groupPort,
                                                 timeout);

      dg.start();

      bg.broadcastConnectors();

      boolean ok = dg.waitForBroadcast(1000);

      Assert.assertTrue(ok);

      Map<String, DiscoveryEntry> entryMap = dg.getDiscoveryEntryMap();

      Assert.assertNotNull(entryMap);

      Assert.assertEquals(1, entryMap.size());

      DiscoveryEntry entry = entryMap.get(nodeID);

      Assert.assertNotNull(entry);

      Assert.assertEquals(connectorPair, entry.getConnectorPair());

      bg.stop();

      dg.stop();

      dg.start();

      bg.start();

      bg.broadcastConnectors();

      ok = dg.waitForBroadcast(1000);

      Assert.assertTrue(ok);

      entryMap = dg.getDiscoveryEntryMap();

      Assert.assertNotNull(entryMap);

      Assert.assertEquals(1, entryMap.size());
View Full Code Here

      Pair<TransportConfiguration, TransportConfiguration> connectorPair = new Pair<TransportConfiguration, TransportConfiguration>(live1,
                                                                                                                                    backup1);

      bg.addConnectorPair(connectorPair);

      DiscoveryGroup dg = new DiscoveryGroupImpl(nodeID, RandomUtil.randomString(), null, groupAddress, groupPort, timeout);

      dg.start();

      bg.broadcastConnectors();

      boolean ok = dg.waitForBroadcast(1000);

      Assert.assertFalse(ok);

      Map<String, DiscoveryEntry> entryMap = dg.getDiscoveryEntryMap();

      Assert.assertNotNull(entryMap);

      Assert.assertEquals(0, entryMap.size());

      bg.stop();

      dg.stop();

   }
View Full Code Here

      bg.addConnectorPair(connectorPair);

      final int port2 = 6746;

      DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
                                                 RandomUtil.randomString(),
                                                 null,
                                                 groupAddress,
                                                 port2,
                                                 timeout);

      dg.start();

      bg.broadcastConnectors();

      boolean ok = dg.waitForBroadcast(1000);

      Assert.assertFalse(ok);

      bg.stop();

      dg.stop();
   }
View Full Code Here

      bg.addConnectorPair(connectorPair);

      final InetAddress groupAddress2 = InetAddress.getByName(DiscoveryTest.address2);
      final int port2 = 6746;

      DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
                                                 RandomUtil.randomString(),
                                                 null,
                                                 groupAddress2,
                                                 port2,
                                                 timeout);

      dg.start();

      bg.broadcastConnectors();

      boolean ok = dg.waitForBroadcast(1000);

      Assert.assertFalse(ok);

      bg.stop();

      dg.stop();
   }
View Full Code Here

TOP

Related Classes of org.hornetq.core.cluster.DiscoveryGroup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.