You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2015/11/02 22:53:00 UTC

[34/50] [abbrv] incubator-geode git commit: GEODE-376: fix race in waiting for serializer

GEODE-376: fix race in waiting for serializer

This also fixes GEODE-400, GEODE-455, GEODE-457,
GEODE-470, GEODE-472, and GEODE-476.


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

Branch: refs/heads/feature/GEODE-328
Commit: f0bd8b04afe226f5878b0f27636f507b330b8d35
Parents: 4a42443
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Fri Oct 23 09:58:27 2015 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Fri Oct 23 11:17:57 2015 -0700

----------------------------------------------------------------------
 .../internal/InternalDataSerializer.java        |  6 ++--
 .../gemfire/cache30/MultiVMRegionTestCase.java  | 38 ++++++++++++--------
 2 files changed, 27 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f0bd8b04/gemfire-core/src/main/java/com/gemstone/gemfire/internal/InternalDataSerializer.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/InternalDataSerializer.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/InternalDataSerializer.java
index 27ba141..ca1fe68 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/InternalDataSerializer.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/InternalDataSerializer.java
@@ -3384,14 +3384,16 @@ public abstract class InternalDataSerializer extends DataSerializer implements D
    * updates.  If the serialized bytes arrive at a VM before the
    * registration message does, the deserializer will wait an amount
    * of time for the registration message to arrive.
+   * Made public for unit test access.
    * @since 5.7
    */
-  static class GetMarker extends Marker {
+  public static class GetMarker extends Marker {
     /**
      * Number of milliseconds to wait. Also used by InternalInstantiator.
      * Note that some tests set this to a small amount to speed up failures.
+     * Made public for unit test access.
      */
-    static int WAIT_MS = Integer.getInteger("gemfire.InternalDataSerializer.WAIT_MS", 60 * 1000);
+    public static int WAIT_MS = Integer.getInteger("gemfire.InternalDataSerializer.WAIT_MS", 60 * 1000);
 
     /**
      * Returns the serializer associated with this marker.  If the

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f0bd8b04/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java
index b6b4c10..06e8166 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/MultiVMRegionTestCase.java
@@ -5410,8 +5410,6 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
 
     final String name = this.getUniqueName();
 
-    disconnectAllFromDS(); // possible fix for GEODE-376
-
     SerializableRunnable create =
       new CacheSerializableRunnable("Create Region") {
           public void run2() throws CacheException {
@@ -5465,21 +5463,31 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
     SerializableRunnable get = new CacheSerializableRunnable("Get int") {
         public void run2() throws CacheException {
           Region region = getRootRegion().getSubregion(name);
-//          if (region.getAttributes().getScope().isDistributedNoAck()) {
-            // wait a while for the serializer to be registered
-            long end = System.currentTimeMillis() + 30000;
-            while (InternalDataSerializer.getSerializer((byte)120) == null) {
-              assertTrue("This test sometimes fails due to timing issues",
-                  System.currentTimeMillis() <= end);
-              try {
-                Thread.sleep(1000);
+          // wait a while for the serializer to be registered
+          // A race condition exists in the product in which
+          // this thread can be stuck waiting in getSerializer
+          // for 60 seconds. So it only calls getSerializer once
+          // causing it to fail intermittently (see GEODE-376).
+          // To workaround this the test wets WAIT_MS to 1 ms.
+          // So the getSerializer will only block for 1 ms.
+          // This allows the WaitCriterion to make multiple calls
+          // of getSerializer and the subsequent calls will find
+          // the DataSerializer.
+          final int savVal = InternalDataSerializer.GetMarker.WAIT_MS;
+          InternalDataSerializer.GetMarker.WAIT_MS = 1;
+          try {
+            WaitCriterion ev = new WaitCriterion() {
+              public boolean done() {
+                return InternalDataSerializer.getSerializer((byte)120) != null;
               }
-              catch (InterruptedException e) {
-                // no need to keep interrupt bit here
-                throw new CacheException("Test interrupted") { };
+              public String description() {
+                return "DataSerializer with id 120 was never registered";
               }
-            }
-//          }
+            };
+            DistributedTestCase.waitForCriterion(ev, 30 * 1000, 10, true);
+          } finally {
+            InternalDataSerializer.GetMarker.WAIT_MS = savVal;
+          }
           IntWrapper value = (IntWrapper) region.get(key);
           assertNotNull(InternalDataSerializer.getSerializer((byte)120));
           assertNotNull(value);