Repository: qpid-broker-j
Updated Branches:
  refs/heads/master fb93bae63 -> fcad8ea35


QPID-7059: [Java System Tests] Fix racey BDBHAVirtualHostNodeRestTest test


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/fcad8ea3
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/fcad8ea3
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/fcad8ea3

Branch: refs/heads/master
Commit: fcad8ea35a8947116af59d6262520e146a59dc0f
Parents: fb93bae
Author: Keith Wall <kw...@apache.org>
Authored: Thu Oct 5 15:19:39 2017 +0100
Committer: Keith Wall <kw...@apache.org>
Committed: Fri Oct 6 09:07:19 2017 +0100

----------------------------------------------------------------------
 .../BDBHAVirtualHostNodeRestTest.java           | 33 +++++++-------------
 .../qpid/systest/rest/RestTestHelper.java       | 17 +++++++---
 2 files changed, 25 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/fcad8ea3/bdbstore/systests/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/BDBHAVirtualHostNodeRestTest.java
----------------------------------------------------------------------
diff --git 
a/bdbstore/systests/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/BDBHAVirtualHostNodeRestTest.java
 
b/bdbstore/systests/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/BDBHAVirtualHostNodeRestTest.java
index 372bb8c..0fde56f 100644
--- 
a/bdbstore/systests/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/BDBHAVirtualHostNodeRestTest.java
+++ 
b/bdbstore/systests/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/BDBHAVirtualHostNodeRestTest.java
@@ -293,7 +293,7 @@ public class BDBHAVirtualHostNodeRestTest extends 
QpidRestTestCase
                 break;
             }
             counter++;
-            Thread.sleep(100l);
+            Thread.sleep(100L);
         }
 
         //connect intruder node
@@ -337,7 +337,7 @@ public class BDBHAVirtualHostNodeRestTest extends 
QpidRestTestCase
 
     private Map<String, Object> createNodeAttributeMap(String nodeName, int 
nodePort, int helperPort) throws Exception
     {
-        Map<String, Object> nodeData = new HashMap<String, Object>();
+        Map<String, Object> nodeData = new HashMap<>();
         nodeData.put(BDBHAVirtualHostNode.NAME, nodeName);
         nodeData.put(BDBHAVirtualHostNode.TYPE, 
BDBHAVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
         nodeData.put(BDBHAVirtualHostNode.GROUP_NAME, _hostName);
@@ -390,35 +390,26 @@ public class BDBHAVirtualHostNodeRestTest extends 
QpidRestTestCase
 
     private void assertRemoteNodes(String masterNode, String... replicaNodes) 
throws Exception
     {
-        List<String> clusterNodes = new 
ArrayList<String>(Arrays.asList(replicaNodes));
+        List<String> clusterNodes = new 
ArrayList<>(Arrays.asList(replicaNodes));
         clusterNodes.add(masterNode);
 
         for (String clusterNodeName : clusterNodes)
         {
-            List<String> remotes = new ArrayList<String>(clusterNodes);
+            List<String> remotes = new ArrayList<>(clusterNodes);
             remotes.remove(clusterNodeName);
             for (String remote : remotes)
             {
                 String remoteUrl = "remotereplicationnode/" + clusterNodeName 
+ "/" + remote;
-                Map<String, Object> nodeData = 
_restTestHelper.waitForAttributeChanged(remoteUrl, 
BDBHARemoteReplicationNode.ROLE, remote.equals(masterNode) ? "MASTER" : 
"REPLICA");
-                assertRemoteNodeData(remote, nodeData);
+                String desiredNodeState = remote.equals(masterNode) ? "MASTER" 
: "REPLICA";
+                _restTestHelper.waitForAttributeChanged(remoteUrl,
+                                                        node -> 
desiredNodeState.equals(node.get(
+                                                                
BDBHARemoteReplicationNode.ROLE))
+                                                                && (Integer) 
node.get(BDBHAVirtualHostNode.LAST_KNOWN_REPLICATION_TRANSACTION_ID) > 0
+                                                                && ((Number) 
node.get(BDBHAVirtualHostNode.JOIN_TIME)).longValue() > 0L);
             }
         }
     }
 
-    private void assertRemoteNodeData(String name, Map<String, Object> 
nodeData)
-    {
-        assertEquals("Remote node " + name + " has unexpected name", name, 
nodeData.get(BDBHAVirtualHostNode.NAME));
-
-        Integer lastKnownTransactionId = (Integer) 
nodeData.get(BDBHAVirtualHostNode.LAST_KNOWN_REPLICATION_TRANSACTION_ID);
-        assertNotNull("Node " + name + " has unexpected 
lastKnownReplicationId", lastKnownTransactionId);
-        assertTrue("Node " + name + " has unexpected lastKnownReplicationId " 
+ lastKnownTransactionId, lastKnownTransactionId > 0);
-
-        Number joinTime = (Number) 
nodeData.get(BDBHAVirtualHostNode.JOIN_TIME);
-        assertNotNull("Node " + name + " has unexpected joinTime", joinTime);
-        assertTrue("Node " + name + " has unexpected joinTime " + joinTime, 
joinTime.longValue() > 0);
-     }
-
     private void assertActualAndDesiredStates(final String restUrl,
                                               final String 
expectedDesiredState,
                                               final String 
expectedActualState) throws IOException
@@ -429,7 +420,7 @@ public class BDBHAVirtualHostNodeRestTest extends 
QpidRestTestCase
 
     private void mutateDesiredState(final String restUrl, final String 
newState) throws IOException
     {
-        Map<String, Object> newAttributes = new HashMap<String, Object>();
+        Map<String, Object> newAttributes = new HashMap<>();
         newAttributes.put(VirtualHostNode.DESIRED_STATE, newState);
 
         getRestTestHelper().submitRequest(restUrl, "PUT", newAttributes, 
HttpServletResponse.SC_OK);
@@ -468,7 +459,7 @@ public class BDBHAVirtualHostNodeRestTest extends 
QpidRestTestCase
             }
             if (newMasterData == null)
             {
-                Thread.sleep(100l);
+                Thread.sleep(100L);
                 counter++;
             }
         }

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/fcad8ea3/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java
----------------------------------------------------------------------
diff --git 
a/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java 
b/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java
index b4f474a..4ba8687 100644
--- a/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java
+++ b/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java
@@ -38,6 +38,7 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.function.Predicate;
 
 import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.KeyManager;
@@ -662,16 +663,24 @@ public class RestTestHelper
                                                        String attributeName,
                                                        Object newValue) throws 
Exception
     {
+        return waitForAttributeChanged(url, (attr -> 
newValue.equals(attr.get(attributeName))));
+
+    }
+
+    public Map<String, Object> waitForAttributeChanged(String url,
+                                                       Predicate<Map<String, 
Object>> attributePredicate) throws Exception
+    {
         Map<String, Object> nodeAttributes = 
getAttributesIgnoringNotFound(url);
         int timeout = 30000;
         long limit = System.currentTimeMillis() + timeout;
-        while(System.currentTimeMillis() < limit && (nodeAttributes == null|| 
!newValue.equals(nodeAttributes.get(attributeName))))
+        while(System.currentTimeMillis() < limit && (nodeAttributes == null || 
!attributePredicate.test(nodeAttributes)))
         {
-            Thread.sleep(100l);
+            Thread.sleep(100L);
             nodeAttributes = getAttributesIgnoringNotFound(url);
         }
-        Assert.assertEquals("Attribute " + attributeName + " did not reach 
expected value within permitted timeout " + timeout + "ms.", newValue, 
nodeAttributes
-                .get(attributeName));
+        Assert.assertTrue(String.format("Attributes predicate not satisfied 
after %d ms.  Last attribute state state : %s",
+                                          timeout,
+                                          nodeAttributes), 
attributePredicate.test(nodeAttributes));
         return nodeAttributes;
     }
 


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

Reply via email to