qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1626955 - in /qpid/trunk/qpid/java: bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/ bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/b...
Date Tue, 23 Sep 2014 06:55:35 GMT
Author: kwall
Date: Tue Sep 23 06:55:34 2014
New Revision: 1626955

URL: http://svn.apache.org/r1626955
Log:
QPID-6111: [Java Broker] HA Tests - change JE tests to assert that JE replication ports are
always relinquished.

Modified:
    qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java
    qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java
    qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java
    qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java
    qpid/trunk/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java
    qpid/trunk/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java

Modified: qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java?rev=1626955&r1=1626954&r2=1626955&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java
(original)
+++ qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java
Tue Sep 23 06:55:34 2014
@@ -51,11 +51,14 @@ import org.apache.qpid.server.virtualhos
 import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHAVirtualHostNode;
 import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHAVirtualHostNodeTestHelper;
 import org.apache.qpid.server.virtualhostnode.berkeleydb.NodeRole;
+import org.apache.qpid.test.utils.PortHelper;
 import org.apache.qpid.test.utils.QpidTestCase;
 
 public class BDBHAVirtualHostNodeTest extends QpidTestCase
 {
     private BDBHAVirtualHostNodeTestHelper _helper;
+    private PortHelper _portHelper = new PortHelper();
+
     @Override
     protected void setUp() throws Exception
     {
@@ -75,11 +78,13 @@ public class BDBHAVirtualHostNodeTest ex
         {
             super.tearDown();
         }
+
+        _portHelper.waitUntilAllocatedPortsAreFree();
     }
 
     public void testCreateAndActivateVirtualHostNode() throws Exception
     {
-        int node1PortNumber = findFreePort();
+        int node1PortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";
@@ -132,7 +137,7 @@ public class BDBHAVirtualHostNodeTest ex
 
     public void testMutableAttributes() throws Exception
     {
-        int node1PortNumber = findFreePort();
+        int node1PortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";
@@ -161,9 +166,9 @@ public class BDBHAVirtualHostNodeTest ex
 
     public void testTransferMasterToSelf() throws Exception
     {
-        int node1PortNumber = findFreePort();
-        int node2PortNumber = getNextAvailable(node1PortNumber + 1);
-        int node3PortNumber = getNextAvailable(node2PortNumber + 1);
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
+        int node3PortNumber = _portHelper.getNextAvailable();
 
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
@@ -187,9 +192,9 @@ public class BDBHAVirtualHostNodeTest ex
 
     public void testTransferMasterToRemoteReplica() throws Exception
     {
-        int node1PortNumber = findFreePort();
-        int node2PortNumber = getNextAvailable(node1PortNumber + 1);
-        int node3PortNumber = getNextAvailable(node2PortNumber + 1);
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
+        int node3PortNumber = _portHelper.getNextAvailable();
 
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
@@ -233,7 +238,7 @@ public class BDBHAVirtualHostNodeTest ex
 
     public void testMutatingRoleWhenNotReplica_IsDisallowed() throws Exception
     {
-        int nodePortNumber = findFreePort();
+        int nodePortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + nodePortNumber;
         String groupName = "group";
         String nodeName = "node1";
@@ -256,23 +261,30 @@ public class BDBHAVirtualHostNodeTest ex
 
     public void testRemoveReplicaNode() throws Exception
     {
-        int node1PortNumber = findFreePort();
-        int node2PortNumber = getNextAvailable(node1PortNumber + 1);
-        int node3PortNumber = getNextAvailable(node2PortNumber + 1);
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
+        int node3PortNumber = _portHelper.getNextAvailable();
 
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";
 
+        assertTrue(_portHelper.isPortAvailable(node1PortNumber));
+
         Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName,
groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber, node3PortNumber);
         _helper.createAndStartHaVHN(node1Attributes);
 
+        assertTrue(_portHelper.isPortAvailable(node2PortNumber));
+
         Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2",
groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
         _helper.createAndStartHaVHN(node2Attributes);
 
+        assertTrue(_portHelper.isPortAvailable(node3PortNumber));
+
         Map<String, Object> node3Attributes = _helper.createNodeAttributes("node3",
groupName, "localhost:" + node3PortNumber, helperAddress, nodeName);
         _helper.createAndStartHaVHN(node3Attributes);
 
+
         BDBHAVirtualHostNode<?> master = _helper.awaitAndFindNodeInRole(NodeRole.MASTER);
         _helper.awaitRemoteNodes(master, 2);
 
@@ -286,10 +298,9 @@ public class BDBHAVirtualHostNodeTest ex
         assertNull("Remote node " + replica.getName() + " is not found", _helper.findRemoteNode(master,
replica.getName()));
     }
 
-
     public void testSetSynchronizationPolicyAttributesOnVirtualHost() throws Exception
     {
-        int node1PortNumber = findFreePort();
+        int node1PortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";
@@ -346,9 +357,9 @@ public class BDBHAVirtualHostNodeTest ex
 
     public void testNotPermittedNodeIsNotAllowedToConnect() throws Exception
     {
-        int node1PortNumber = findFreePort();
-        int node2PortNumber = getNextAvailable(node1PortNumber+1);
-        int node3PortNumber = getNextAvailable(node2PortNumber+1);
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
+        int node3PortNumber = _portHelper.getNextAvailable();
 
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
@@ -374,9 +385,9 @@ public class BDBHAVirtualHostNodeTest ex
 
     public void testCurrentNodeCannotBeRemovedFromPermittedNodeList() throws Exception
     {
-        int node1PortNumber = findFreePort();
-        int node2PortNumber = getNextAvailable(node1PortNumber+1);
-        int node3PortNumber = getNextAvailable(node2PortNumber+1);
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
+        int node3PortNumber = _portHelper.getNextAvailable();
 
         String node1Address = "localhost:" + node1PortNumber;
         String node2Address = "localhost:" + node2PortNumber;
@@ -415,11 +426,11 @@ public class BDBHAVirtualHostNodeTest ex
 
     public void testPermittedNodesAttributeModificationConditions() throws Exception
     {
-        int node1PortNumber = findFreePort();
-        int node2PortNumber = getNextAvailable(node1PortNumber+1);
-        int node3PortNumber = getNextAvailable(node2PortNumber+1);
-        int node4PortNumber = getNextAvailable(node3PortNumber+1);
-        int node5PortNumber = getNextAvailable(node4PortNumber+1);
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
+        int node3PortNumber = _portHelper.getNextAvailable();
+        int node4PortNumber = _portHelper.getNextAvailable();
+        int node5PortNumber = _portHelper.getNextAvailable();
 
         String node1Address = "localhost:" + node1PortNumber;
         String node2Address = "localhost:" + node2PortNumber;
@@ -472,8 +483,8 @@ public class BDBHAVirtualHostNodeTest ex
 
     public void testIntruderProtectionInManagementMode() throws Exception
     {
-        int node1PortNumber = findFreePort();
-        int node2PortNumber = getNextAvailable(node1PortNumber + 1);
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
 
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
@@ -517,8 +528,8 @@ public class BDBHAVirtualHostNodeTest ex
 
     public void testIntruderConnected() throws Exception
     {
-        int node1PortNumber = findFreePort();
-        int node2PortNumber = getNextAvailable(node1PortNumber + 1);
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
 
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
@@ -553,13 +564,24 @@ public class BDBHAVirtualHostNodeTest ex
         envConfig.setDurability(Durability.parse((String) node1Attributes.get(BDBHAVirtualHostNode.DURABILITY)));
 
         ReplicatedEnvironment intruder = null;
+        String originalThreadName = Thread.currentThread().getName();
         try
         {
             intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig,
envConfig);
         }
         finally
         {
-            intruder.close();
+            try
+            {
+                if (intruder != null)
+                {
+                    intruder.close();
+                }
+            }
+            finally
+            {
+                Thread.currentThread().setName(originalThreadName);
+            }
         }
 
         assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(20,
TimeUnit.SECONDS));

Modified: qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java?rev=1626955&r1=1626954&r2=1626955&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java
(original)
+++ qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java
Tue Sep 23 06:55:34 2014
@@ -35,6 +35,7 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.log4j.Logger;
 import org.apache.qpid.server.store.berkeleydb.EnvironmentFacade;
+import org.apache.qpid.test.utils.PortHelper;
 import org.apache.qpid.test.utils.QpidTestCase;
 import org.apache.qpid.test.utils.TestFileUtils;
 import org.apache.qpid.util.FileUtils;
@@ -57,17 +58,20 @@ import org.codehaus.jackson.map.ObjectMa
 public class ReplicatedEnvironmentFacadeTest extends QpidTestCase
 {
     private static final Logger LOGGER = Logger.getLogger(ReplicatedEnvironmentFacadeTest.class);
-    private static final int TEST_NODE_PORT = new QpidTestCase().findFreePort();
     private static final int LISTENER_TIMEOUT = 5;
     private static final int WAIT_STATE_CHANGE_TIMEOUT = 30;
-    private static final String TEST_GROUP_NAME = "testGroupName";
-    private static final String TEST_NODE_NAME = "testNodeName";
-    private static final String TEST_NODE_HOST_PORT = "localhost:" + TEST_NODE_PORT;
-    private static final String TEST_NODE_HELPER_HOST_PORT = TEST_NODE_HOST_PORT;
-    private static final Durability TEST_DURABILITY = Durability.parse("SYNC,NO_SYNC,SIMPLE_MAJORITY");
-    private static final boolean TEST_DESIGNATED_PRIMARY = false;
-    private static final int TEST_PRIORITY = 1;
-    private static final int TEST_ELECTABLE_GROUP_OVERRIDE = 0;
+
+    private final PortHelper _portHelper = new PortHelper();
+
+    private final String TEST_GROUP_NAME = "testGroupName";
+    private final String TEST_NODE_NAME = "testNodeName";
+    private final int TEST_NODE_PORT = _portHelper.getNextAvailable();
+    private final String TEST_NODE_HOST_PORT = "localhost:" + TEST_NODE_PORT;
+    private final String TEST_NODE_HELPER_HOST_PORT = TEST_NODE_HOST_PORT;
+    private final Durability TEST_DURABILITY = Durability.parse("SYNC,NO_SYNC,SIMPLE_MAJORITY");
+    private final boolean TEST_DESIGNATED_PRIMARY = false;
+    private final int TEST_PRIORITY = 1;
+    private final int TEST_ELECTABLE_GROUP_OVERRIDE = 0;
 
     private File _storePath;
     private final Map<String, ReplicatedEnvironmentFacade> _nodes = new HashMap<String,
ReplicatedEnvironmentFacade>();
@@ -105,6 +109,8 @@ public class ReplicatedEnvironmentFacade
                 super.tearDown();
             }
         }
+
+        _portHelper.waitUntilAllocatedPortsAreFree();
     }
     public void testEnvironmentFacade() throws Exception
     {
@@ -220,7 +226,7 @@ public class ReplicatedEnvironmentFacade
         ReplicatedEnvironmentFacade master = createMaster();
         String nodeName2 = TEST_NODE_NAME + "_2";
         String host = "localhost";
-        int port = getNextAvailable(TEST_NODE_PORT + 1);
+        int port = _portHelper.getNextAvailable();
         String node2NodeHostPort = host + ":" + port;
 
         final AtomicInteger invocationCount = new AtomicInteger();
@@ -264,7 +270,7 @@ public class ReplicatedEnvironmentFacade
         assertEquals("Unexpected number of nodes at start of test", 1, replicatedEnvironmentFacade.getNumberOfElectableGroupMembers());
 
         String node2Name = TEST_NODE_NAME + "_2";
-        String node2NodeHostPort = "localhost" + ":" + getNextAvailable(TEST_NODE_PORT +
1);
+        String node2NodeHostPort = "localhost" + ":" + _portHelper.getNextAvailable();
         replicatedEnvironmentFacade.setPermittedNodes(Arrays.asList(replicatedEnvironmentFacade.getHostPort(),
node2NodeHostPort));
         createReplica(node2Name, node2NodeHostPort, new NoopReplicationGroupListener());
 
@@ -307,7 +313,7 @@ public class ReplicatedEnvironmentFacade
         assertTrue("Master was not started", stateChangeListener.awaitForStateChange(LISTENER_TIMEOUT,
TimeUnit.SECONDS));
 
         String node2Name = TEST_NODE_NAME + "_2";
-        String node2NodeHostPort = "localhost" + ":" + getNextAvailable(TEST_NODE_PORT +
1);
+        String node2NodeHostPort = "localhost" + ":" + _portHelper.getNextAvailable();
         replicatedEnvironmentFacade.setPermittedNodes(Arrays.asList(replicatedEnvironmentFacade.getHostPort(),
node2NodeHostPort));
         createReplica(node2Name, node2NodeHostPort, new NoopReplicationGroupListener());
 
@@ -357,7 +363,7 @@ public class ReplicatedEnvironmentFacade
         ReplicatedEnvironmentFacade replicatedEnvironmentFacade = addNode(stateChangeListener,
listener);
         assertTrue("Master was not started", stateChangeListener.awaitForStateChange(LISTENER_TIMEOUT,
TimeUnit.SECONDS));
 
-        String node2NodeHostPort = "localhost" + ":" + getNextAvailable(TEST_NODE_PORT +
1);
+        String node2NodeHostPort = "localhost" + ":" + _portHelper.getNextAvailable();
         replicatedEnvironmentFacade.setPermittedNodes(Arrays.asList(replicatedEnvironmentFacade.getHostPort(),
node2NodeHostPort));
         createReplica(node2Name, node2NodeHostPort, new NoopReplicationGroupListener());
 
@@ -380,7 +386,7 @@ public class ReplicatedEnvironmentFacade
 
 
         String node2Name = TEST_NODE_NAME + "_2";
-        String node2NodeHostPort = "localhost:" + getNextAvailable(TEST_NODE_PORT + 1);
+        String node2NodeHostPort = "localhost:" + _portHelper.getNextAvailable();
         ReplicatedEnvironmentFacade ref2 = createReplica(node2Name, node2NodeHostPort, new
NoopReplicationGroupListener());
 
         assertEquals("Unexpected group members count", 2, environmentFacade.getNumberOfElectableGroupMembers());
@@ -436,7 +442,7 @@ public class ReplicatedEnvironmentFacade
 
         masterEnvironment.setDesignatedPrimary(true);
 
-        int replica1Port = getNextAvailable(TEST_NODE_PORT + 1);
+        int replica1Port = _portHelper.getNextAvailable();
         String node1NodeHostPort = "localhost:" + replica1Port;
         masterEnvironment.setPermittedNodes(Arrays.asList(masterEnvironment.getHostPort(),
node1NodeHostPort));
         ReplicatedEnvironmentFacade replica = createReplica(replicaName, node1NodeHostPort,
new NoopReplicationGroupListener());
@@ -493,9 +499,9 @@ public class ReplicatedEnvironmentFacade
         addNode(stateChangeListener, new NoopReplicationGroupListener());
         assertTrue("Master was not started", masterLatch.await(LISTENER_TIMEOUT, TimeUnit.SECONDS));
 
-        int replica1Port = getNextAvailable(TEST_NODE_PORT + 1);
+        int replica1Port = _portHelper.getNextAvailable();
         String node1NodeHostPort = "localhost:" + replica1Port;
-        int replica2Port = getNextAvailable(replica1Port + 1);
+        int replica2Port = _portHelper.getNextAvailable();
         String node2NodeHostPort = "localhost:" + replica2Port;
 
         ReplicatedEnvironmentFacade replica1 = createReplica(TEST_NODE_NAME + "_1", node1NodeHostPort,
new NoopReplicationGroupListener());
@@ -535,12 +541,12 @@ public class ReplicatedEnvironmentFacade
         ReplicatedEnvironmentFacade firstNode = addNode(stateChangeListener, new NoopReplicationGroupListener());
         assertTrue("Environment did not become a master", firstNodeMasterStateLatch.await(10,
TimeUnit.SECONDS));
 
-        int replica1Port = getNextAvailable(TEST_NODE_PORT + 1);
+        int replica1Port = _portHelper.getNextAvailable();
         String node1NodeHostPort = "localhost:" + replica1Port;
         ReplicatedEnvironmentFacade secondNode = createReplica(TEST_NODE_NAME + "_1", node1NodeHostPort,
new NoopReplicationGroupListener());
         assertEquals("Unexpected state", ReplicatedEnvironment.State.REPLICA.name(), secondNode.getNodeState());
 
-        int replica2Port = getNextAvailable(replica1Port + 1);
+        int replica2Port = _portHelper.getNextAvailable();
         String node2NodeHostPort = "localhost:" + replica2Port;
         final CountDownLatch replicaStateLatch = new CountDownLatch(1);
         final CountDownLatch masterStateLatch = new CountDownLatch(1);
@@ -594,12 +600,12 @@ public class ReplicatedEnvironmentFacade
         ReplicatedEnvironmentFacade firstNode = addNode(stateChangeListener, new NoopReplicationGroupListener());
         assertTrue("Environment did not become a master", firstNodeMasterStateLatch.await(10,
TimeUnit.SECONDS));
 
-        int replica1Port = getNextAvailable(TEST_NODE_PORT + 1);
+        int replica1Port = _portHelper.getNextAvailable();
         String node1NodeHostPort = "localhost:" + replica1Port;
         ReplicatedEnvironmentFacade secondNode = createReplica(TEST_NODE_NAME + "_1", node1NodeHostPort,
new NoopReplicationGroupListener());
         assertEquals("Unexpected state", ReplicatedEnvironment.State.REPLICA.name(), secondNode.getNodeState());
 
-        int replica2Port = getNextAvailable(replica1Port + 1);
+        int replica2Port = _portHelper.getNextAvailable();
         String node2NodeHostPort = "localhost:" + replica2Port;
         final CountDownLatch replicaStateLatch = new CountDownLatch(1);
         final CountDownLatch masterStateLatch = new CountDownLatch(1);
@@ -657,7 +663,7 @@ public class ReplicatedEnvironmentFacade
 
         Set<String> permittedNodes = new HashSet<String>();
         permittedNodes.add("localhost:" + TEST_NODE_PORT);
-        permittedNodes.add("localhost:" + getNextAvailable(TEST_NODE_PORT + 1));
+        permittedNodes.add("localhost:" + _portHelper.getNextAvailable());
         firstNode.setPermittedNodes(permittedNodes);
 
         ReplicatedEnvironmentFacade.ReplicationNodeImpl replicationNode = new ReplicatedEnvironmentFacade.ReplicationNodeImpl(TEST_NODE_NAME,
TEST_NODE_HOST_PORT);
@@ -674,7 +680,7 @@ public class ReplicatedEnvironmentFacade
     {
         ReplicatedEnvironmentFacade firstNode = createMaster();
 
-        int replica1Port = getNextAvailable(TEST_NODE_PORT + 1);
+        int replica1Port = _portHelper.getNextAvailable();
         String node1NodeHostPort = "localhost:" + replica1Port;
 
         Set<String> permittedNodes = new HashSet<String>();
@@ -705,7 +711,7 @@ public class ReplicatedEnvironmentFacade
             }
         };
         ReplicatedEnvironmentFacade firstNode = createMaster(listener);
-        int replica1Port = getNextAvailable(TEST_NODE_PORT + 1);
+        int replica1Port = _portHelper.getNextAvailable();
         String node1NodeHostPort = "localhost:" + replica1Port;
 
         Set<String> permittedNodes = new HashSet<String>();

Modified: qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java?rev=1626955&r1=1626954&r2=1626955&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java
(original)
+++ qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java
Tue Sep 23 06:55:34 2014
@@ -36,6 +36,7 @@ import org.apache.qpid.server.logging.me
 import org.apache.qpid.server.model.ConfiguredObject;
 import org.apache.qpid.server.model.SystemConfig;
 import org.apache.qpid.server.store.berkeleydb.NoopConfigurationChangeListener;
+import org.apache.qpid.test.utils.PortHelper;
 import org.apache.qpid.test.utils.QpidTestCase;
 import org.hamcrest.Description;
 import org.mockito.ArgumentMatcher;
@@ -47,6 +48,7 @@ public class BDBHAVirtualHostNodeOperati
 {
     private BDBHAVirtualHostNodeTestHelper _helper;
     private EventLogger _eventLogger;
+    private PortHelper _portHelper = new PortHelper();
 
     @Override
     protected void setUp() throws Exception
@@ -69,11 +71,13 @@ public class BDBHAVirtualHostNodeOperati
         {
             super.tearDown();
         }
+
+        _portHelper.waitUntilAllocatedPortsAreFree();
     }
 
     public void testCreate() throws Exception
     {
-        int node1PortNumber = findFreePort();
+        int node1PortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";
@@ -97,7 +101,7 @@ public class BDBHAVirtualHostNodeOperati
 
     public void testDelete() throws Exception
     {
-        int node1PortNumber = findFreePort();
+        int node1PortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";
@@ -118,7 +122,7 @@ public class BDBHAVirtualHostNodeOperati
 
     public void testSetPriority() throws Exception
     {
-        int node1PortNumber = findFreePort();
+        int node1PortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";
@@ -141,7 +145,7 @@ public class BDBHAVirtualHostNodeOperati
 
     public void testSetQuorumOverride() throws Exception
     {
-        int node1PortNumber = findFreePort();
+        int node1PortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";
@@ -164,7 +168,7 @@ public class BDBHAVirtualHostNodeOperati
 
     public void testSetDesignatedPrimary() throws Exception
     {
-        int node1PortNumber = findFreePort();
+        int node1PortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";
@@ -187,8 +191,8 @@ public class BDBHAVirtualHostNodeOperati
 
     public void testRemoteNodeAdded() throws Exception
     {
-        int node1PortNumber = findFreePort();
-        int node2PortNumber = getNextAvailable(node1PortNumber + 1);
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";
@@ -215,8 +219,8 @@ public class BDBHAVirtualHostNodeOperati
 
     public void testRemoteNodeRemoved() throws Exception
     {
-        int node1PortNumber = findFreePort();
-        int node2PortNumber = getNextAvailable(node1PortNumber + 1);
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";
@@ -247,8 +251,8 @@ public class BDBHAVirtualHostNodeOperati
 
     public void testRemoteNodeDetached() throws Exception
     {
-        int node1PortNumber = findFreePort();
-        int node2PortNumber = getNextAvailable(node1PortNumber + 1);
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";
@@ -299,8 +303,8 @@ public class BDBHAVirtualHostNodeOperati
 
     public void testRemoteNodeReAttached() throws Exception
     {
-        int node1PortNumber = findFreePort();
-        int node2PortNumber = getNextAvailable(node1PortNumber + 1);
+        int node1PortNumber = _portHelper.getNextAvailable();
+        int node2PortNumber = _portHelper.getNextAvailable();
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
         String nodeName = "node1";

Modified: qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java?rev=1626955&r1=1626954&r2=1626955&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java
(original)
+++ qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java
Tue Sep 23 06:55:34 2014
@@ -102,10 +102,10 @@ public class BDBHAVirtualHostNodeTestHel
                         firstException = e;
                     }
                 }
-                if (firstException != null)
-                {
-                    throw firstException;
-                }
+            }
+            if (firstException != null)
+            {
+                throw firstException;
             }
         }
         finally

Modified: qpid/trunk/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java?rev=1626955&r1=1626954&r2=1626955&view=diff
==============================================================================
--- qpid/trunk/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java
(original)
+++ qpid/trunk/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java
Tue Sep 23 06:55:34 2014
@@ -21,6 +21,8 @@ package org.apache.qpid.test.utils;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
+import java.util.HashSet;
+import java.util.NoSuchElementException;
 import java.util.Set;
 
 import org.apache.log4j.Logger;
@@ -29,10 +31,72 @@ public class PortHelper
 {
     private static final Logger _logger = Logger.getLogger(PortHelper.class);
 
+    public static final int START_PORT_NUMBER = 10000;
+
     private static final int DEFAULT_TIMEOUT_MILLIS = 5000;
 
+    public static final int MIN_PORT_NUMBER = 1;
+    public static final int MAX_PORT_NUMBER = 49151;
+
     private int _timeout = DEFAULT_TIMEOUT_MILLIS;
 
+
+    private final Set<Integer> _allocatedPorts = new HashSet<>();
+    private int _highestIssuedPort = -1;
+
+    /**
+     * Gets the next available port starting from given point.
+     *
+     * @param fromPort the port to scan for availability
+     * @throws java.util.NoSuchElementException if there are no ports available
+     */
+    public int getNextAvailable(int fromPort)
+    {
+        if ((fromPort < MIN_PORT_NUMBER) || (fromPort > MAX_PORT_NUMBER))
+        {
+            throw new IllegalArgumentException("Invalid start port: " + fromPort);
+        }
+
+        for (int i = fromPort; i <= MAX_PORT_NUMBER; i++)
+        {
+            if (isPortAvailable(i))
+            {
+                _allocatedPorts.add(i);
+                _highestIssuedPort = Math.max(_highestIssuedPort, i);
+                return i;
+            }
+        }
+
+        throw new NoSuchElementException("Could not find an available port above " + fromPort);
+    }
+
+    /**
+     * Gets the next available port that is higher than all other port numbers issued
+     * thus far.  If no port numbers have been issued, a default is used.
+     *
+     * @throws java.util.NoSuchElementException if there are no ports available
+     */
+    public int getNextAvailable()
+    {
+
+        if (_highestIssuedPort < 0)
+        {
+            return getNextAvailable(START_PORT_NUMBER);
+        }
+        else
+        {
+            return getNextAvailable(_highestIssuedPort + 1);
+        }
+    }
+
+    /**
+     * Tests that all ports allocated by getNextAvailable are free.
+     */
+    public void waitUntilAllocatedPortsAreFree()
+    {
+        waitUntilPortsAreFree(_allocatedPorts);
+    }
+
     public void waitUntilPortsAreFree(Set<Integer> ports)
     {
         _logger.debug("Checking if ports " + ports + " are free...");

Modified: qpid/trunk/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java?rev=1626955&r1=1626954&r2=1626955&view=diff
==============================================================================
--- qpid/trunk/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
(original)
+++ qpid/trunk/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
Tue Sep 23 06:55:34 2014
@@ -166,9 +166,6 @@ public class QpidTestCase extends TestCa
         return System.getProperty(VIRTUAL_HOST_NODE_CONTEXT_BLUEPRINT);
     }
 
-    public static final int MIN_PORT_NUMBER = 1;
-    public static final int MAX_PORT_NUMBER = 49151;
-
 
     /**
      * Gets the next available port starting at a port.
@@ -178,25 +175,12 @@ public class QpidTestCase extends TestCa
      */
     public int getNextAvailable(int fromPort)
     {
-        if ((fromPort < MIN_PORT_NUMBER) || (fromPort > MAX_PORT_NUMBER))
-        {
-            throw new IllegalArgumentException("Invalid start port: " + fromPort);
-        }
-
-        PortHelper portHelper = new PortHelper();
-        for (int i = fromPort; i <= MAX_PORT_NUMBER; i++)
-        {
-            if (portHelper.isPortAvailable(i)) {
-                return i;
-            }
-        }
-
-        throw new NoSuchElementException("Could not find an available port above " + fromPort);
+        return new PortHelper().getNextAvailable(fromPort);
     }
 
     public int findFreePort()
     {
-        return getNextAvailable(10000);
+        return new PortHelper().getNextAvailable();
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message