use of org.apache.activemq.artemis.core.cluster.DiscoveryGroup 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.DiscoveryGroup in project activemq-artemis by apache.
the class DiscoveryStayAliveTest method testDiscoveryRunning.
@Test
public void testDiscoveryRunning() throws Throwable {
final InetAddress groupAddress = InetAddress.getByName(address1);
final int groupPort = getUDPDiscoveryPort();
final int timeout = 500;
final DiscoveryGroup dg = newDiscoveryGroup(RandomUtil.randomString(), RandomUtil.randomString(), InetAddress.getByName("localhost"), groupAddress, groupPort, timeout);
final AtomicInteger errors = new AtomicInteger(0);
Thread t = new Thread() {
@Override
public void run() {
try {
dg.internalRunning();
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
};
t.start();
BroadcastGroupImpl bg = null;
try {
bg = new BroadcastGroupImpl(new FakeNodeManager("test-nodeID"), RandomUtil.randomString(), 1, scheduledExecutorService, new UDPBroadcastEndpointFactory().setGroupAddress(address1).setGroupPort(groupPort));
bg.start();
bg.addConnector(generateTC());
for (int i = 0; i < 10; i++) {
BroadcastEndpointFactory factoryEndpoint = new UDPBroadcastEndpointFactory().setGroupAddress(address1).setGroupPort(groupPort).setLocalBindAddress("localhost");
sendBadData(factoryEndpoint);
}
Thread.sleep(100);
assertTrue(t.isAlive());
assertEquals(0, errors.get());
} finally {
if (bg != null) {
bg.stop();
}
if (dg != null) {
dg.stop();
}
t.join(1000);
// it will retry for a limited time only
for (int i = 0; t.isAlive() && i < 100; i++) {
t.interrupt();
Thread.sleep(100);
}
}
}
Aggregations