use of org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl 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.server.cluster.impl.BroadcastGroupImpl 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);
}
}
}
use of org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl in project activemq-artemis by apache.
the class ClusterManager method createBroadcastGroup.
private BroadcastGroup createBroadcastGroup(BroadcastGroupConfiguration config) throws Exception {
BroadcastGroup group = broadcastGroups.get(config.getName());
if (group == null) {
group = new BroadcastGroupImpl(nodeManager, config.getName(), config.getBroadcastPeriod(), scheduledExecutor, config.getEndpointFactory());
for (String connectorInfo : config.getConnectorInfos()) {
TransportConfiguration connector = configuration.getConnectorConfigurations().get(connectorInfo);
if (connector == null) {
logWarnNoConnector(connectorInfo, config.getName());
return null;
}
group.addConnector(connector);
}
}
if (group.size() == 0) {
logWarnNoConnector(config.getConnectorInfos().toString(), group.getName());
return null;
}
broadcastGroups.put(config.getName(), group);
return group;
}
use of org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl 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);
}
Aggregations