use of org.apache.qpid.server.model.RemoteReplicationNode in project qpid-broker-j by apache.
the class BDBHAVirtualHostNodeTest method testTransferMasterToRemoteReplica.
public void testTransferMasterToRemoteReplica() throws Exception {
int node1PortNumber = _portHelper.getNextAvailable();
int node2PortNumber = _portHelper.getNextAvailable();
int node3PortNumber = _portHelper.getNextAvailable();
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
String nodeName = "node1";
Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber, node3PortNumber);
BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes);
final AtomicReference<RemoteReplicationNode<?>> lastSeenReplica = new AtomicReference<>();
final CountDownLatch remoteNodeLatch = new CountDownLatch(2);
node1.addChangeListener(new AbstractConfigurationChangeListener() {
@Override
public void childAdded(ConfiguredObject<?> object, ConfiguredObject<?> child) {
if (child instanceof RemoteReplicationNode) {
remoteNodeLatch.countDown();
lastSeenReplica.set((RemoteReplicationNode<?>) child);
}
}
});
Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
BDBHAVirtualHostNode<?> node2 = _helper.createAndStartHaVHN(node2Attributes);
Map<String, Object> node3Attributes = _helper.createNodeAttributes("node3", groupName, "localhost:" + node3PortNumber, helperAddress, nodeName);
BDBHAVirtualHostNode<?> node3 = _helper.createAndStartHaVHN(node3Attributes);
assertTrue("Replication nodes have not been seen during 5s", remoteNodeLatch.await(5, TimeUnit.SECONDS));
BDBHARemoteReplicationNodeImpl replicaRemoteNode = (BDBHARemoteReplicationNodeImpl) lastSeenReplica.get();
_helper.awaitForAttributeChange(replicaRemoteNode, BDBHARemoteReplicationNodeImpl.ROLE, NodeRole.REPLICA);
replicaRemoteNode.setAttributes(Collections.<String, Object>singletonMap(BDBHARemoteReplicationNode.ROLE, NodeRole.MASTER));
BDBHAVirtualHostNode<?> replica = replicaRemoteNode.getName().equals(node2.getName()) ? node2 : node3;
_helper.assertNodeRole(replica, NodeRole.MASTER);
}
Aggregations