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