diff options
| author | Alex Rudyy <orudyy@apache.org> | 2014-08-06 12:21:59 +0000 |
|---|---|---|
| committer | Alex Rudyy <orudyy@apache.org> | 2014-08-06 12:21:59 +0000 |
| commit | 1f2d3541f070cedbda87e3df6ee692edbcdf9381 (patch) | |
| tree | 0142e6a7babc1f00b87c805f567d6338a653986f /qpid/java/bdbstore/src/test | |
| parent | 90c8a29045f18554fd4c2da5ad01dd00af11cae7 (diff) | |
| download | qpid-python-1f2d3541f070cedbda87e3df6ee692edbcdf9381.tar.gz | |
QPID-5967: Intruder node detection must be mandatory and should validate all necessary arguments
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1616186 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/bdbstore/src/test')
4 files changed, 156 insertions, 315 deletions
diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java index 66b252a246..c667e7f7bb 100644 --- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java @@ -34,6 +34,8 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import com.sleepycat.je.Durability; +import com.sleepycat.je.EnvironmentConfig; import com.sleepycat.je.rep.ReplicatedEnvironment; import com.sleepycat.je.rep.ReplicationConfig; @@ -80,25 +82,16 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase public void testCreateAndActivateVirtualHostNode() throws Exception { - String messageStorePath = _helper.getMessageStorePath(); - String repStreamTimeout = "2 h"; - String nodeName = "node"; + int node1PortNumber = findFreePort(); + String helperAddress = "localhost:" + node1PortNumber; String groupName = "group"; - String nodeHostPort = "localhost:" + findFreePort(); - String helperHostPort = nodeHostPort; - UUID id = UUID.randomUUID(); - - Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(BDBHAVirtualHostNode.TYPE, BDBHAVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE); - attributes.put(BDBHAVirtualHostNode.ID, id); - attributes.put(BDBHAVirtualHostNode.NAME, nodeName); - attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - attributes.put(BDBHAVirtualHostNode.ADDRESS, nodeHostPort); - attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperHostPort); - attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath); - attributes.put(BDBHAVirtualHostNode.CONTEXT, - singletonMap(ReplicationConfig.REP_STREAM_TIMEOUT, repStreamTimeout)); + String nodeName = "node1"; + Map<String, Object> attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber); + String messageStorePath = (String)attributes.get(BDBHAVirtualHostNode.STORE_PATH); + String repStreamTimeout = "2 h"; + Map<String,String> context = (Map<String,String>)attributes.get(BDBHAVirtualHostNode.CONTEXT); + context.put(ReplicationConfig.REP_STREAM_TIMEOUT, repStreamTimeout); BDBHAVirtualHostNode<?> node = _helper.createHaVHN(attributes); final CountDownLatch virtualHostAddedLatch = new CountDownLatch(1); @@ -117,6 +110,7 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase node.start(); _helper.assertNodeRole(node, "MASTER", "REPLICA"); + assertEquals("Unexpected node state", State.ACTIVE, node.getState()); DurableConfigurationStore store = node.getConfigurationStore(); @@ -128,8 +122,8 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase assertEquals(nodeName, environment.getNodeName()); assertEquals(groupName, environment.getGroup().getName()); - assertEquals(nodeHostPort, replicationConfig.getNodeHostPort()); - assertEquals(helperHostPort, replicationConfig.getHelperHosts()); + assertEquals(helperAddress, replicationConfig.getNodeHostPort()); + assertEquals(helperAddress, replicationConfig.getHelperHosts()); assertEquals("SYNC,NO_SYNC,SIMPLE_MAJORITY", environment.getConfig().getDurability().toString()); assertEquals("Unexpected JE replication stream timeout", repStreamTimeout, replicationConfig.getConfigParam(ReplicationConfig.REP_STREAM_TIMEOUT)); @@ -155,18 +149,12 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase public void testMutableAttributes() throws Exception { - UUID id = UUID.randomUUID(); - String address = "localhost:" + findFreePort(); - - Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - attributes.put(BDBHAVirtualHostNode.ID, id); - attributes.put(BDBHAVirtualHostNode.NAME, "node"); - attributes.put(BDBHAVirtualHostNode.GROUP_NAME, "group"); - attributes.put(BDBHAVirtualHostNode.ADDRESS, address); - attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, address); - attributes.put(BDBHAVirtualHostNode.STORE_PATH, _helper.getMessageStorePath()); + int node1PortNumber = findFreePort(); + String helperAddress = "localhost:" + node1PortNumber; + String groupName = "group"; + String nodeName = "node1"; + Map<String, Object> attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber); BDBHAVirtualHostNode<?> node = _helper.createAndStartHaVHN(attributes); BDBConfigurationStore bdbConfigurationStore = (BDBConfigurationStore) node.getConfigurationStore(); @@ -190,42 +178,21 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase public void testTransferMasterToSelf() throws Exception { - String messageStorePath = _helper.getMessageStorePath(); int node1PortNumber = findFreePort(); + int node2PortNumber = getNextAvailable(node1PortNumber + 1); + int node3PortNumber = getNextAvailable(node2PortNumber + 1); + String helperAddress = "localhost:" + node1PortNumber; String groupName = "group"; + String nodeName = "node1"; - Map<String, Object> node1Attributes = new HashMap<String, Object>(); - node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1"); - node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1"); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber, node3PortNumber); _helper.createAndStartHaVHN(node1Attributes); - int node2PortNumber = getNextAvailable(node1PortNumber+1); - - Map<String, Object> node2Attributes = new HashMap<String, Object>(); - node2Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node2Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node2Attributes.put(BDBHAVirtualHostNode.NAME, "node2"); - node2Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node2Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node2PortNumber); - node2Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "2"); + Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName); _helper.createAndStartHaVHN(node2Attributes); - int node3PortNumber = getNextAvailable(node2PortNumber+1); - Map<String, Object> node3Attributes = new HashMap<String, Object>(); - node3Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node3Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node3Attributes.put(BDBHAVirtualHostNode.NAME, "node3"); - node3Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node3Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node3PortNumber); - node3Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node3Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "3"); + Map<String, Object> node3Attributes = _helper.createNodeAttributes("node3", groupName, "localhost:" + node3PortNumber, helperAddress, nodeName); _helper.createAndStartHaVHN(node3Attributes); BDBHAVirtualHostNode<?> replica = _helper.awaitAndFindNodeInRole("REPLICA"); @@ -238,19 +205,15 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase public void testTransferMasterToRemoteReplica() throws Exception { int node1PortNumber = findFreePort(); + int node2PortNumber = getNextAvailable(node1PortNumber + 1); + int node3PortNumber = getNextAvailable(node2PortNumber + 1); + String helperAddress = "localhost:" + node1PortNumber; String groupName = "group"; - String messageStorePath = _helper.getMessageStorePath(); - - Map<String, Object> node1Attributes = new HashMap<String, Object>(); - node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1"); - node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1"); + 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<>(); @@ -268,28 +231,10 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase } }); - int node2PortNumber = getNextAvailable(node1PortNumber+1); - - Map<String, Object> node2Attributes = new HashMap<String, Object>(); - node2Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node2Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node2Attributes.put(BDBHAVirtualHostNode.NAME, "node2"); - node2Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node2Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node2PortNumber); - node2Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "2"); - + Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName); BDBHAVirtualHostNode<?> node2 = _helper.createAndStartHaVHN(node2Attributes); - int node3PortNumber = getNextAvailable(node2PortNumber+1); - Map<String, Object> node3Attributes = new HashMap<String, Object>(); - node3Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node3Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node3Attributes.put(BDBHAVirtualHostNode.NAME, "node3"); - node3Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node3Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node3PortNumber); - node3Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node3Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "3"); + 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)); @@ -308,17 +253,9 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase int nodePortNumber = findFreePort(); String helperAddress = "localhost:" + nodePortNumber; String groupName = "group"; - String messageStorePath = _helper.getMessageStorePath(); - - Map<String, Object> node1Attributes = new HashMap<String, Object>(); - node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1"); - node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1"); + String nodeName = "node1"; + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, nodePortNumber); BDBHAVirtualHostNode<?> node = _helper.createAndStartHaVHN(node1Attributes); _helper.assertNodeRole(node, "MASTER"); @@ -336,42 +273,21 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase public void testRemoveReplicaNode() throws Exception { - String messageStorePath = _helper.getMessageStorePath(); int node1PortNumber = findFreePort(); + int node2PortNumber = getNextAvailable(node1PortNumber + 1); + int node3PortNumber = getNextAvailable(node2PortNumber + 1); + String helperAddress = "localhost:" + node1PortNumber; String groupName = "group"; + String nodeName = "node1"; - Map<String, Object> node1Attributes = new HashMap<String, Object>(); - node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1"); - node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1"); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber, node3PortNumber); _helper.createAndStartHaVHN(node1Attributes); - int node2PortNumber = getNextAvailable(node1PortNumber+1); - - Map<String, Object> node2Attributes = new HashMap<String, Object>(); - node2Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node2Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node2Attributes.put(BDBHAVirtualHostNode.NAME, "node2"); - node2Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node2Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node2PortNumber); - node2Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "2"); + Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName); _helper.createAndStartHaVHN(node2Attributes); - int node3PortNumber = getNextAvailable(node2PortNumber+1); - Map<String, Object> node3Attributes = new HashMap<String, Object>(); - node3Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node3Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node3Attributes.put(BDBHAVirtualHostNode.NAME, "node3"); - node3Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node3Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node3PortNumber); - node3Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node3Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "3"); + Map<String, Object> node3Attributes = _helper.createNodeAttributes("node3", groupName, "localhost:" + node3PortNumber, helperAddress, nodeName); _helper.createAndStartHaVHN(node3Attributes); BDBHAVirtualHostNode<?> master = _helper.awaitAndFindNodeInRole("MASTER"); @@ -393,15 +309,9 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase int node1PortNumber = findFreePort(); String helperAddress = "localhost:" + node1PortNumber; String groupName = "group"; + String nodeName = "node1"; - Map<String, Object> nodeAttributes = new HashMap<String, Object>(); - nodeAttributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - nodeAttributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - nodeAttributes.put(BDBHAVirtualHostNode.NAME, "node1"); - nodeAttributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - nodeAttributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress); - nodeAttributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - nodeAttributes.put(BDBHAVirtualHostNode.STORE_PATH, _helper.getMessageStorePath() + File.separator + "1"); + Map<String, Object> nodeAttributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber); BDBHAVirtualHostNode<?> node = _helper.createHaVHN(nodeAttributes); final CountDownLatch virtualHostAddedLatch = new CountDownLatch(1); @@ -465,59 +375,23 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase } - public void testIntruderProtection() throws Exception + public void testNotPermittedNodeIsNotAllowedToConnect() throws Exception { - String messageStorePath = _helper.getMessageStorePath(); int node1PortNumber = findFreePort(); int node2PortNumber = getNextAvailable(node1PortNumber+1); + int node3PortNumber = getNextAvailable(node2PortNumber+1); + String helperAddress = "localhost:" + node1PortNumber; String groupName = "group"; + String nodeName = "node1"; - List<String> permittedNodes = new ArrayList<>(); - permittedNodes.add(helperAddress); - String node2Address = "localhost:" + node2PortNumber; - permittedNodes.add(node2Address); - - String blueprint = String.format("{ \"%s\" : [ \"%s\", \"%s\" ] } ", BDBHAVirtualHost.PERMITTED_NODES, helperAddress, node2Address); - - Map<String, Object> node1Attributes = new HashMap<>(); - node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1"); - node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1"); - Map<String, String> contextMap = singletonMap(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, blueprint); - node1Attributes.put(BDBHAVirtualHostNode.CONTEXT, contextMap); - + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber); BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes); - Map<String, Object> node2Attributes = new HashMap<String, Object>(); - node2Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node2Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node2Attributes.put(BDBHAVirtualHostNode.NAME, "node2"); - node2Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node2Attributes.put(BDBHAVirtualHostNode.ADDRESS, node2Address); - node2Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "2"); - node2Attributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, "node1"); - node2Attributes.put(BDBHAVirtualHostNode.PRIORITY, 0); - + Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName); BDBHAVirtualHostNode<?> node2 = _helper.createAndStartHaVHN(node2Attributes); - int node3PortNumber = getNextAvailable(node2PortNumber+1); - Map<String, Object> node3Attributes = new HashMap<String, Object>(); - node3Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node3Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node3Attributes.put(BDBHAVirtualHostNode.NAME, "node3"); - node3Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node3Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node3PortNumber); - node3Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node3Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "3"); - node3Attributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, "node1"); - node3Attributes.put(BDBHAVirtualHostNode.PRIORITY, 0); - + Map<String, Object> node3Attributes = _helper.createNodeAttributes("node3", groupName, "localhost:" + node3PortNumber, helperAddress, nodeName); try { _helper.createHaVHN(node3Attributes); @@ -527,59 +401,22 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase { assertEquals("Unexpected exception message", String.format("Node from '%s' is not permitted!", "localhost:" + node3PortNumber), e.getMessage()); } - - // join node by skipping a step retrieving node state and checking the permitted hosts - node3Attributes.remove(BDBHAVirtualHostNode.HELPER_NODE_NAME); - - final CountDownLatch stopLatch = new CountDownLatch(1); - ConfigurationChangeListener listener = new NoopConfigurationChangeListener() - { - @Override - public void stateChanged(ConfiguredObject<?> object, State oldState, State newState) - { - if (newState == State.ERRORED) - { - stopLatch.countDown(); - } - } - }; - node1.addChangeListener(listener); - - _helper.createHaVHN(node3Attributes); - - assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(10, TimeUnit.SECONDS)); } public void testIntruderProtectionInManagementMode() throws Exception { - String messageStorePath = _helper.getMessageStorePath(); int node1PortNumber = findFreePort(); + int node2PortNumber = getNextAvailable(node1PortNumber + 1); + String helperAddress = "localhost:" + node1PortNumber; String groupName = "group"; + String nodeName = "node1"; - Map<String, Object> node1Attributes = new HashMap<String, Object>(); - node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1"); - node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1"); - + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber); BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes); - int node2PortNumber = getNextAvailable(node1PortNumber+1); - Map<String, Object> node2Attributes = new HashMap<String, Object>(); - node2Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node2Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node2Attributes.put(BDBHAVirtualHostNode.NAME, "node2"); - node2Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node2Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node2PortNumber); - node2Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "2"); - node2Attributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, "node1"); + Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName); node2Attributes.put(BDBHAVirtualHostNode.PRIORITY, 0); - BDBHAVirtualHostNode<?> node2 = _helper.createAndStartHaVHN(node2Attributes); final CountDownLatch stopLatch = new CountDownLatch(1); @@ -613,37 +450,18 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase remote.delete(); } - public void testIntruderConnectedBeforePermittedNodesAreSet() throws Exception + public void testIntruderConnected() throws Exception { - String messageStorePath = _helper.getMessageStorePath(); int node1PortNumber = findFreePort(); + int node2PortNumber = getNextAvailable(node1PortNumber + 1); + String helperAddress = "localhost:" + node1PortNumber; String groupName = "group"; + String nodeName = "node1"; - Map<String, Object> node1Attributes = new HashMap<String, Object>(); - node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1"); - node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1"); - + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber); BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes); - int node2PortNumber = getNextAvailable(node1PortNumber+1); - Map<String, Object> node2Attributes = new HashMap<String, Object>(); - node2Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); - node2Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA"); - node2Attributes.put(BDBHAVirtualHostNode.NAME, "node2"); - node2Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName); - node2Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node2PortNumber); - node2Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); - node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "2"); - node2Attributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, "node1"); - - _helper.createAndStartHaVHN(node2Attributes); - final CountDownLatch stopLatch = new CountDownLatch(1); ConfigurationChangeListener listener = new NoopConfigurationChangeListener() { @@ -658,14 +476,28 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase }; node1.addChangeListener(listener); - BDBHAVirtualHost<?> host = (BDBHAVirtualHost<?>)node1.getVirtualHost(); - List<String> permittedNodes = new ArrayList<String>(); - permittedNodes.add(helperAddress); - host.setAttributes(Collections.<String, Object>singletonMap(BDBHAVirtualHost.PERMITTED_NODES, permittedNodes)); + String node2Name = "node2"; + File environmentPathFile = new File(_helper.getMessageStorePath() + File.separator + node2Name); + environmentPathFile.mkdirs(); - assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(20, TimeUnit.SECONDS)); - } + ReplicationConfig replicationConfig = new ReplicationConfig(groupName, node2Name, "localhost:" + node2PortNumber ); + replicationConfig.setHelperHosts(helperAddress); + EnvironmentConfig envConfig = new EnvironmentConfig(); + envConfig.setAllowCreate(true); + envConfig.setTransactional(true); + envConfig.setDurability(Durability.parse((String) node1Attributes.get(BDBHAVirtualHostNode.DURABILITY))); -} + ReplicatedEnvironment intruder = null; + try + { + intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig); + } + finally + { + intruder.close(); + } + assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(20, TimeUnit.SECONDS)); + } +}
\ No newline at end of file diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java index 229c2c3f27..44fc19e14f 100644 --- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java @@ -24,11 +24,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.File; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -55,6 +51,7 @@ import com.sleepycat.je.rep.ReplicationConfig; import com.sleepycat.je.rep.ReplicationNode; import com.sleepycat.je.rep.StateChangeEvent; import com.sleepycat.je.rep.StateChangeListener; +import org.codehaus.jackson.map.ObjectMapper; public class ReplicatedEnvironmentFacadeTest extends QpidTestCase { @@ -267,6 +264,7 @@ public class ReplicatedEnvironmentFacadeTest extends QpidTestCase String node2Name = TEST_NODE_NAME + "_2"; String node2NodeHostPort = "localhost" + ":" + getNextAvailable(TEST_NODE_PORT + 1); + replicatedEnvironmentFacade.setPermittedNodes(Arrays.asList(replicatedEnvironmentFacade.getHostPort(), node2NodeHostPort)); createReplica(node2Name, node2NodeHostPort, new NoopReplicationGroupListener()); assertTrue("Listener not fired within timeout", nodeAddedLatch.await(LISTENER_TIMEOUT, TimeUnit.SECONDS)); @@ -309,6 +307,7 @@ public class ReplicatedEnvironmentFacadeTest extends QpidTestCase String node2Name = TEST_NODE_NAME + "_2"; String node2NodeHostPort = "localhost" + ":" + getNextAvailable(TEST_NODE_PORT + 1); + replicatedEnvironmentFacade.setPermittedNodes(Arrays.asList(replicatedEnvironmentFacade.getHostPort(), node2NodeHostPort)); createReplica(node2Name, node2NodeHostPort, new NoopReplicationGroupListener()); assertEquals("Unexpected number of nodes at start of test", 2, replicatedEnvironmentFacade.getNumberOfElectableGroupMembers()); @@ -358,6 +357,7 @@ public class ReplicatedEnvironmentFacadeTest extends QpidTestCase assertTrue("Master was not started", stateChangeListener.awaitForStateChange(LISTENER_TIMEOUT, TimeUnit.SECONDS)); String node2NodeHostPort = "localhost" + ":" + getNextAvailable(TEST_NODE_PORT + 1); + replicatedEnvironmentFacade.setPermittedNodes(Arrays.asList(replicatedEnvironmentFacade.getHostPort(), node2NodeHostPort)); createReplica(node2Name, node2NodeHostPort, new NoopReplicationGroupListener()); assertEquals("Unexpected number of nodes at start of test", 2, replicatedEnvironmentFacade.getNumberOfElectableGroupMembers()); @@ -434,7 +434,7 @@ public class ReplicatedEnvironmentFacadeTest extends QpidTestCase int replica1Port = getNextAvailable(TEST_NODE_PORT + 1); 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(WAIT_STATE_CHANGE_TIMEOUT, TimeUnit.SECONDS)); @@ -658,7 +658,10 @@ public class ReplicatedEnvironmentFacadeTest extends QpidTestCase NodeState nodeState = firstNode.getRemoteNodeState(new ReplicatedEnvironmentFacade.ReplicationNodeImpl(TEST_NODE_NAME, TEST_NODE_HOST_PORT)); - Collection<String> appStatePermittedNodes = firstNode.bytesToPermittedNodeList(nodeState.getAppState()); + ObjectMapper objectMapper = new ObjectMapper(); + + Map<String, Object> settings = objectMapper.readValue(nodeState.getAppState(), Map.class); + Collection<String> appStatePermittedNodes = (Collection<String>)settings.get(ReplicatedEnvironmentFacade.PERMITTED_NODE_LIST); assertEquals("Unexpected permitted nodes", permittedNodes, new HashSet<String>(appStatePermittedNodes)); } @@ -684,33 +687,6 @@ public class ReplicatedEnvironmentFacadeTest extends QpidTestCase assertEquals("Unexpected state", State.REPLICA.name(), secondNode.getNodeState()); } - public void testNotPermittedNodeIsNotAllowedToConnect() throws Exception - { - ReplicatedEnvironmentFacade firstNode = createMaster(); - - int replica1Port = getNextAvailable(TEST_NODE_PORT + 1); - String node1NodeHostPort = "localhost:" + replica1Port; - - Set<String> permittedNodes = new HashSet<String>(); - permittedNodes.add("localhost:" + TEST_NODE_PORT); - - firstNode.setPermittedNodes(permittedNodes); - - ReplicatedEnvironmentConfiguration configuration = createReplicatedEnvironmentConfiguration(TEST_NODE_NAME + "_1", node1NodeHostPort, false); - when(configuration.getHelperNodeName()).thenReturn(TEST_NODE_NAME); - - try - { - createReplicatedEnvironmentFacade(TEST_NODE_NAME + "_1", new TestStateChangeListener(State.REPLICA), new NoopReplicationGroupListener(), configuration); - fail("Node is not allowed to connect from " + node1NodeHostPort + " but environment was successfully created"); - } - catch (IllegalConfigurationException e) - { - assertEquals("Unexpected exception message", String.format("Node from '%s' is not permitted!", - node1NodeHostPort), e.getMessage()); - } - } - public void testIntruderNodeIsDetected() throws Exception { final CountDownLatch intruderLatch = new CountDownLatch(1); @@ -820,6 +796,7 @@ public class ReplicatedEnvironmentFacadeTest extends QpidTestCase when(node.getPriority()).thenReturn(TEST_PRIORITY); when(node.getGroupName()).thenReturn(TEST_GROUP_NAME); when(node.getHelperHostPort()).thenReturn(TEST_NODE_HELPER_HOST_PORT); + when(node.getHelperNodeName()).thenReturn(TEST_NODE_NAME); Map<String, String> repConfig = new HashMap<String, String>(); repConfig.put(ReplicationConfig.REPLICA_ACK_TIMEOUT, "2 s"); diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java index 665a778dd8..45527313e6 100644 --- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java @@ -75,7 +75,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase String groupName = "group"; String nodeName = "node1"; - Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber); BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes); _helper.assertNodeRole(node1, "MASTER"); @@ -105,7 +105,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase String groupName = "group"; String nodeName = "node1"; - Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber); BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes); _helper.assertNodeRole(node1, "MASTER"); reset(_eventLogger); @@ -128,7 +128,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase String groupName = "group"; String nodeName = "node1"; - Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber); BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes); _helper.assertNodeRole(node1, "MASTER"); @@ -148,7 +148,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase String groupName = "group"; String nodeName = "node1"; - Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber); BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes); _helper.assertNodeRole(node1, "MASTER"); @@ -172,7 +172,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase String groupName = "group"; String nodeName = "node1"; - Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber); BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes); _helper.assertNodeRole(node1, "MASTER"); @@ -195,7 +195,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase String groupName = "group"; String nodeName = "node1"; - Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber); BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes); _helper.assertNodeRole(node1, "MASTER"); @@ -218,7 +218,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase String groupName = "group"; String nodeName = "node1"; - Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber); BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes); _helper.assertNodeRole(node1, "MASTER"); @@ -237,18 +237,19 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase public void testRemoteNodeAdded() throws Exception { int node1PortNumber = findFreePort(); + int node2PortNumber = getNextAvailable(node1PortNumber + 1); String helperAddress = "localhost:" + node1PortNumber; String groupName = "group"; String nodeName = "node1"; - Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber); BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes); _helper.assertNodeRole(node1, "MASTER"); reset(_eventLogger); - int node2PortNumber = getNextAvailable(node1PortNumber + 1); - Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress); + + Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName); BDBHAVirtualHostNodeImpl node2 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node2Attributes); _helper.awaitRemoteNodes(node1, 1); @@ -269,19 +270,19 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase public void testRemoteNodeRemoved() throws Exception { int node1PortNumber = findFreePort(); + int node2PortNumber = getNextAvailable(node1PortNumber + 1); String helperAddress = "localhost:" + node1PortNumber; String groupName = "group"; String nodeName = "node1"; - Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber); node1Attributes.put(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, true); BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes); _helper.assertNodeRole(node1, "MASTER"); resetEventLogger(); - int node2PortNumber = getNextAvailable(node1PortNumber + 1); - Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress); + Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName); BDBHAVirtualHostNodeImpl node2 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node2Attributes); _helper.awaitRemoteNodes(node1, 1); @@ -301,17 +302,17 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase public void testRemoteNodeDetached() throws Exception { int node1PortNumber = findFreePort(); + int node2PortNumber = getNextAvailable(node1PortNumber + 1); String helperAddress = "localhost:" + node1PortNumber; String groupName = "group"; String nodeName = "node1"; - Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber); node1Attributes.put(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, true); BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes); _helper.assertNodeRole(node1, "MASTER"); - int node2PortNumber = getNextAvailable(node1PortNumber + 1); - Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress); + Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName); BDBHAVirtualHostNodeImpl node2 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node2Attributes); _helper.awaitRemoteNodes(node1, 1); @@ -334,18 +335,19 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase public void testRemoteNodeReAttached() throws Exception { int node1PortNumber = findFreePort(); + int node2PortNumber = getNextAvailable(node1PortNumber + 1); String helperAddress = "localhost:" + node1PortNumber; String groupName = "group"; String nodeName = "node1"; - Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress); + Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber); node1Attributes.put(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, true); BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes); _helper.assertNodeRole(node1, "MASTER"); resetEventLogger(); - int node2PortNumber = getNextAvailable(node1PortNumber + 1); - Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress); + + Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName); BDBHAVirtualHostNodeImpl node2 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node2Attributes); _helper.awaitRemoteNodes(node1, 1); diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java index 754d8d1d09..07b5a8a21c 100644 --- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java @@ -26,10 +26,13 @@ import static org.junit.Assert.fail; import static org.mockito.Mockito.when; import java.io.File; +import java.io.StringWriter; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -38,18 +41,17 @@ import com.sleepycat.je.rep.ReplicationConfig; import org.apache.qpid.server.configuration.updater.TaskExecutor; import org.apache.qpid.server.configuration.updater.TaskExecutorImpl; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.BrokerModel; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ConfiguredObjectFactory; -import org.apache.qpid.server.model.RemoteReplicationNode; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.VirtualHostNode; +import org.apache.qpid.server.model.*; import org.apache.qpid.server.store.ConfiguredObjectRecordImpl; import org.apache.qpid.server.store.UnresolvedConfiguredObject; import org.apache.qpid.server.util.BrokerTestHelper; +import org.apache.qpid.server.virtualhost.berkeleydb.BDBHAVirtualHost; +import org.apache.qpid.server.virtualhost.berkeleydb.BDBHAVirtualHostImpl; +import org.apache.qpid.server.virtualhostnode.AbstractVirtualHostNode; import org.apache.qpid.test.utils.QpidTestCase; import org.apache.qpid.util.FileUtils; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; /** * Helper class to make the tests of BDB HA Virtual Host Nodes simpler and more concise. @@ -258,7 +260,9 @@ public class BDBHAVirtualHostNodeTestHelper return _broker; } - Map<String, Object> createNodeAttributes(String nodeName, String groupName, String address, String helperAddress) + public Map<String, Object> createNodeAttributes(String nodeName, String groupName, String address, + String helperAddress, String helperNodeNode, int... ports) + throws Exception { Map<String, Object> node1Attributes = new HashMap<String, Object>(); node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID()); @@ -268,13 +272,39 @@ public class BDBHAVirtualHostNodeTestHelper node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, address); node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, getMessageStorePath() + File.separator + nodeName); + node1Attributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, helperNodeNode); - Map<String, String> repConfig = new HashMap<String, String>(); - repConfig.put(ReplicationConfig.REPLICA_ACK_TIMEOUT, "2 s"); - repConfig.put(ReplicationConfig.INSUFFICIENT_REPLICAS_TIMEOUT, "2 s"); + Map<String, String> context = new HashMap<String, String>(); + context.put(ReplicationConfig.REPLICA_ACK_TIMEOUT, "2 s"); + context.put(ReplicationConfig.INSUFFICIENT_REPLICAS_TIMEOUT, "2 s"); - node1Attributes.put(BDBHAVirtualHostNode.CONTEXT, repConfig); + if (ports != null) + { + String bluePrint = getBlueprint(ports); + context.put(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, bluePrint); + } + + node1Attributes.put(BDBHAVirtualHostNode.CONTEXT, context); return node1Attributes; } + + public static String getBlueprint(int... ports) throws Exception + { + List<String> permittedNodes = new ArrayList<String>(); + for (int port:ports) + { + permittedNodes.add("localhost:" + port); + } + Map<String,Object> bluePrint = new HashMap<>(); + bluePrint.put(VirtualHost.TYPE, BDBHAVirtualHostImpl.VIRTUAL_HOST_TYPE); + bluePrint.put(BDBHAVirtualHost.PERMITTED_NODES, permittedNodes); + + StringWriter writer = new StringWriter(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); + mapper.writeValue(writer, bluePrint); + return writer.toString(); + } + } |
