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