use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.
the class ClusteredBridgeReconnectTest method testReconnectBridge.
@Test
public void testReconnectBridge() throws Exception {
setupServer(0, isFileStorage(), isNetty());
setupServer(1, isFileStorage(), isNetty());
setupClusterConnection("cluster0", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1);
setupClusterConnection("cluster1", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0);
startServers(0, 1);
setupSessionFactory(0, isNetty());
setupSessionFactory(1, isNetty());
createQueue(0, "queues.testaddress", "queue0", null, true);
createQueue(1, "queues.testaddress", "queue0", null, true);
addConsumer(0, 0, "queue0", null);
addConsumer(1, 1, "queue0", null);
waitForBindings(0, "queues.testaddress", 1, 1, true);
waitForBindings(1, "queues.testaddress", 1, 1, true);
waitForBindings(0, "queues.testaddress", 1, 1, false);
waitForBindings(1, "queues.testaddress", 1, 1, false);
ClientSession session0 = sfs[0].createSession();
ClientSession session1 = sfs[0].createSession();
session0.start();
session1.start();
ClientProducer producer = session0.createProducer("queues.testaddress");
int NUMBER_OF_MESSAGES = 100;
Assert.assertEquals(1, servers[0].getClusterManager().getClusterConnections().size());
ClusterConnectionImpl connection = servers[0].getClusterManager().getClusterConnections().toArray(new ClusterConnectionImpl[0])[0];
Assert.assertEquals(1, connection.getRecords().size());
MessageFlowRecord record = connection.getRecords().values().toArray(new MessageFlowRecord[1])[0];
ClusterConnectionBridge bridge = (ClusterConnectionBridge) record.getBridge();
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
ClientMessage msg = session0.createMessage(true);
producer.send(msg);
session0.commit();
if (i == 17) {
bridge.getSessionFactory().getConnection().fail(new ActiveMQException("failed once!"));
}
}
int cons0Count = 0, cons1Count = 0;
while (true) {
ClientMessage msg = consumers[0].getConsumer().receive(1000);
if (msg == null) {
break;
}
cons0Count++;
msg.acknowledge();
session0.commit();
}
while (true) {
ClientMessage msg = consumers[1].getConsumer().receive(1000);
if (msg == null) {
break;
}
cons1Count++;
msg.acknowledge();
session1.commit();
}
Assert.assertEquals("cons0 = " + cons0Count + ", cons1 = " + cons1Count, NUMBER_OF_MESSAGES, cons0Count + cons1Count);
session0.commit();
session1.commit();
connection = servers[0].getClusterManager().getClusterConnections().toArray(new ClusterConnectionImpl[0])[0];
Assert.assertEquals(1, connection.getRecords().size());
Assert.assertNotNull(bridge.getSessionFactory());
stopServers(0, 1);
}
use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.
the class ClusterConnectionImpl method stop.
@Override
public void stop() throws Exception {
if (!started) {
return;
}
stopping = true;
if (logger.isDebugEnabled()) {
logger.debug(this + "::stopping ClusterConnection");
}
if (serverLocator != null) {
serverLocator.removeClusterTopologyListener(this);
}
logger.debug("Cluster connection being stopped for node" + nodeManager.getNodeId() + ", server = " + this.server + " serverLocator = " + serverLocator);
synchronized (this) {
for (MessageFlowRecord record : records.values()) {
try {
record.close();
} catch (Exception ignore) {
}
}
}
if (managementService != null) {
TypedProperties props = new TypedProperties();
props.putSimpleStringProperty(new SimpleString("name"), name);
Notification notification = new Notification(nodeManager.getNodeId().toString(), CoreNotificationType.CLUSTER_CONNECTION_STOPPED, props);
managementService.sendNotification(notification);
}
executor.execute(new Runnable() {
@Override
public void run() {
synchronized (ClusterConnectionImpl.this) {
closeLocator(serverLocator);
serverLocator = null;
}
}
});
started = false;
}
use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.
the class ClusterConnectionImpl method removeRecord.
@Override
public void removeRecord(String targetNodeID) {
logger.debug("Removing record for: " + targetNodeID);
MessageFlowRecord record = records.remove(targetNodeID);
try {
if (record != null) {
record.close();
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToRemoveRecord(e);
}
}
use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.
the class ClusterConnectionConfigTest method makeSureForwardingFlowControl.
private void makeSureForwardingFlowControl(int producerWindow, int... indices) throws NoSuchFieldException, IllegalAccessException {
for (int i : indices) {
ClusterConnectionImpl cc = (ClusterConnectionImpl) servers[i].getClusterManager().getClusterConnection("cluster" + i);
Map<String, MessageFlowRecord> map = cc.getRecords();
assertEquals(1, map.size());
MessageFlowRecord record = map.entrySet().iterator().next().getValue();
// NoSuchFieldException
Field f = record.getClass().getDeclaredField("targetLocator");
f.setAccessible(true);
ServerLocatorInternal targetLocator = (ServerLocatorInternal) f.get(record);
assertEquals(producerWindow, targetLocator.getProducerWindowSize());
}
}
use of org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord in project activemq-artemis by apache.
the class OneWayChainClusterTest method testChainClusterConnections.
@Test
public void testChainClusterConnections() throws Exception {
setupClusterConnection("cluster0-1", 0, 1, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
setupClusterConnection("cluster1-2", 1, 2, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
setupClusterConnection("cluster2-3", 2, 3, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
setupClusterConnection("cluster3-4", 3, 4, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
setupClusterConnection("cluster4-X", 4, -1, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
startServers(0, 1, 2, 3, 4);
Set<ClusterConnection> connectionSet = getServer(0).getClusterManager().getClusterConnections();
assertNotNull(connectionSet);
assertEquals(1, connectionSet.size());
ClusterConnectionImpl ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
long timeout = System.currentTimeMillis() + 5000;
Map<String, MessageFlowRecord> records = null;
while (timeout > System.currentTimeMillis()) {
records = ccon.getRecords();
if (records != null && records.size() == 1) {
break;
}
}
assertNotNull(records);
assertEquals(records.size(), 1);
getServer(1).getClusterManager().getClusterConnections();
assertNotNull(connectionSet);
assertEquals(1, connectionSet.size());
ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
records = ccon.getRecords();
assertNotNull(records);
assertEquals(records.size(), 1);
getServer(2).getClusterManager().getClusterConnections();
assertNotNull(connectionSet);
assertEquals(1, connectionSet.size());
ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
records = ccon.getRecords();
assertNotNull(records);
assertEquals(records.size(), 1);
getServer(3).getClusterManager().getClusterConnections();
assertNotNull(connectionSet);
assertEquals(1, connectionSet.size());
ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
records = ccon.getRecords();
assertNotNull(records);
assertEquals(records.size(), 1);
getServer(4).getClusterManager().getClusterConnections();
assertNotNull(connectionSet);
assertEquals(1, connectionSet.size());
ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
records = ccon.getRecords();
assertNotNull(records);
assertEquals(records.size(), 1);
}
Aggregations