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: refactored test code Added additional debugging on failure Removed excessive logging during test runs
Date Wed, 26 Aug 2015 18:57:33 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-280 [created] 25ddd4e27


refactored test code
Added additional debugging on failure
Removed excessive logging during test runs


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

Branch: refs/heads/feature/GEODE-280
Commit: 25ddd4e27651773f8eb71ec82bb9b99d7e21e051
Parents: eeb7ae1
Author: Jason Huynh <huynhja@gmail.com>
Authored: Wed Aug 26 11:54:32 2015 -0700
Committer: Jason Huynh <huynhja@gmail.com>
Committed: Wed Aug 26 11:54:32 2015 -0700

----------------------------------------------------------------------
 .../query/functional/StructSetOrResultsSet.java | 223 +++++++------------
 1 file changed, 75 insertions(+), 148 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/25ddd4e2/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 3593db0..d53c28b 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
@@ -64,29 +64,9 @@ public class StructSetOrResultsSet extends TestCase {
 
     Collection coll1 = null;
     Collection coll2 = null;
-    Iterator itert1 = null;
-    Iterator itert2 = null;
-    ObjectType type1, type2;
     for (int j = 0; j < len; j++) {
-      type1 = ((SelectResults) r[j][0]).getCollectionType().getElementType();
-      type2 = ((SelectResults) r[j][1]).getCollectionType().getElementType();
-      if ((type1.getClass().getName()).equals(type2.getClass().getName())) {
-        CacheUtils.log("Both SelectResults are of the same Type i.e.--> "
-            + ((SelectResults) r[j][0]).getCollectionType().getElementType());
-      } else {
-        CacheUtils.log("Classes are : " + type1.getClass().getName() + " "
-            + type2.getClass().getName());
-        fail("FAILED:Select result Type is different in both the cases."
-            + "; failed query=" + queries[j]);
-      }
-      if (((SelectResults) r[j][0]).size() == ((SelectResults) r[j][1]).size()) {
-        CacheUtils.log("Both SelectResults are of Same Size i.e.  Size= "
-            + ((SelectResults) r[j][1]).size());
-      } else {
-        fail("FAILED:SelectResults size is different in both the cases. Size1="
-            + ((SelectResults) r[j][0]).size() + " Size2 = "
-            + ((SelectResults) r[j][1]).size() + "; failed query=" + queries[j]);
-      }
+      checkSelectResultTypes((SelectResults)r[j][0], (SelectResults)r[j][1], queries[j]);
+      checkResultSizes((SelectResults)r[j][0], (SelectResults)r[j][1], queries[j]);
       
       if (checkOrder) {
         coll2 = (((SelectResults) r[j][1]).asList());
@@ -95,47 +75,7 @@ public class StructSetOrResultsSet extends TestCase {
         coll2 = (((SelectResults) r[j][1]).asSet());
         coll1 = (((SelectResults) r[j][0]).asSet());
       }
-      // boolean pass = true;
-      itert1 = coll1.iterator();
-      itert2 = coll2.iterator();
-      while (itert1.hasNext()) {
-        Object p1 = itert1.next();
-        if (!checkOrder) {
-          itert2 = coll2.iterator();
-        }
-
-        boolean exactMatch = false;
-        while (itert2.hasNext()) {
-          Object p2 = itert2.next();
-          if (p1 instanceof Struct) {
-            Object[] values1 = ((Struct) p1).getFieldValues();
-            Object[] values2 = ((Struct) p2).getFieldValues();
-            assertEquals(values1.length, values2.length);
-            boolean elementEqual = true;
-            for (int i = 0; i < values1.length; ++i) {
-              // CacheUtils.log("Comparing: " + values1[i] + " with: " +
-              // values2[i]);
-              elementEqual = elementEqual
-                  && ((values1[i] == values2[i]) || values1[i]
-                      .equals(values2[i]));
-            }
-            exactMatch = elementEqual;
-          } else {
-            // CacheUtils.log("Comparing: " + p1 + " with: " + p2);
-            exactMatch = (p2 == p1) || p2.equals(p1);
-          }
-          if (exactMatch || checkOrder) {
-            break;
-          }
-        }
-        if (!exactMatch) {
-          fail("Atleast one element in the pair of SelectResults "
-              + "supposedly identical, is not equal " + "Match not found for :"
-              + p1 + "; failed query=" + queries[j] + "; element unmatched ="
-              + p1 + ";p1 class=" + p1.getClass() + " ; other set has ="
-              + coll2);
-        }
-      }
+      compareResults(coll1, coll2, queries[j], checkOrder);
     }
   }
 
@@ -357,38 +297,10 @@ public class StructSetOrResultsSet extends TestCase {
       assertEquals(queries[j], 1, result1.size());
       assertEquals(queries[j], 1, result2.size());
 
-      if ((result1.asList().get(0).getClass().getName()).equals(result2
-          .asList().get(0).getClass().getName())) {
-        CacheUtils.log("Both SelectResults are of the same Type i.e.--> "
-            + ((SelectResults) r[j][0]).getCollectionType().getElementType());
-      } else {
-        fail("FAILED:Select result Type is different in both the cases."
-            + "; failed query=" + queries[j]);
-      }
-
-      if (((SelectResults) r[j][0]).size() == ((SelectResults) r[j][1]).size()) {
-        CacheUtils.log("Both SelectResults are of Same Size i.e.  Size= "
-            + ((SelectResults) r[j][1]).size());
-      } else {
-        fail("FAILED:SelectResults size is different in both the cases. Size1="
-            + ((SelectResults) r[j][0]).size() + " Size2 = "
-            + ((SelectResults) r[j][1]).size() + "; failed query=" + queries[j]);
-      }
-
-      // boolean pass = true;
-      itert1 = result1.iterator();
-      itert2 = result2.iterator();
-      while (itert1.hasNext()) {
-        Integer p1 = itert1.next();
-        Integer p2 = itert2.next();
-        CacheUtils.log("result1: " + p1 + "result2: " + p2);
-        exactMatch &= p1.intValue() == p2.intValue();
-
-      }
-      if (!exactMatch) {
-        fail("Atleast one element in the pair of SelectResults supposedly identical, is not
equal "
-            + "; failed query=" + queries[j]);
-      }
+      
+      checkSelectResultTypes((SelectResults) r[j][0], (SelectResults) r[j][1], queries[j]);
+      checkResultSizes((SelectResults) r[j][0], (SelectResults) r[j][1], queries[j]);
+      compareResults(result1, result2, queries[j], true);
     }
   }
 
@@ -413,71 +325,86 @@ public class StructSetOrResultsSet extends TestCase {
     Integer count1, count2;
     Iterator<Integer> itert1, itert2;
     ArrayList result1, result2;
+
     for (int j = 0; j < len; j++) {
       result1 = ((ArrayList) r[j][0]);
       result2 = ((ArrayList) r[j][1]);
       result1.trimToSize();
       result2.trimToSize();
-      // assertFalse(queries[j], result1.size()==0);
-      // assertFalse(queries[j], result2.size()==0);
-
-      if (checkClass) {
-        if ((result1.get(0).getClass().getName()).equals(result2.get(0)
-            .getClass().getName())) {
-          CacheUtils.log("Both SelectResults are of the same Type i.e.--> "
-              + result1.get(0).getClass().getName());
-        } else {
-          fail("FAILED:Select result Type is different in both the cases."
-              + result1.get(0).getClass().getName() + "and"
-              + result1.get(0).getClass().getName() + "; failed query="
-              + queries[j]);
-        }
-      }
-
-      if (result1.size() == result2.size()) {
-        CacheUtils.log("Both SelectResults are of Same Size i.e.  Size= "
-            + result2.size());
+    
+      compareQueryResultLists(result1, result2, len, checkOrder, checkClass, queries[j]);
+    }
+  }
+  
+  public void compareQueryResultLists(List r1, List r2,
+      int len, boolean checkOrder, boolean checkClass, String query) {
+    if (checkClass) {
+      if ((r1.get(0).getClass().getName()).equals(r2.get(0)
+          .getClass().getName())) {
+        CacheUtils.log("Both SelectResults are of the same Type i.e.--> "
+            + r1.get(0).getClass().getName());
       } else {
-        fail("FAILED:SelectResults size is different in both the cases. Size1="
-            + result1.size() + " Size2 = " + result2.size() + "; failed query="
-            + queries[j]);
+        fail("FAILED:Select result Type is different in both the cases."
+            + r1.get(0).getClass().getName() + "and"
+            + r1.get(0).getClass().getName() + "; failed query="
+            + query);
       }
+    }
 
-      // boolean pass = true;
-      itert1 = result1.iterator();
-      itert2 = result2.iterator();
-      while (itert1.hasNext()) {
-        Object p1 = itert1.next();
-        if (!checkOrder) {
-          itert2 = result2.iterator();
+    checkResultSizes(r1, r2, query);
+    compareResults(r1, r2, query, checkOrder);
+  }
+  
+  private void checkSelectResultTypes(SelectResults r1, SelectResults r2, String query) {
+    ObjectType type1, type2;
+    type1 = r1.getCollectionType().getElementType();
+    type2 = r2.getCollectionType().getElementType();
+    if (!(type1.getClass().getName()).equals(type2.getClass().getName())) {
+      CacheUtils.log("Classes are : " + type1.getClass().getName() + " " + type2.getClass().getName());
+      fail("FAILED:Select result Type is different in both the cases." + "; failed query="
+ query);
+    }
+  }
+  
+  private void checkResultSizes(Collection r1, Collection r2, String query) {
+    if (r1.size() != r2.size()) {
+      fail("FAILED:SelectResults size is different in both the cases. Size1="
+          + ((SelectResults) r1).size() + " Size2 = "
+          + ((SelectResults) r2).size() + "; failed query=" + query);
+    }
+  }
+  
+  
+  private void compareResults(Collection result1, Collection result2, String query, boolean
checkOrder) {
+    Iterator itert1 = result1.iterator();
+    Iterator itert2 = result2.iterator();
+    int currentIndex = 0;
+    while (itert1.hasNext()) {
+      Object p1 = itert1.next();
+      Object p2 = null;
+      if (!checkOrder) {
+        if (!result2.contains(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
="
+              + p1 + ";p1 class=" + p1.getClass() + " ; other set has ="
+              + result2);
         }
-
-        boolean exactMatch = false;
-        while (itert2.hasNext()) {
-          Object p2 = itert2.next();
-          if (p1 instanceof Struct) {
-            Object[] values1 = ((Struct) p1).getFieldValues();
-            Object[] values2 = ((Struct) p2).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]));
-            }
-            exactMatch = elementEqual;
-          } else {
-            exactMatch = (p2 == p1) || p2.equals(p1);
-          }
-          if (exactMatch || checkOrder) {
-            break;
+      }
+      else {
+        boolean matched = false;
+        if (itert2.hasNext()) {
+          p2 = itert2.next();
+          matched = (p2 == p1) || p2.equals(p1);
+          if (!matched) {
+            fail("Order of results was not the same, match not found for :"
+                + p1 + " compared with:" + p2 + "; failed query=" + query + "; element unmatched
="
+                + p1 + ";p1 class=" + p1.getClass() + " compared with " + p2 + ";p2 class="
+ p2.getClass()
+                + "currentIndex:" + currentIndex 
+                + "\nr1:" + result1 + "\n\nr2:" + result2);
           }
         }
-        if (!exactMatch) {
-          fail("Atleast one element in the pair of SelectResults supposedly identical, is
not equal "
-              + "; failed query=" + queries[j]);
-        }
       }
+      currentIndex ++;
     }
   }
 }


Mime
View raw message