use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl in project activemq-artemis by apache.
the class ClusteredBridgeReconnectTest method testReconnectBridge.
@Test
@BMRules(rules = { @BMRule(name = "enter", targetClass = "org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl", targetMethod = "connect", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.ClusteredBridgeReconnectTest.enterConnect();"), @BMRule(name = "exit", targetClass = "org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl", targetMethod = "connect", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.ClusteredBridgeReconnectTest.exitConnect();"), @BMRule(name = "send", targetClass = "org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl", targetMethod = "send(org.apache.activemq.artemis.core.protocol.core.Packet)", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.ClusteredBridgeReconnectTest.send();") })
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) {
shouldFail = true;
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();
stopServers(0, 1);
}
use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl 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.impl.ClusterConnectionImpl in project activemq-artemis by apache.
the class ClusterTestBase method waitForFailoverTopology.
protected void waitForFailoverTopology(final int bNode, final int... nodes) throws Exception {
ActiveMQServer server = servers[bNode];
log.debug("waiting for " + Arrays.toString(nodes) + " on the topology for server = " + server);
long start = System.currentTimeMillis();
final int waitMillis = 2000;
final int sleepTime = 50;
int nWaits = 0;
while (server.getClusterManager() == null && nWaits++ < waitMillis / sleepTime) {
Thread.sleep(sleepTime);
}
Set<ClusterConnection> ccs = server.getClusterManager().getClusterConnections();
if (ccs.size() != 1) {
throw new IllegalStateException("You need a single cluster connection on this version of waitForTopology on ServiceTestBase");
}
boolean exists = false;
for (int node : nodes) {
ClusterConnectionImpl clusterConnection = (ClusterConnectionImpl) ccs.iterator().next();
Topology topology = clusterConnection.getTopology();
TransportConfiguration nodeConnector = servers[node].getClusterManager().getClusterConnections().iterator().next().getConnector();
do {
Collection<TopologyMemberImpl> members = topology.getMembers();
for (TopologyMemberImpl member : members) {
if (member.getConnector().getA() != null && member.getConnector().getA().equals(nodeConnector)) {
exists = true;
break;
}
}
if (exists) {
break;
}
Thread.sleep(10);
} while (System.currentTimeMillis() - start < WAIT_TIMEOUT);
if (!exists) {
String msg = "Timed out waiting for cluster topology of " + Arrays.toString(nodes) + " (received " + topology.getMembers().size() + ") topology = " + topology + ")";
log.error(msg);
logTopologyDiagram();
throw new Exception(msg);
}
}
}
use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl in project activemq-artemis by apache.
the class ClusterManager method deployClusterConnection.
private void deployClusterConnection(final ClusterConnectionConfiguration config) throws Exception {
if (!config.validateConfiguration()) {
return;
}
TransportConfiguration connector = config.getTransportConfiguration(configuration);
if (connector == null) {
return;
}
if (clusterConnections.containsKey(config.getName())) {
ActiveMQServerLogger.LOGGER.clusterConnectionAlreadyExists(config.getConnectorName());
return;
}
ClusterConnectionImpl clusterConnection;
if (config.getDiscoveryGroupName() != null) {
DiscoveryGroupConfiguration dg = config.getDiscoveryGroupConfiguration(configuration);
if (dg == null)
return;
if (logger.isDebugEnabled()) {
logger.debug(this + " Starting a Discovery Group Cluster Connection, name=" + config.getDiscoveryGroupName() + ", dg=" + dg);
}
clusterConnection = new ClusterConnectionImpl(this, dg, connector, new SimpleString(config.getName()), new SimpleString(config.getAddress() != null ? config.getAddress() : ""), config.getMinLargeMessageSize(), config.getClientFailureCheckPeriod(), config.getConnectionTTL(), config.getRetryInterval(), config.getRetryIntervalMultiplier(), config.getMaxRetryInterval(), config.getInitialConnectAttempts(), config.getReconnectAttempts(), config.getCallTimeout(), config.getCallFailoverTimeout(), config.isDuplicateDetection(), config.getMessageLoadBalancingType(), config.getConfirmationWindowSize(), config.getProducerWindowSize(), executorFactory, server, postOffice, managementService, scheduledExecutor, config.getMaxHops(), nodeManager, server.getConfiguration().getClusterUser(), server.getConfiguration().getClusterPassword(), config.isAllowDirectConnectionsOnly(), config.getClusterNotificationInterval(), config.getClusterNotificationAttempts());
clusterController.addClusterConnection(clusterConnection.getName(), dg, config);
} else {
TransportConfiguration[] tcConfigs = config.getTransportConfigurations(configuration);
if (logger.isDebugEnabled()) {
logger.debug(this + " defining cluster connection towards " + Arrays.toString(tcConfigs));
}
clusterConnection = new ClusterConnectionImpl(this, tcConfigs, connector, new SimpleString(config.getName()), new SimpleString(config.getAddress()), config.getMinLargeMessageSize(), config.getClientFailureCheckPeriod(), config.getConnectionTTL(), config.getRetryInterval(), config.getRetryIntervalMultiplier(), config.getMaxRetryInterval(), config.getInitialConnectAttempts(), config.getReconnectAttempts(), config.getCallTimeout(), config.getCallFailoverTimeout(), config.isDuplicateDetection(), config.getMessageLoadBalancingType(), config.getConfirmationWindowSize(), config.getProducerWindowSize(), executorFactory, server, postOffice, managementService, scheduledExecutor, config.getMaxHops(), nodeManager, server.getConfiguration().getClusterUser(), server.getConfiguration().getClusterPassword(), config.isAllowDirectConnectionsOnly(), config.getClusterNotificationInterval(), config.getClusterNotificationAttempts());
clusterController.addClusterConnection(clusterConnection.getName(), tcConfigs, config);
}
if (defaultClusterConnection == null) {
defaultClusterConnection = clusterConnection;
clusterController.setDefaultClusterConnectionName(defaultClusterConnection.getName());
}
managementService.registerCluster(clusterConnection, config);
clusterConnections.put(config.getName(), clusterConnection);
if (logger.isTraceEnabled()) {
logger.trace("ClusterConnection.start at " + clusterConnection, new Exception("trace"));
}
}
use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl 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());
}
}
Aggregations