GEODE-2026: fix flaky test

The test was initializing a value to a String,
then starting an async thread that would keep
changing it to an int,
it slept for 100ms and then assummed that the async
thread had changed the value to an Integer.
In rare cases the thread never was able to to its first
put so the value was still a String.

The test now waits for the async thread to change the value
to an Integer instead of doing a 100ms sleep.


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

Branch: refs/heads/feature/GEM-983
Commit: cd06c8c19edc554a712859aa41243d39d5f0da09
Parents: af6a18c
Author: Darrel Schneider <[email protected]>
Authored: Mon Oct 24 16:15:04 2016 -0700
Committer: Darrel Schneider <[email protected]>
Committed: Tue Oct 25 10:42:29 2016 -0700

----------------------------------------------------------------------
 .../PersistentPartitionedRegionDUnitTest.java        | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd06c8c1/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionDUnitTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionDUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionDUnitTest.java
index 5ca3d01..9479883 100644
--- 
a/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionDUnitTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionDUnitTest.java
@@ -1628,7 +1628,20 @@ public class PersistentPartitionedRegionDUnitTest 
extends PersistentPartitionedR
 
     AsyncInvocation asyncCreate = vm0.invokeAsync(createData);
 
-    Thread.sleep(100);
+    SerializableCallable waitForIntValue = new SerializableCallable() {
+      public Object call() {
+        Cache cache = getCache();
+        Region region = cache.getRegion(PR_REGION_NAME);
+        // The value is initialized as a String so wait
+        // for it to be changed to an Integer.
+        await().atMost(60, SECONDS).until(() -> {
+          return region.get(0) instanceof Integer;
+        });
+        return region.get(0);
+      }
+    };
+    vm0.invoke(waitForIntValue);
+    vm1.invoke(waitForIntValue);
 
     AsyncInvocation close0 = closeCacheAsync(vm0);
     AsyncInvocation close1 = closeCacheAsync(vm1);

Reply via email to