use of org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory in project activemq-artemis by apache.
the class ConnectionFactoryURITest method testJGroupsFileURI.
@Test
public void testJGroupsFileURI() throws Exception {
DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration();
JGroupsFileBroadcastEndpointFactory endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName("channel-name").setFile("channel-file.xml");
discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpointFactory);
ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF);
URI tcp = parser.createSchema("jgroups", connectionFactoryWithHA);
ActiveMQConnectionFactory factory = parser.newObject(tcp, null);
DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration();
Assert.assertNotNull(dgc);
BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory();
Assert.assertNotNull(befc);
Assert.assertTrue(befc instanceof JGroupsFileBroadcastEndpointFactory);
Assert.assertEquals(dgc.getName(), "foo");
Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678);
Assert.assertEquals(dgc.getRefreshTimeout(), 12345);
JGroupsFileBroadcastEndpointFactory fileBroadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) befc;
Assert.assertEquals(fileBroadcastEndpointFactory.getFile(), "channel-file.xml");
Assert.assertEquals(fileBroadcastEndpointFactory.getChannelName(), "channel-name");
BeanUtilsBean bean = new BeanUtilsBean();
checkEquals(bean, connectionFactoryWithHA, factory);
}
use of org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory in project activemq-artemis by apache.
the class ConnectionFactoryURITest method testJGroupsFile.
@Test
public void testJGroupsFile() throws Exception {
ActiveMQConnectionFactory factory = parser.newObject(new URI("jgroups://channel-name?file=/path/to/some/file/channel-file.xml&test=33"), null);
Assert.assertTrue(ActiveMQJMSConnectionFactory.class.getName().equals(factory.getClass().getName()));
JGroupsFileBroadcastEndpointFactory broadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) factory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory();
Assert.assertEquals(broadcastEndpointFactory.getFile(), "/path/to/some/file/channel-file.xml");
Assert.assertEquals(broadcastEndpointFactory.getChannelName(), "channel-name");
}
use of org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory in project activemq-artemis by apache.
the class DiscoveryTest method testStraightSendReceiveJGroups.
@Test
public void testStraightSendReceiveJGroups() throws Exception {
BroadcastEndpoint broadcaster = null;
BroadcastEndpoint client = null;
try {
JGroupsFileBroadcastEndpointFactory endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName("tst").setFile(TEST_JGROUPS_CONF_FILE);
broadcaster = endpointFactory.createBroadcastEndpoint();
broadcaster.openBroadcaster();
client = endpointFactory.createBroadcastEndpoint();
client.openClient();
Thread.sleep(1000);
byte[] randomBytes = "PQP".getBytes();
broadcaster.broadcast(randomBytes);
byte[] btreceived = client.receiveBroadcast(5, TimeUnit.SECONDS);
System.out.println("BTReceived = " + Arrays.toString(btreceived));
assertNotNull(btreceived);
assertEquals(randomBytes.length, btreceived.length);
for (int i = 0; i < randomBytes.length; i++) {
assertEquals(randomBytes[i], btreceived[i]);
}
} finally {
try {
if (broadcaster != null)
broadcaster.close(true);
if (client != null)
client.close(false);
} catch (Exception ignored) {
ignored.printStackTrace();
}
}
}
use of org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory in project activemq-artemis by apache.
the class DiscoveryTest method testJGropusChannelReferenceCounting.
/**
* Create one broadcaster and 100 receivers. Make sure broadcasting works.
* Then stop 99 of the receivers, the last one could still be working.
*
* @throws Exception
*/
@Test
public void testJGropusChannelReferenceCounting() throws Exception {
BroadcastEndpointFactory factory = new JGroupsFileBroadcastEndpointFactory().setChannelName("tst").setFile(TEST_JGROUPS_CONF_FILE);
BroadcastEndpoint broadcaster = factory.createBroadcastEndpoint();
broadcaster.openBroadcaster();
try {
int num = 100;
BroadcastEndpoint[] receivers = new BroadcastEndpoint[num];
for (int i = 0; i < num; i++) {
receivers[i] = factory.createBroadcastEndpoint();
receivers[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 < num - 1; i++) {
receivers[i].close(false);
}
byte[] data1 = receivers[num - 1].receiveBroadcast(5, TimeUnit.SECONDS);
assertNull(data1);
broadcaster.broadcast(data);
data1 = receivers[num - 1].receiveBroadcast(5, TimeUnit.SECONDS);
assertNotNull(data1);
assertEquals(5, data1.length);
assertEquals(1, data1[0]);
assertEquals(2, data1[1]);
assertEquals(3, data1[2]);
assertEquals(4, data1[3]);
assertEquals(5, data1[4]);
receivers[num - 1].close(false);
} finally {
broadcaster.close(true);
}
}
use of org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory 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);
}
Aggregations