geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jasonhu...@apache.org
Subject incubator-geode git commit: [GEODE-384] Fix for failing tests: PRColocatedEquiJoinDUnitTest.testPRLocalQuerying and QueryREUpdateInProgressJUnitTest Refactor of GEODE-280 missed on comparing struct types
Date Tue, 06 Oct 2015 17:50:05 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/develop 2eb4e1750 -> 8087818d5


[GEODE-384] Fix for failing tests:
PRColocatedEquiJoinDUnitTest.testPRLocalQuerying and QueryREUpdateInProgressJUnitTest
Refactor of GEODE-280 missed on comparing struct types


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/8087818d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/8087818d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/8087818d

Branch: refs/heads/develop
Commit: 8087818d56b03784652898e4d6254516e660c2c6
Parents: 2eb4e17
Author: Jason Huynh <huynhja@gmail.com>
Authored: Tue Oct 6 10:50:24 2015 -0700
Committer: Jason Huynh <huynhja@gmail.com>
Committed: Tue Oct 6 10:53:17 2015 -0700

----------------------------------------------------------------------
 .../query/functional/StructSetOrResultsSet.java | 41 +++++++++++++++++++-
 1 file changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8087818d/gemfire-core/src/test/java/com/gemstone/gemfire/cache/query/functional/StructSetOrResultsSet.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/query/functional/StructSetOrResultsSet.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/query/functional/StructSetOrResultsSet.java
index d53c28b..7f3e14d 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/query/functional/StructSetOrResultsSet.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/query/functional/StructSetOrResultsSet.java
@@ -382,7 +382,7 @@ public class StructSetOrResultsSet extends TestCase {
       Object p1 = itert1.next();
       Object p2 = null;
       if (!checkOrder) {
-        if (!result2.contains(p1)) {
+        if (!collectionContains(result2, p1)) {
           fail("Atleast one element in the pair of SelectResults "
               + "supposedly identical, is not equal " + "Match not found for :"
               + p1 + " compared with:" + p2 + "; failed query=" + query + "; element unmatched
="
@@ -394,7 +394,7 @@ public class StructSetOrResultsSet extends TestCase {
         boolean matched = false;
         if (itert2.hasNext()) {
           p2 = itert2.next();
-          matched = (p2 == p1) || p2.equals(p1);
+          matched = objectsEqual(p1, p2);
           if (!matched) {
             fail("Order of results was not the same, match not found for :"
                 + p1 + " compared with:" + p2 + "; failed query=" + query + "; element unmatched
="
@@ -407,4 +407,41 @@ public class StructSetOrResultsSet extends TestCase {
       currentIndex ++;
     }
   }
+  
+  private boolean collectionContains(Collection collection, Object object) {
+    Iterator iterator = collection.iterator();
+    while (iterator.hasNext()) {
+      Object o = iterator.next();
+      if (objectsEqual(object, o)) {
+        return true;
+      }
+    }
+    return false;
+  }
+  
+  private boolean objectsEqual(Object o1, Object o2) {
+    //Assumed that o1 and o2 are the same object type as both are from collections created
by executing the same query
+    if (o1 instanceof Struct) {
+      //if o2 is null, an NPE will be thrown.
+      Object[] values1 = ((Struct) o1).getFieldValues();
+      Object[] values2 = ((Struct) o2).getFieldValues();
+      assertEquals(values1.length, values2.length);
+      boolean elementEqual = true;
+      for (int i = 0; i < values1.length; ++i) {
+        elementEqual = elementEqual
+            && ((values1[i] == values2[i]) || values1[i]
+                .equals(values2[i]));
+      }
+      if (elementEqual) {
+        return true;
+      }
+    } 
+    else {
+      //if o1 is null and o2 is not, an NPE will be thrown
+      if (o1 == o2 || o1.equals(o2)) {
+        return true;
+      }
+    }
+    return false;
+  }
 }


Mime
View raw message