Search in sources :

Example 6 with BroadcastEndpoint

use of org.apache.activemq.artemis.api.core.BroadcastEndpoint in project activemq-artemis by apache.

the class DiscoveryTest method testJGropusChannelReferenceCounting2.

/**
 * Create one broadcaster and 50 receivers. Then stop half of the receivers.
 * Then add the half back, plus some more. Make sure all receivers receive data.
 *
 * @throws Exception
 */
@Test
public void testJGropusChannelReferenceCounting2() throws Exception {
    BroadcastEndpointFactory factory = new JGroupsFileBroadcastEndpointFactory().setChannelName("tst").setFile(TEST_JGROUPS_CONF_FILE);
    BroadcastEndpoint broadcaster = factory.createBroadcastEndpoint();
    broadcaster.openBroadcaster();
    int num = 50;
    BroadcastEndpoint[] receivers = new BroadcastEndpoint[num];
    for (int i = 0; i < num; i++) {
        receivers[i] = factory.createBroadcastEndpoint();
        receivers[i].openClient();
    }
    for (int i = 0; i < num / 2; i++) {
        receivers[i].close(false);
    }
    for (int i = 0; i < num / 2; i++) {
        receivers[i] = factory.createBroadcastEndpoint();
        receivers[i].openClient();
    }
    int num2 = 10;
    BroadcastEndpoint[] moreReceivers = new BroadcastEndpoint[num2];
    for (int i = 0; i < num2; i++) {
        moreReceivers[i] = factory.createBroadcastEndpoint();
        moreReceivers[i].openClient();
    }
    final byte[] data = new byte[] { 1, 2, 3, 4, 5 };
    broadcaster.broadcast(data);
    for (int i = 0; i < num; i++) {
        byte[] received = receivers[i].receiveBroadcast(5000, TimeUnit.MILLISECONDS);
        assertNotNull(received);
        assertEquals(5, received.length);
        assertEquals(1, received[0]);
        assertEquals(2, received[1]);
        assertEquals(3, received[2]);
        assertEquals(4, received[3]);
        assertEquals(5, received[4]);
    }
    for (int i = 0; i < num2; i++) {
        byte[] received = moreReceivers[i].receiveBroadcast(5000, TimeUnit.MILLISECONDS);
        assertNotNull(received);
        assertEquals(5, received.length);
        assertEquals(1, received[0]);
        assertEquals(2, received[1]);
        assertEquals(3, received[2]);
        assertEquals(4, received[3]);
        assertEquals(5, received[4]);
    }
    for (int i = 0; i < num; i++) {
        receivers[i].close(false);
    }
    for (int i = 0; i < num2; i++) {
        moreReceivers[i].close(false);
    }
    broadcaster.close(true);
}
Also used : BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory) Test(org.junit.Test)

Example 7 with BroadcastEndpoint

use of org.apache.activemq.artemis.api.core.BroadcastEndpoint in project activemq-artemis by apache.

the class ConnectionFactoryWithJGroupsSerializationTest method tearDown.

@Override
@After
public void tearDown() throws Exception {
    // small hack, the channel here is cached, so checking that it's not closed by any endpoint
    BroadcastEndpoint broadcastEndpoint = jmsServer.getActiveMQServer().getConfiguration().getDiscoveryGroupConfigurations().get("dg1").getBroadcastEndpointFactory().createBroadcastEndpoint();
    broadcastEndpoint.close(true);
    if (channel != null) {
        assertFalse(channel.isClosed());
        channel.close();
    }
    super.tearDown();
}
Also used : BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) After(org.junit.After)

Example 8 with BroadcastEndpoint

use of org.apache.activemq.artemis.api.core.BroadcastEndpoint in project activemq-artemis by apache.

the class SimpleJNDIClientTest method testRemoteCFWithJgroupsWithTransportConfigFile.

@Test
public void testRemoteCFWithJgroupsWithTransportConfigFile() throws Exception {
    Hashtable<String, String> props = new Hashtable<>();
    props.put(Context.INITIAL_CONTEXT_FACTORY, org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory.class.getCanonicalName());
    props.put("connectionFactory.myConnectionFactory", "jgroups://testChannelName?file=test-jgroups-file_ping.xml&" + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000");
    Context ctx = new InitialContext(props);
    ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
    DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration();
    Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout());
    Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout());
    BroadcastEndpoint broadcastEndpoint = cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory().createBroadcastEndpoint();
    Assert.assertTrue(broadcastEndpoint instanceof JGroupsFileBroadcastEndpoint);
    broadcastEndpoint.close(false);
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) JGroupsFileBroadcastEndpoint(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpoint) BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) Hashtable(java.util.Hashtable) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) JGroupsFileBroadcastEndpoint(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpoint) ActiveMQInitialContextFactory(org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Aggregations

BroadcastEndpoint (org.apache.activemq.artemis.api.core.BroadcastEndpoint)8 Test (org.junit.Test)6 BroadcastEndpointFactory (org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)4 JGroupsFileBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory)4 UDPBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory)3 Hashtable (java.util.Hashtable)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 ChannelBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory)1 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)1 JGroupsFileBroadcastEndpoint (org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpoint)1 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)1 ActiveMQInitialContextFactory (org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory)1 JChannel (org.jgroups.JChannel)1 PlainConfigurator (org.jgroups.conf.PlainConfigurator)1 After (org.junit.After)1