Search in sources :

Example 6 with DiscoveryEntry

use of org.apache.activemq.artemis.core.cluster.DiscoveryEntry in project activemq-artemis by apache.

the class DiscoveryTest method testMultipleGroups.

@Test
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);
}
Also used : DiscoveryEntry(org.apache.activemq.artemis.core.cluster.DiscoveryEntry) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InetAddress(java.net.InetAddress) BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) Test(org.junit.Test)

Example 7 with DiscoveryEntry

use of org.apache.activemq.artemis.core.cluster.DiscoveryEntry in project activemq-artemis by apache.

the class DiscoveryTest method testSimpleBroadcastSpecificNIC.

@Test
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 = InetAddress.getLoopbackAddress();
    log.info("Local address is " + localAddress);
    bg = newBroadcast(nodeID, RandomUtil.randomString(), localAddress, -1, 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);
}
Also used : DiscoveryEntry(org.apache.activemq.artemis.core.cluster.DiscoveryEntry) NetworkInterface(java.net.NetworkInterface) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InetAddress(java.net.InetAddress) BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) Test(org.junit.Test)

Example 8 with DiscoveryEntry

use of org.apache.activemq.artemis.core.cluster.DiscoveryEntry in project activemq-artemis by apache.

the class DiscoveryTest method testConnectorsUpdatedMultipleBroadcasters.

@Test
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);
}
Also used : DiscoveryEntry(org.apache.activemq.artemis.core.cluster.DiscoveryEntry) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InetAddress(java.net.InetAddress) BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) Test(org.junit.Test)

Example 9 with DiscoveryEntry

use of org.apache.activemq.artemis.core.cluster.DiscoveryEntry in project activemq-artemis by apache.

the class DiscoveryTest method testSimpleBroadcast.

@Test
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 UDPBroadcastEndpointFactory().setGroupAddress(address1).setGroupPort(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);
}
Also used : DiscoveryEntry(org.apache.activemq.artemis.core.cluster.DiscoveryEntry) BroadcastGroupImpl(org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InetAddress(java.net.InetAddress) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) Test(org.junit.Test)

Example 10 with DiscoveryEntry

use of org.apache.activemq.artemis.core.cluster.DiscoveryEntry in project activemq-artemis by apache.

the class DiscoveryBaseTest method dump.

protected static void dump(List<TransportConfiguration> sortedExpected, List<DiscoveryEntry> sortedActual) {
    System.out.println("wrong broadcasts received");
    System.out.println("expected");
    System.out.println("----------------------------");
    for (TransportConfiguration transportConfiguration : sortedExpected) {
        System.out.println("transportConfiguration = " + transportConfiguration);
    }
    System.out.println("----------------------------");
    System.out.println("actual");
    System.out.println("----------------------------");
    for (DiscoveryEntry discoveryEntry : sortedActual) {
        System.out.println("transportConfiguration = " + discoveryEntry.getConnector());
    }
    System.out.println("----------------------------");
}
Also used : DiscoveryEntry(org.apache.activemq.artemis.core.cluster.DiscoveryEntry) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Aggregations

TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)10 DiscoveryEntry (org.apache.activemq.artemis.core.cluster.DiscoveryEntry)10 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 Test (org.junit.Test)8 InetAddress (java.net.InetAddress)7 BroadcastEndpoint (org.apache.activemq.artemis.api.core.BroadcastEndpoint)7 BroadcastGroupImpl (org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl)2 NetworkInterface (java.net.NetworkInterface)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 JGroupsFileBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory)1 UDPBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory)1 DiscoveryGroup (org.apache.activemq.artemis.core.cluster.DiscoveryGroup)1