use of org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl in project activemq-artemis by apache.
the class AutomaticColocatedQuorumVoteTest method testSimpleDistributionOfBackupsMaxBackupsExceeded.
@Test
public void testSimpleDistributionOfBackupsMaxBackupsExceeded() throws Exception {
ActiveMQServer server0 = createServer(0, 1, false);
ActiveMQServer server1 = createServer(1, 0, false);
ActiveMQServer server2 = createServer(2, 0, false);
ActiveMQServer server3 = createServer(3, 0, false);
TransportConfiguration liveConnector0 = getConnectorTransportConfiguration("liveConnector" + 0, 0);
TransportConfiguration liveConnector1 = getConnectorTransportConfiguration("liveConnector" + 1, 1);
TransportConfiguration liveConnector2 = getConnectorTransportConfiguration("liveConnector" + 2, 2);
TransportConfiguration liveConnector3 = getConnectorTransportConfiguration("liveConnector" + 3, 3);
try (ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(liveConnector0)) {
server0.start();
server1.start();
ClientSessionFactory sessionFactory0 = serverLocator.createSessionFactory(liveConnector0);
waitForRemoteBackup(sessionFactory0, 10);
ClientSessionFactory sessionFactory1 = serverLocator.createSessionFactory(liveConnector1);
waitForRemoteBackup(sessionFactory1, 10);
Topology topology = serverLocator.getTopology();
Collection<TopologyMemberImpl> members = topology.getMembers();
Assert.assertEquals(members.size(), 2);
Map<String, ActiveMQServer> backupServers0 = server0.getClusterManager().getHAManager().getBackupServers();
Assert.assertEquals(backupServers0.size(), 1);
Map<String, ActiveMQServer> backupServers1 = server1.getClusterManager().getHAManager().getBackupServers();
Assert.assertEquals(backupServers1.size(), 1);
ActiveMQServer backupServer0 = backupServers0.values().iterator().next();
ActiveMQServer backupServer1 = backupServers1.values().iterator().next();
waitForRemoteBackupSynchronization(backupServer0);
waitForRemoteBackupSynchronization(backupServer1);
Assert.assertEquals(server0.getNodeID(), backupServer1.getNodeID());
Assert.assertEquals(server1.getNodeID(), backupServer0.getNodeID());
server2.start();
// just give server2 time to try both server 0 and 1
ClientSessionFactory sessionFactory2 = serverLocator.createSessionFactory(liveConnector2);
server3.start();
ClientSessionFactory sessionFactory3 = serverLocator.createSessionFactory(liveConnector3);
waitForRemoteBackup(sessionFactory2, 10);
waitForRemoteBackup(sessionFactory3, 10);
Assert.assertEquals(members.size(), 2);
Map<String, ActiveMQServer> backupServers2 = server2.getClusterManager().getHAManager().getBackupServers();
Assert.assertEquals(backupServers2.size(), 1);
Map<String, ActiveMQServer> backupServers3 = server3.getClusterManager().getHAManager().getBackupServers();
Assert.assertEquals(backupServers3.size(), 1);
ActiveMQServer backupServer2 = backupServers2.values().iterator().next();
ActiveMQServer backupServer3 = backupServers3.values().iterator().next();
waitForRemoteBackupSynchronization(backupServer2);
waitForRemoteBackupSynchronization(backupServer3);
Assert.assertEquals(server0.getNodeID(), backupServer1.getNodeID());
Assert.assertEquals(server1.getNodeID(), backupServer0.getNodeID());
Assert.assertEquals(server2.getNodeID(), backupServer3.getNodeID());
Assert.assertEquals(server3.getNodeID(), backupServer2.getNodeID());
} finally {
server0.stop();
server1.stop();
server2.stop();
server3.stop();
}
}
use of org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl in project activemq-artemis by apache.
the class ActiveMQTestBase method waitForTopology.
protected Topology waitForTopology(final ActiveMQServer server, final int liveNodes, final int backupNodes, final long timeout) throws Exception {
logger.debug("waiting for " + liveNodes + " on the topology for server = " + server);
long start = System.currentTimeMillis();
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");
}
Topology topology = server.getClusterManager().getDefaultConnection(null).getTopology();
int liveNodesCount = 0;
int backupNodesCount = 0;
do {
liveNodesCount = 0;
backupNodesCount = 0;
for (TopologyMemberImpl member : topology.getMembers()) {
if (member.getLive() != null) {
liveNodesCount++;
ActiveMQServerLogger.LOGGER.info("Found live server connected to " + server.getNodeID());
}
if (member.getBackup() != null) {
backupNodesCount++;
}
}
if ((liveNodes == -1 || liveNodes == liveNodesCount) && (backupNodes == -1 || backupNodes == backupNodesCount)) {
return topology;
}
Thread.sleep(10);
} while (System.currentTimeMillis() - start < timeout);
String msg = "Timed out waiting for cluster topology of live=" + liveNodes + ",backup=" + backupNodes + " (received live=" + liveNodesCount + ", backup=" + backupNodesCount + ") topology = " + topology.describe() + ")";
ActiveMQServerLogger.LOGGER.error(msg);
throw new Exception(msg);
}
use of org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl in project activemq-artemis by apache.
the class ServerConnectVoteHandler method vote.
@Override
public Vote vote(Vote vote) {
ServerConnectVote serverConnectVote = (ServerConnectVote) vote;
String nodeid = serverConnectVote.getNodeId();
TopologyMemberImpl member = server.getClusterManager().getDefaultConnection(null).getTopology().getMember(nodeid);
if (member != null && member.getLive() != null) {
ActiveMQServerLogger.LOGGER.nodeFoundInClusterTopology(nodeid);
return new ServerConnectVote(nodeid, (Boolean) vote.getVote());
}
ActiveMQServerLogger.LOGGER.nodeNotFoundInClusterTopology(nodeid);
return new ServerConnectVote(nodeid, !((Boolean) vote.getVote()));
}
use of org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl in project activemq-artemis by apache.
the class ClusterConnectionImpl method informClusterOfBackup.
@Override
public synchronized void informClusterOfBackup() {
String nodeID = server.getNodeID().toString();
TopologyMemberImpl localMember = new TopologyMemberImpl(nodeID, null, null, null, connector);
topology.updateAsLive(nodeID, localMember);
}
use of org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl in project activemq-artemis by apache.
the class ClusterConnectionImpl method nodeAnnounced.
@Override
public void nodeAnnounced(final long uniqueEventID, final String nodeID, final String backupGroupName, final String scaleDownGroupName, final Pair<TransportConfiguration, TransportConfiguration> connectorPair, final boolean backup) {
if (logger.isDebugEnabled()) {
logger.debug(this + "::NodeAnnounced, backup=" + backup + nodeID + connectorPair);
}
TransportConfiguration live = connectorPair.getA();
TransportConfiguration backupTC = connectorPair.getB();
TopologyMemberImpl newMember = new TopologyMemberImpl(nodeID, backupGroupName, scaleDownGroupName, live, backupTC);
newMember.setUniqueEventID(uniqueEventID);
if (backup) {
topology.updateBackup(new TopologyMemberImpl(nodeID, backupGroupName, scaleDownGroupName, live, backupTC));
} else {
topology.updateMember(uniqueEventID, nodeID, newMember);
}
}
Aggregations