org.apache.activemq.artemis.core.cluster.DiscoveryGroup

Here are the examples of the java api class org.apache.activemq.artemis.core.cluster.DiscoveryGroup taken from open source projects.

1. DiscoveryTest#testSimpleBroadcastJGropus()

Project: activemq-artemis
Source File: DiscoveryTest.java
View license
@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);
}

2. ServerLocatorImpl#createDiscoveryGroup()

View license
private static DiscoveryGroup createDiscoveryGroup(String nodeID, DiscoveryGroupConfiguration config) throws Exception {
    DiscoveryGroup group = new DiscoveryGroup(nodeID, config.getName(), config.getRefreshTimeout(), config.getBroadcastEndpointFactory(), null);
    return group;
}

3. DiscoveryStayAliveTest#testDiscoveryRunning()

View license
@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);
        }
    }
}