Search in sources :

Example 1 with DiscoveryEntry

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

the class DiscoveryTest method testSimpleBroadcastJGropus.

@Test
public void testSimpleBroadcastJGropus() throws Exception {
    final String nodeID = RandomUtil.randomString();
    bg = new BroadcastGroupImpl(new FakeNodeManager(nodeID), "broadcast", 100, null, new JGroupsFileBroadcastEndpointFactory().setChannelName("tst").setFile(TEST_JGROUPS_CONF_FILE));
    bg.start();
    TransportConfiguration live1 = generateTC();
    bg.addConnector(live1);
    dg = new DiscoveryGroup(nodeID + "1", "broadcast", 5000L, new JGroupsFileBroadcastEndpointFactory().setChannelName("tst").setFile(TEST_JGROUPS_CONF_FILE), null);
    dg.start();
    verifyBroadcast(bg, dg);
    List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
}
Also used : DiscoveryGroup(org.apache.activemq.artemis.core.cluster.DiscoveryGroup) DiscoveryEntry(org.apache.activemq.artemis.core.cluster.DiscoveryEntry) BroadcastGroupImpl(org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 2 with DiscoveryEntry

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

the class DiscoveryTest method testSimpleBroadcastWithStopStartDiscoveryGroup.

@Test
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);
}
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 3 with DiscoveryEntry

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

the class DiscoveryTest method testIgnoreTrafficFromOwnNode.

@Test
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());
}
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 4 with DiscoveryEntry

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

the class ServerLocatorImpl method connectorsChanged.

@Override
public synchronized void connectorsChanged(List<DiscoveryEntry> newConnectors) {
    if (receivedTopology) {
        return;
    }
    TransportConfiguration[] newInitialconnectors = (TransportConfiguration[]) Array.newInstance(TransportConfiguration.class, newConnectors.size());
    int count = 0;
    for (DiscoveryEntry entry : newConnectors) {
        newInitialconnectors[count++] = entry.getConnector();
        if (ha && topology.getMember(entry.getNodeID()) == null) {
            TopologyMemberImpl member = new TopologyMemberImpl(entry.getNodeID(), null, null, entry.getConnector(), null);
            // on this case we set it as zero as any update coming from server should be accepted
            topology.updateMember(0, entry.getNodeID(), member);
        }
    }
    this.initialConnectors = newInitialconnectors.length == 0 ? null : newInitialconnectors;
    if (clusterConnection && !receivedTopology && this.getNumInitialConnectors() > 0) {
        // The node is alone in the cluster. We create a connection to the new node
        // to trigger the node notification to form the cluster.
        Runnable connectRunnable = new Runnable() {

            @Override
            public void run() {
                try {
                    connect();
                } catch (ActiveMQException e) {
                    ActiveMQClientLogger.LOGGER.errorConnectingToNodes(e);
                }
            }
        };
        if (startExecutor != null) {
            startExecutor.execute(connectRunnable);
        } else {
            connectRunnable.run();
        }
    }
}
Also used : DiscoveryEntry(org.apache.activemq.artemis.core.cluster.DiscoveryEntry) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Example 5 with DiscoveryEntry

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

the class DiscoveryTest method testMultipleDiscoveryGroups.

@Test
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();
}
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)

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