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