Search in sources :

Example 1 with BDBHARemoteReplicationNodeImpl

use of org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHARemoteReplicationNodeImpl in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeTest method testTransferMasterToRemoteReplica.

@Test
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);
}
Also used : BDBHARemoteReplicationNodeImpl(org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHARemoteReplicationNodeImpl) RemoteReplicationNode(org.apache.qpid.server.model.RemoteReplicationNode) BDBHARemoteReplicationNode(org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHARemoteReplicationNode) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 RemoteReplicationNode (org.apache.qpid.server.model.RemoteReplicationNode)1 BDBHARemoteReplicationNode (org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHARemoteReplicationNode)1 BDBHARemoteReplicationNodeImpl (org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHARemoteReplicationNodeImpl)1 Test (org.junit.Test)1