Search in sources :

Example 1 with ReplicationNode

use of com.sleepycat.je.rep.ReplicationNode in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacade method populateExistingRemoteReplicationNodes.

private void populateExistingRemoteReplicationNodes() {
    try {
        ReplicationGroup group = getEnvironment().getGroup();
        Set<ReplicationNode> nodes = new HashSet<>(group.getElectableNodes());
        String localNodeName = getNodeName();
        for (ReplicationNode replicationNode : nodes) {
            String discoveredNodeName = replicationNode.getName();
            if (!discoveredNodeName.equals(localNodeName)) {
                _remoteReplicationNodes.put(replicationNode.getName(), replicationNode);
            }
        }
    } catch (RuntimeException e) {
        // should never happen
        handleDatabaseException("Exception on discovery of existing nodes", e);
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ReplicationGroup(com.sleepycat.je.rep.ReplicationGroup) ReplicationNode(com.sleepycat.je.rep.ReplicationNode) HashSet(java.util.HashSet)

Example 2 with ReplicationNode

use of com.sleepycat.je.rep.ReplicationNode in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacadeTest method testEnvironmentFacadeDetectsRemovalOfRemoteNode.

@Test
public void testEnvironmentFacadeDetectsRemovalOfRemoteNode() throws Exception {
    final String replicaName = TEST_NODE_NAME + "_1";
    final CountDownLatch nodeRemovedLatch = new CountDownLatch(1);
    final CountDownLatch nodeAddedLatch = new CountDownLatch(1);
    final AtomicReference<ReplicationNode> addedNodeRef = new AtomicReference<ReplicationNode>();
    final AtomicReference<ReplicationNode> removedNodeRef = new AtomicReference<ReplicationNode>();
    final CountDownLatch stateLatch = new CountDownLatch(1);
    final AtomicReference<NodeState> stateRef = new AtomicReference<NodeState>();
    ReplicationGroupListener listener = new NoopReplicationGroupListener() {

        @Override
        public void onReplicationNodeAddedToGroup(ReplicationNode node) {
            if (addedNodeRef.compareAndSet(null, node)) {
                nodeAddedLatch.countDown();
            }
        }

        @Override
        public void onReplicationNodeRemovedFromGroup(ReplicationNode node) {
            removedNodeRef.set(node);
            nodeRemovedLatch.countDown();
        }

        @Override
        public void onNodeState(ReplicationNode node, NodeState nodeState) {
            if (replicaName.equals(node.getName())) {
                stateRef.set(nodeState);
                stateLatch.countDown();
            }
        }
    };
    TestStateChangeListener stateChangeListener = new TestStateChangeListener();
    final ReplicatedEnvironmentFacade masterEnvironment = addNode(stateChangeListener, listener);
    assertTrue("Master was not started", stateChangeListener.awaitForStateChange(State.MASTER, _timeout, TimeUnit.SECONDS));
    masterEnvironment.reapplyDesignatedPrimary();
    int replica1Port = _portHelper.getNextAvailable();
    String node1NodeHostPort = "localhost:" + replica1Port;
    masterEnvironment.setPermittedNodes(Arrays.asList(masterEnvironment.getHostPort(), node1NodeHostPort));
    ReplicatedEnvironmentFacade replica = createReplica(replicaName, node1NodeHostPort, new NoopReplicationGroupListener());
    assertTrue("Node should be added", nodeAddedLatch.await(_timeout, TimeUnit.SECONDS));
    ReplicationNode node = addedNodeRef.get();
    assertEquals("Unexpected node name", replicaName, node.getName());
    assertTrue("Node state was not heard", stateLatch.await(_timeout, TimeUnit.SECONDS));
    assertEquals("Unexpected node role", State.REPLICA, stateRef.get().getNodeState());
    assertEquals("Unexpected node name", replicaName, stateRef.get().getNodeName());
    replica.close();
    masterEnvironment.removeNodeFromGroup(node.getName());
    assertTrue("Node deleting is undetected by the environment facade", nodeRemovedLatch.await(_timeout, TimeUnit.SECONDS));
    assertEquals("Unexpected node is deleted", node, removedNodeRef.get());
}
Also used : NodeState(com.sleepycat.je.rep.NodeState) ReplicatedEnvironmentFacade(org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountDownLatch(java.util.concurrent.CountDownLatch) ReplicationNode(com.sleepycat.je.rep.ReplicationNode) Test(org.junit.Test)

Example 3 with ReplicationNode

use of com.sleepycat.je.rep.ReplicationNode in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacadeTest method testReplicationGroupListenerHearsAboutExistingRemoteReplicationNodes.

@Test
public void testReplicationGroupListenerHearsAboutExistingRemoteReplicationNodes() throws Exception {
    ReplicatedEnvironmentFacade master = createMaster();
    String nodeName2 = TEST_NODE_NAME + "_2";
    String host = "localhost";
    int port = _portHelper.getNextAvailable();
    String node2NodeHostPort = host + ":" + port;
    final AtomicInteger invocationCount = new AtomicInteger();
    final CountDownLatch nodeRecoveryLatch = new CountDownLatch(1);
    ReplicationGroupListener listener = new NoopReplicationGroupListener() {

        @Override
        public void onReplicationNodeRecovered(ReplicationNode node) {
            nodeRecoveryLatch.countDown();
            invocationCount.incrementAndGet();
        }
    };
    createReplica(nodeName2, node2NodeHostPort, listener);
    assertEquals("Unexpected number of nodes", (long) 2, (long) master.getNumberOfElectableGroupMembers());
    assertTrue("Listener not fired within timeout", nodeRecoveryLatch.await(_timeout, TimeUnit.SECONDS));
    assertEquals("Unexpected number of listener invocations", (long) 1, (long) invocationCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReplicatedEnvironmentFacade(org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountDownLatch(java.util.concurrent.CountDownLatch) ReplicationNode(com.sleepycat.je.rep.ReplicationNode) Test(org.junit.Test)

Example 4 with ReplicationNode

use of com.sleepycat.je.rep.ReplicationNode in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacadeTest method testMasterHearsRemoteNodeRoles.

@Test
public void testMasterHearsRemoteNodeRoles() throws Exception {
    final String node2Name = TEST_NODE_NAME + "_2";
    final CountDownLatch nodeAddedLatch = new CountDownLatch(1);
    final AtomicReference<ReplicationNode> nodeRef = new AtomicReference<ReplicationNode>();
    final CountDownLatch stateLatch = new CountDownLatch(1);
    final AtomicReference<NodeState> stateRef = new AtomicReference<NodeState>();
    ReplicationGroupListener listener = new NoopReplicationGroupListener() {

        @Override
        public void onReplicationNodeAddedToGroup(ReplicationNode node) {
            nodeRef.set(node);
            nodeAddedLatch.countDown();
        }

        @Override
        public void onNodeState(ReplicationNode node, NodeState nodeState) {
            if (node2Name.equals(node.getName())) {
                stateRef.set(nodeState);
                stateLatch.countDown();
            }
        }
    };
    TestStateChangeListener stateChangeListener = new TestStateChangeListener();
    ReplicatedEnvironmentFacade replicatedEnvironmentFacade = addNode(stateChangeListener, listener);
    assertTrue("Master was not started", stateChangeListener.awaitForStateChange(State.MASTER, _timeout, TimeUnit.SECONDS));
    String node2NodeHostPort = "localhost" + ":" + _portHelper.getNextAvailable();
    replicatedEnvironmentFacade.setPermittedNodes(Arrays.asList(replicatedEnvironmentFacade.getHostPort(), node2NodeHostPort));
    createReplica(node2Name, node2NodeHostPort, new NoopReplicationGroupListener());
    assertEquals("Unexpected number of nodes at start of test", (long) 2, (long) replicatedEnvironmentFacade.getNumberOfElectableGroupMembers());
    assertTrue("Node add not fired within timeout", nodeAddedLatch.await(_timeout, TimeUnit.SECONDS));
    ReplicationNode remoteNode = (ReplicationNode) nodeRef.get();
    assertEquals("Unexpected node name", node2Name, remoteNode.getName());
    assertTrue("Node state not fired within timeout", stateLatch.await(_timeout, TimeUnit.SECONDS));
    assertEquals("Unexpected node state", State.REPLICA, stateRef.get().getNodeState());
}
Also used : NodeState(com.sleepycat.je.rep.NodeState) ReplicatedEnvironmentFacade(org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountDownLatch(java.util.concurrent.CountDownLatch) ReplicationNode(com.sleepycat.je.rep.ReplicationNode) Test(org.junit.Test)

Example 5 with ReplicationNode

use of com.sleepycat.je.rep.ReplicationNode in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacadeTest method testReplicationGroupListenerHearsNodeAdded.

@Test
public void testReplicationGroupListenerHearsNodeAdded() throws Exception {
    final CountDownLatch nodeAddedLatch = new CountDownLatch(1);
    final AtomicInteger invocationCount = new AtomicInteger();
    ReplicationGroupListener listener = new NoopReplicationGroupListener() {

        @Override
        public void onReplicationNodeAddedToGroup(ReplicationNode node) {
            invocationCount.getAndIncrement();
            nodeAddedLatch.countDown();
        }
    };
    TestStateChangeListener stateChangeListener = new TestStateChangeListener();
    ReplicatedEnvironmentFacade replicatedEnvironmentFacade = addNode(stateChangeListener, listener);
    assertTrue("Master was not started", stateChangeListener.awaitForStateChange(State.MASTER, _timeout, TimeUnit.SECONDS));
    assertEquals("Unexpected number of nodes at start of test", (long) 1, (long) replicatedEnvironmentFacade.getNumberOfElectableGroupMembers());
    String node2Name = TEST_NODE_NAME + "_2";
    String node2NodeHostPort = "localhost" + ":" + _portHelper.getNextAvailable();
    replicatedEnvironmentFacade.setPermittedNodes(Arrays.asList(replicatedEnvironmentFacade.getHostPort(), node2NodeHostPort));
    createReplica(node2Name, node2NodeHostPort, new NoopReplicationGroupListener());
    assertTrue("Listener not fired within timeout", nodeAddedLatch.await(_timeout, TimeUnit.SECONDS));
    assertEquals("Unexpected number of nodes", (long) 2, (long) replicatedEnvironmentFacade.getNumberOfElectableGroupMembers());
    assertEquals("Unexpected number of listener invocations", (long) 1, (long) invocationCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReplicatedEnvironmentFacade(org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountDownLatch(java.util.concurrent.CountDownLatch) ReplicationNode(com.sleepycat.je.rep.ReplicationNode) Test(org.junit.Test)

Aggregations

ReplicationNode (com.sleepycat.je.rep.ReplicationNode)9 ReplicatedEnvironmentFacade (org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 Test (org.junit.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 NodeState (com.sleepycat.je.rep.NodeState)2 HashSet (java.util.HashSet)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 DatabaseException (com.sleepycat.je.DatabaseException)1 ReplicationGroup (com.sleepycat.je.rep.ReplicationGroup)1 RemoteReplicationNode (org.apache.qpid.server.model.RemoteReplicationNode)1 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)1 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)1