GEODE-2820: Added awaitlity clause to wait for the index size to be correct

        * Added awaitility clause to wait for all the indexes to have all the 
entries
        * This is done to make sure that the queries are executed after the 
indexes are ready.

        This closes #588


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

Branch: refs/heads/feature/GEODE-3062-2
Commit: 822946b9ddc426b45857c6b3919cd0b8b5a98406
Parents: 43b00bd
Author: nabarun <n...@pivotal.io>
Authored: Thu Jun 15 16:32:46 2017 -0700
Committer: nabarun <n...@pivotal.io>
Committed: Wed Jun 21 15:12:49 2017 -0700

----------------------------------------------------------------------
 .../dunit/QueryIndexUsingXMLDUnitTest.java      | 30 +++++++++++++++++---
 1 file changed, 26 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/822946b9/geode-core/src/test/java/org/apache/geode/cache/query/dunit/QueryIndexUsingXMLDUnitTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/cache/query/dunit/QueryIndexUsingXMLDUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/cache/query/dunit/QueryIndexUsingXMLDUnitTest.java
index 83f1da3..e08b019 100644
--- 
a/geode-core/src/test/java/org/apache/geode/cache/query/dunit/QueryIndexUsingXMLDUnitTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/cache/query/dunit/QueryIndexUsingXMLDUnitTest.java
@@ -21,6 +21,7 @@ import static org.apache.geode.test.dunit.Invoke.*;
 import static org.apache.geode.test.dunit.LogWriterUtils.*;
 import static org.assertj.core.api.Assertions.*;
 import static org.awaitility.Awaitility.*;
+import static org.junit.Assert.assertEquals;
 
 import java.io.File;
 import java.net.URL;
@@ -28,8 +29,10 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.io.FileUtils;
+import org.awaitility.Awaitility;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -473,11 +476,7 @@ public class QueryIndexUsingXMLDUnitTest extends 
JUnit4CacheTestCase {
 
   /**
    * Creates async indexes and compares the results between index and 
non-index results.
-   * <p>
-   * DISABLED. This test is disabled due to a high rate of throw new 
AssertionError. See ticket
-   * #52167
    */
-  @Ignore("TODO: test is disabled because of #52167")
   @Test
   public void testCreateAsyncIndexWhileDoingGIIAndCompareQueryResults() throws 
Exception {
     Host host = Host.getHost(0);
@@ -510,11 +509,34 @@ public class QueryIndexUsingXMLDUnitTest extends 
JUnit4CacheTestCase {
     vm1.invoke(prIndexCreationCheck(PERSISTENT_REG_NAME, "secIndex", 50));
     vm1.invoke(indexCreationCheck(REP_REG_NAME, "secIndex"));
 
+    vm0.invoke(() -> validateIndexSize());
+    vm1.invoke(() -> validateIndexSize());
+
+
     // Execute query and verify index usage
     vm0.invoke(executeQueryAndCompareResult(false));
     vm1.invoke(executeQueryAndCompareResult(false));
   }
 
+  public void validateIndexSize() {
+    Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
+      boolean indexSizeCheck_NAME = validateIndexSizeForRegion(NAME);
+      boolean indexSizeCheck_REP_REG_NAME = 
validateIndexSizeForRegion(REP_REG_NAME);
+      boolean indexSizeCheck_PERSISTENT_REG_NAME = 
validateIndexSizeForRegion(PERSISTENT_REG_NAME);
+      assertEquals("Index does not contain all the entries after 60 seconds 
have elapsed ", true,
+          (indexSizeCheck_NAME && indexSizeCheck_REP_REG_NAME
+              && indexSizeCheck_PERSISTENT_REG_NAME));
+    });
+  }
+
+  private boolean validateIndexSizeForRegion(final String regionName) {
+    Region region = getCache().getRegion(regionName);
+    QueryService queryService = getCache().getQueryService();
+    return queryService.getIndex(region, 
"statusIndex").getStatistics().getNumberOfValues() == 500
+        && queryService.getIndex(region, 
"idIndex").getStatistics().getNumberOfValues() == 500
+        && queryService.getIndex(region, 
"statusIndex").getStatistics().getNumberOfValues() == 500;
+  }
+
   @Test
   public void 
testIndexCreationForReplicatedPersistentOverFlowRegionOnRestart() throws 
Exception {
     Host host = Host.getHost(0);

Reply via email to