Package org.hornetq.core.cluster

Examples of org.hornetq.core.cluster.DiscoveryGroup


      bg1.addConnectorPair(connectorPair1);
      bg2.addConnectorPair(connectorPair2);
      bg3.addConnectorPair(connectorPair3);

      DiscoveryGroup dg1 = new DiscoveryGroupImpl(RandomUtil.randomString(),
                                                  RandomUtil.randomString(),
                                                  null,
                                                  groupAddress1,
                                                  groupPort1,
                                                  timeout);
      dg1.start();

      DiscoveryGroup dg2 = new DiscoveryGroupImpl(RandomUtil.randomString(),
                                                  RandomUtil.randomString(),
                                                  null,
                                                  groupAddress2,
                                                  groupPort2,
                                                  timeout);
      dg2.start();

      DiscoveryGroup dg3 = new DiscoveryGroupImpl(RandomUtil.randomString(),
                                                  RandomUtil.randomString(),
                                                  null,
                                                  groupAddress3,
                                                  groupPort3,
                                                  timeout);
      dg3.start();

      bg1.broadcastConnectors();

      bg2.broadcastConnectors();

      bg3.broadcastConnectors();

      boolean ok = dg1.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      Map<String, DiscoveryEntry> entryMap = dg1.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(1, entryMap.size());
      DiscoveryEntry entry = entryMap.get(node1);
      Assert.assertNotNull(entry);
      Assert.assertEquals(connectorPair1, entry.getConnectorPair());

      ok = dg2.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      entryMap = dg2.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(1, entryMap.size());
      entry = entryMap.get(node2);
      Assert.assertNotNull(entry);
      Assert.assertEquals(connectorPair2, entry.getConnectorPair());

      ok = dg3.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      entryMap = dg3.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(1, entryMap.size());
      entry = entryMap.get(node3);
      Assert.assertNotNull(entry);
      Assert.assertEquals(connectorPair3, entry.getConnectorPair());

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

      dg1.stop();
      dg2.stop();
      dg3.stop();
   }
View Full Code Here


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

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

      bg.addConnectorPair(connectorPair);

      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

      TransportConfiguration backup3 = generateTC();
      Pair<TransportConfiguration, TransportConfiguration> connectorPair3 = new Pair<TransportConfiguration, TransportConfiguration>(live3,
                                                                                                                                     backup3);
      bg3.addConnectorPair(connectorPair3);

      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);
      Map<String, DiscoveryEntry> entryMap = dg.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(1, entryMap.size());
      DiscoveryEntry entry = entryMap.get(node1);
      Assert.assertNotNull(entry);
      Assert.assertEquals(connectorPair1, entry.getConnectorPair());
      Assert.assertTrue(listener1.called);
      Assert.assertTrue(listener2.called);
      listener1.called = false;
      listener2.called = false;

      bg2.broadcastConnectors();
      ok = dg.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      entryMap = dg.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(2, entryMap.size());
      DiscoveryEntry entry1 = entryMap.get(node1);
      Assert.assertNotNull(entry1);
      Assert.assertEquals(connectorPair1, entry1.getConnectorPair());
      DiscoveryEntry entry2 = entryMap.get(node2);
      Assert.assertNotNull(entry2);
      Assert.assertEquals(connectorPair2, entry2.getConnectorPair());
      Assert.assertTrue(listener1.called);
      Assert.assertTrue(listener2.called);
      listener1.called = false;
      listener2.called = false;

      bg3.broadcastConnectors();
      ok = dg.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      entryMap = dg.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(3, entryMap.size());
      entry1 = entryMap.get(node1);
      Assert.assertNotNull(entry1);
      Assert.assertEquals(connectorPair1, entry1.getConnectorPair());
      entry2 = entryMap.get(node2);
      Assert.assertNotNull(entry2);
      Assert.assertEquals(connectorPair2, entry2.getConnectorPair());
      DiscoveryEntry entry3 = entryMap.get(node3);
      Assert.assertNotNull(entry3);
      Assert.assertEquals(connectorPair3, entry3.getConnectorPair());
      Assert.assertTrue(listener1.called);
      Assert.assertTrue(listener2.called);
      listener1.called = false;
      listener2.called = false;

      bg1.broadcastConnectors();
      ok = dg.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      entryMap = dg.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(3, entryMap.size());
      entry1 = entryMap.get(node1);
      Assert.assertNotNull(entry1);
      Assert.assertEquals(connectorPair1, entry1.getConnectorPair());
      entry2 = entryMap.get(node2);
      Assert.assertNotNull(entry2);
      Assert.assertEquals(connectorPair2, entry2.getConnectorPair());
      entry3 = entryMap.get(node3);
      Assert.assertNotNull(entry3);
      Assert.assertEquals(connectorPair3, entry3.getConnectorPair());
      Assert.assertFalse(listener1.called);
      Assert.assertFalse(listener2.called);
      listener1.called = false;
      listener2.called = false;

      bg2.broadcastConnectors();
      ok = dg.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      entryMap = dg.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(3, entryMap.size());
      entry1 = entryMap.get(node1);
      Assert.assertNotNull(entry1);
      Assert.assertEquals(connectorPair1, entry1.getConnectorPair());
      entry2 = entryMap.get(node2);
      Assert.assertNotNull(entry2);
      Assert.assertEquals(connectorPair2, entry2.getConnectorPair());
      entry3 = entryMap.get(node3);
      Assert.assertNotNull(entry3);
      Assert.assertEquals(connectorPair3, entry3.getConnectorPair());
      Assert.assertFalse(listener1.called);
      Assert.assertFalse(listener2.called);
      listener1.called = false;
      listener2.called = false;

      bg3.broadcastConnectors();
      ok = dg.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      entryMap = dg.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(3, entryMap.size());
      entry1 = entryMap.get(node1);
      Assert.assertNotNull(entry1);
      Assert.assertEquals(connectorPair1, entry1.getConnectorPair());
      entry2 = entryMap.get(node2);
      Assert.assertNotNull(entry2);
      Assert.assertEquals(connectorPair2, entry2.getConnectorPair());
      entry3 = entryMap.get(node3);
      Assert.assertNotNull(entry3);
      Assert.assertEquals(connectorPair3, entry3.getConnectorPair());
      Assert.assertFalse(listener1.called);
      Assert.assertFalse(listener2.called);
      listener1.called = false;
      listener2.called = false;

      bg2.removeConnectorPair(connectorPair2);
      bg2.broadcastConnectors();
      ok = dg.waitForBroadcast(1000);
      Assert.assertTrue(ok);

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

      entryMap = dg.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(3, entryMap.size());
      entry1 = entryMap.get(node1);
      Assert.assertNotNull(entry1);
      Assert.assertEquals(connectorPair1, entry1.getConnectorPair());
      entry2 = entryMap.get(node2);
      Assert.assertNotNull(entry2);
      Assert.assertEquals(connectorPair2, entry2.getConnectorPair());
      entry3 = entryMap.get(node3);
      Assert.assertNotNull(entry3);
      Assert.assertEquals(connectorPair3, entry3.getConnectorPair());

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

      entryMap = dg.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(2, entryMap.size());
      entry1 = entryMap.get(node1);
      Assert.assertNotNull(entry1);
      Assert.assertEquals(connectorPair1, entry1.getConnectorPair());
      entry3 = entryMap.get(node3);
      Assert.assertNotNull(entry3);
      Assert.assertEquals(connectorPair3, entry3.getConnectorPair());

      Assert.assertTrue(listener1.called);
      Assert.assertTrue(listener2.called);
      listener1.called = false;
      listener2.called = false;

      bg1.removeConnectorPair(connectorPair1);
      bg3.removeConnectorPair(connectorPair3);

      Thread.sleep(timeout);

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

      entryMap = dg.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(0, entryMap.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);

      entryMap = dg.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(0, entryMap.size());
      Assert.assertFalse(listener1.called);
      Assert.assertFalse(listener2.called);

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

      dg.stop();
   }
View Full Code Here

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

      bg.addConnectorPair(connectorPair1);

      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);
      Map<String, DiscoveryEntry> entryMap = dg1.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(1, entryMap.size());
      DiscoveryEntry entry = entryMap.get(nodeID);
      Assert.assertNotNull(entry);
      Assert.assertEquals(connectorPair1, entry.getConnectorPair());

      ok = dg2.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      entryMap = dg2.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(1, entryMap.size());
      entry = entryMap.get(nodeID);
      Assert.assertNotNull(entry);
      Assert.assertEquals(connectorPair1, entry.getConnectorPair());

      ok = dg3.waitForBroadcast(1000);
      Assert.assertTrue(ok);
      entryMap = dg3.getDiscoveryEntryMap();
      Assert.assertNotNull(entryMap);
      Assert.assertEquals(1, entryMap.size());
      entry = entryMap.get(nodeID);
      Assert.assertNotNull(entry);
      Assert.assertEquals(connectorPair1, entry.getConnectorPair());

      bg.stop();

      dg1.stop();
      dg2.stop();
      dg3.stop();
   }
View Full Code Here

      final InetAddress groupAddress = InetAddress.getByName(DiscoveryTest.address1);
      final int groupPort = 6745;
      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

      }
   }

   private static DiscoveryGroup createDiscoveryGroup(String nodeID, DiscoveryGroupConfiguration config) throws Exception
   {
      DiscoveryGroup group = new DiscoveryGroup(nodeID, config.getName(),
            config.getRefreshTimeout(), config.getBroadcastEndpointFactoryConfiguration().createBroadcastEndpointFactory(), null);
      return group;
   }
View Full Code Here

      TransportConfiguration live1 = generateTC();

      bg.addConnector(live1);

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

      dg.start();

      bg.broadcastConnectors();

      boolean ok = dg.waitForBroadcast(1000);

      Assert.assertTrue(ok);

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

      bg.stop();

      dg.stop();

      dg.start();

      bg.start();

      bg.broadcastConnectors();

      ok = dg.waitForBroadcast(1000);

      Assert.assertTrue(ok);

      entries = dg.getDiscoveryEntries();
      assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);

      dg.stop();

      bg.stop();
   }
View Full Code Here

      TransportConfiguration live1 = generateTC();

      bg.addConnector(live1);

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

      dg.start();

      bg.broadcastConnectors();

      boolean ok = dg.waitForBroadcast(1000);

      Assert.assertFalse(ok);

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

      Assert.assertNotNull(entries);

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

      bg.stop();

      dg.stop();

   }
View Full Code Here

      bg.addConnector(live1);

      final int port2 = getUDPDiscoveryPort(1);

      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

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.