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());
}
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());
}
Aggregations