Search in sources :

Example 6 with ReplicationNode

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

the class ReplicatedEnvironmentFacadeTest method testReplicationGroupListenerHearsNodeAdded.

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", 1, 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", 2, replicatedEnvironmentFacade.getNumberOfElectableGroupMembers());
    assertEquals("Unexpected number of listener invocations", 1, invocationCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) ReplicationNode(com.sleepycat.je.rep.ReplicationNode)

Example 7 with ReplicationNode

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

the class ReplicatedEnvironmentFacadeTest method testReplicationGroupListenerHearsNodeRemoved.

public void testReplicationGroupListenerHearsNodeRemoved() throws Exception {
    final CountDownLatch nodeDeletedLatch = new CountDownLatch(1);
    final CountDownLatch nodeAddedLatch = new CountDownLatch(1);
    final AtomicInteger invocationCount = new AtomicInteger();
    ReplicationGroupListener listener = new NoopReplicationGroupListener() {

        @Override
        public void onReplicationNodeRecovered(ReplicationNode node) {
            nodeAddedLatch.countDown();
        }

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

        @Override
        public void onReplicationNodeRemovedFromGroup(ReplicationNode node) {
            invocationCount.getAndIncrement();
            nodeDeletedLatch.countDown();
        }
    };
    TestStateChangeListener stateChangeListener = new TestStateChangeListener();
    ReplicatedEnvironmentFacade replicatedEnvironmentFacade = addNode(stateChangeListener, listener);
    // Set the node to be primary so that the node will remain master even when the 2nd node is shutdown
    replicatedEnvironmentFacade.reapplyDesignatedPrimary();
    assertTrue("Master was not started", stateChangeListener.awaitForStateChange(State.MASTER, _timeout, TimeUnit.SECONDS));
    String node2Name = TEST_NODE_NAME + "_2";
    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", 2, replicatedEnvironmentFacade.getNumberOfElectableGroupMembers());
    // Need to await the listener hearing the addition of the node to the model.
    assertTrue("Node add not fired within timeout", nodeAddedLatch.await(_timeout, TimeUnit.SECONDS));
    // Now remove the node and ensure we hear the event
    replicatedEnvironmentFacade.removeNodeFromGroup(node2Name);
    assertTrue("Node delete not fired within timeout", nodeDeletedLatch.await(_timeout, TimeUnit.SECONDS));
    assertEquals("Unexpected number of nodes after node removal", 1, replicatedEnvironmentFacade.getNumberOfElectableGroupMembers());
    assertEquals("Unexpected number of listener invocations", 1, invocationCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) ReplicationNode(com.sleepycat.je.rep.ReplicationNode)

Aggregations

ReplicationNode (com.sleepycat.je.rep.ReplicationNode)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 NodeState (com.sleepycat.je.rep.NodeState)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ReplicatedEnvironmentFacade.getRemoteNodeState (org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade.getRemoteNodeState)2 DatabaseException (com.sleepycat.je.DatabaseException)1 HashSet (java.util.HashSet)1 RemoteReplicationNode (org.apache.qpid.server.model.RemoteReplicationNode)1 ReplicatedEnvironmentFacade (org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade)1