geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bschucha...@apache.org
Subject [47/50] [abbrv] incubator-geode git commit: GEODE-156: fix unit tests that call pauseIfNecessary
Date Mon, 27 Jul 2015 23:20:10 GMT
GEODE-156: fix unit tests that call pauseIfNecessary

all calls to pauseIfNecessary have been changed to flushIfNecessary.
The new flushIfNecessary method uses StateFlushOperation.


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

Branch: refs/heads/feature/GEODE-77
Commit: 73d0dcd2ae7c4d3ffcd490472d88faf3ec264885
Parents: 27b37ef
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Fri Jul 24 11:39:40 2015 -0700
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Mon Jul 27 09:53:55 2015 -0700

----------------------------------------------------------------------
 .../gemfire/cache30/CacheLoaderTestCase.java    |   2 +-
 .../DistributedNoAckRegionDUnitTest.java        |  14 +++
 .../gemfire/cache30/MultiVMRegionTestCase.java  | 122 +++++++++----------
 .../gemfire/cache30/RegionTestCase.java         |   8 ++
 4 files changed, 80 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/73d0dcd2/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheLoaderTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheLoaderTestCase.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheLoaderTestCase.java
index 5262ed2..ea06e13 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheLoaderTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheLoaderTestCase.java
@@ -153,9 +153,9 @@ public abstract class CacheLoaderTestCase
 ////        factory.setCacheLoader(remoteloader);
 //        Region rgn = createRegion(name);
 //        rgn.put(key, value);
+//        flushIfNecessary(rgn);
 //      }
 //    });
-//    pauseIfNecessary();
 //
 //
 //    assertEquals(value, region.get(key));

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/73d0dcd2/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/DistributedNoAckRegionDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/DistributedNoAckRegionDUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/DistributedNoAckRegionDUnitTest.java
index 733ba81..b9f5104 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/DistributedNoAckRegionDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/DistributedNoAckRegionDUnitTest.java
@@ -8,7 +8,11 @@
 package com.gemstone.gemfire.cache30;
 
 import java.util.*;
+
 import com.gemstone.gemfire.cache.*;
+import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
+import com.gemstone.gemfire.internal.cache.DistributedRegion;
+import com.gemstone.gemfire.internal.cache.StateFlushOperation;
 
 import dunit.*;
 
@@ -254,20 +258,30 @@ public class DistributedNoAckRegionDUnitTest
    }
   }
 
+  @Override
   protected void pauseIfNecessary(int ms) {
     pause(ms);
   }
   
+  @Override
   protected void pauseIfNecessary() {
     pause();
   }
 
+  @Override
+  protected void flushIfNecessary(Region r) {
+    DistributedRegion dr = (DistributedRegion)r;
+    Set<InternalDistributedMember> targets = dr.getDistributionAdvisor().adviseCacheOp();
+    StateFlushOperation.flushTo(targets, dr);
+  }
+
   /**
    * The number of milliseconds to try repeating validation code in the
    * event that AssertionFailedError is thrown.  For DISTRIBUTED_NO_ACK 
    * scopes, a repeat timeout is used to account for the fact that a
    * previous operation may have not yet completed.
    */
+  @Override
   protected long getRepeatTimeoutMs() {
     return 5000;
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/73d0dcd2/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 d0acc4d..5e605dd 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
@@ -371,23 +371,21 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
             Region region =
               getRootRegion().getSubregion(name);
             region.put(key, oldValue);
+            flushIfNecessary(region);
           }
       };
 
     vm0.invoke(put);
     vm1.invoke(put);
 
-    pauseIfNecessary();
-
     vm0.invoke(new CacheSerializableRunnable("Update") {
         public void run2() throws CacheException {
           Region region = getRootRegion().getSubregion(name);
           region.put(key, newValue);
+          flushIfNecessary(region);
         }
       });
 
-    pauseIfNecessary();
-
     vm1.invoke(new CacheSerializableRunnable("Validate update") {
         public void run2() throws CacheException {
           Region region = getRootRegion().getSubregion(name);
@@ -456,6 +454,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
                 }
               }
             });
+          flushIfNecessary(region);
         }
       });
     AsyncInvocation ai1 =
@@ -479,8 +478,6 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
           }
         });
 
-    pauseIfNecessary();
-
     AsyncInvocation ai0 =
       vm0.invokeAsync(new CacheSerializableRunnable("Populate") {
           public void run2() throws CacheException {
@@ -678,13 +675,8 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
 
     vm0.invoke(create);
     vm1.invoke(create);
-
-    // vm2 is on a different gemfire system
     vm2.invoke(create);
 
-
-    Thread.sleep(250);
-
     final Object key = "KEY";
     final Object value = "VALUE";
 
@@ -697,6 +689,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
             region.put(key, value);
             assertTrue(!region.isDestroyed());
             assertTrue(!region.getParentRegion().isDestroyed());
+            flushIfNecessary(region);
           }
         };
 
@@ -720,13 +713,12 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
     vm1.invoke(verifyPut);
     vm2.invoke(verifyPut);
 
-    pauseIfNecessary(500);
-
     vm0.invoke(new CacheSerializableRunnable("Destroy Entry") {
         public void run2() throws CacheException {
           Region region =
             getRootRegion().getSubregion(name);
           region.destroy(key);
+          flushIfNecessary(region);
         }
       });
 
@@ -740,9 +732,9 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
             assertNull(region.getEntry(key));
           }
         };
-    invokeRepeatingIfNecessary(vm0, verifyDestroy);
-    invokeRepeatingIfNecessary(vm1, verifyDestroy);
-    invokeRepeatingIfNecessary(vm2, verifyDestroy);
+    vm0.invoke(verifyDestroy);
+    vm1.invoke(verifyDestroy);
+    vm2.invoke(verifyDestroy);
   }
 
   /**
@@ -773,11 +765,10 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
           Region region =
             getRootRegion().getSubregion(name);
           region.destroyRegion();
+          flushIfNecessary(region);
         }
       });
 
-    pauseIfNecessary(400);
-
     invokeInEveryVM(new CacheSerializableRunnable("Verify region destruction") {
       public void run2() throws CacheException {
         WaitCriterion ev = new WaitCriterion() {
@@ -788,7 +779,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
             return "Waiting for region " + name + " to be destroyed";
           }
         };
-        DistributedTestCase.waitForCriterion(ev, 60 * 1000, 200, true);
+        DistributedTestCase.waitForCriterion(ev, 60 * 1000, 10, true);
         Region region = getRootRegion().getSubregion(name);
         assertNull(region);
       }
@@ -948,6 +939,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
             Region region =
               getRootRegion().getSubregion(name);
             region.put(key, value);
+            flushIfNecessary(region);
           }
         };
 
@@ -955,13 +947,12 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
     vm1.invoke(put);
     vm2.invoke(put);
 
-    pauseIfNecessary(500);
-
     vm0.invoke(new CacheSerializableRunnable("Invalidate Entry") {
         public void run2() throws CacheException {
           Region region =
             getRootRegion().getSubregion(name);
           region.invalidate(key);
+          flushIfNecessary(region);
         }
       });
 
@@ -983,8 +974,8 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
         };
 
 
-    invokeRepeatingIfNecessary(vm1, verify);
-    invokeRepeatingIfNecessary(vm2, verify);
+    vm1.invoke(verify);
+    vm2.invoke(verify);
   }
 
   /**
@@ -1001,8 +992,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
     SerializableRunnable create =
       new CacheSerializableRunnable("Create Region") {
           public void run2() throws CacheException {
-            Region region = createRegion(name);
-            region.put(key, value);
+            createRegion(name);
           }
         };
 
@@ -1013,14 +1003,28 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase
{
       vm.invoke(create);
     }
 
-    pause();
+    SerializableRunnable put =
+        new CacheSerializableRunnable("put entry") {
+            public void run2() throws CacheException {
+              Region region =
+                  getRootRegion().getSubregion(name);
+              region.put(key, value);
+              flushIfNecessary(region);
+            }
+          };
 
-    SerializableRunnable invalidate =
+      for (int i = 0; i < vmCount; i++) {
+        VM vm = host.getVM(i);
+        vm.invoke(put);
+      }
+
+      SerializableRunnable invalidate =
       new CacheSerializableRunnable("Invalidate Entry") {
         public void run2() throws CacheException {
           Region region =
             getRootRegion().getSubregion(name);
           region.invalidate(key);
+          flushIfNecessary(region);
         }
       };
 
@@ -1044,10 +1048,6 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase
{
       VM vm = host.getVM(i);
       vm.invoke(verify);
     }
-
-    // Why is this long 2.5 second pause needed on no-ack?
-    pauseIfNecessary(2500);  // wait for messages to acquiesce before tearing down
-    getLogWriter().info("Tearing down...");
   }
 
   /**
@@ -1088,20 +1088,19 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase
{
               getRootRegion().getSubregion(name);
             region.put(key, value);
             region.put(key2, value2);
+            flushIfNecessary(region);
 
             if (useSubs) {
               Region subregion = region.getSubregion(subname);
               subregion.put(key, value);
               subregion.put(key2, value2);
+              flushIfNecessary(subregion);
             }
           }
         };
 
     invokeInEveryVM(put);
 
-    // wait for update messages to all be propagated
-    pauseIfNecessary(1000);
-
     Host host = Host.getHost(0);
     VM vm0 = host.getVM(0);
 
@@ -1218,6 +1217,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
     // a listener but for this test it does not matter.
     // So I'm commenting out the following pause:
     //pauseIfNecessary();
+    // If needed then do a flushIfNecessary(region) after adding the cache listener
 
     vm0.invoke(new CacheSerializableRunnable("Update") {
         public void run2() throws CacheException {
@@ -1583,13 +1583,10 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase
{
               }
             };
           region.getAttributesMutator().setCacheLoader(loader);
+          flushIfNecessary(region);
         }
       });
 
-   pauseIfNecessary();
-
-   pauseIfNecessary();
-
     vm0.invoke(new CacheSerializableRunnable("Remote load") {
         public void run2() throws CacheException {
           Region region =
@@ -1663,11 +1660,10 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase
{
               }
             };
           region.getAttributesMutator().setCacheLoader(loader);
+          flushIfNecessary(region);
         }
       });
 
-    pauseIfNecessary();
-
     vm0.invoke(new CacheSerializableRunnable("Remote load") {
         public void run2() throws CacheException {
           Region region =
@@ -1725,9 +1721,9 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
 //        factory.setCacheLoader(remoteloader);
         Region rgn = createRegion(name);
         rgn.put(key, value);
+        flushIfNecessary(rgn);
       }
     });
-    pauseIfNecessary();
 
     final TestCacheLoader loader1 = new TestCacheLoader() {
         public Object load2(LoaderHelper helper)
@@ -2037,12 +2033,10 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase
{
               }
             };
           region.getAttributesMutator().setCacheWriter(writer);
+          flushIfNecessary(region);
         }
       });
 
-    // give no-ack time to propagate bookkeeping info
-    pauseIfNecessary();
-
     vm0.invoke(new CacheSerializableRunnable("Create with Exception") {
         public void run2() throws CacheException {
           Region region =
@@ -2481,6 +2475,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
             }
           };
         region.getAttributesMutator().setCacheLoader(loader);
+        flushIfNecessary(region);
       }
     };
 
@@ -2518,11 +2513,10 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase
{
               }
             };
           region.getAttributesMutator().setCacheWriter(writer);
+          flushIfNecessary(region);
         }
       });
 
-    pauseIfNecessary();
-
     vm0.invoke(new CacheSerializableRunnable("Create entry") {
         public void run2() throws CacheException {
           Region region =
@@ -2852,7 +2846,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
     if (!supportsReplication()) {
       return;
     }
-    pauseIfNecessary(100); // wait for previous tearDown to complete
+    //pauseIfNecessary(100); // wait for previous tearDown to complete
 
     final String name = this.getUniqueName();
     final Object key1 = "KEY1";
@@ -2886,9 +2880,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
       };
 
     vm0.invoke(create);
-    Thread.sleep(250);
     vm2.invoke(create);
-    Thread.sleep(250);
 
     vm0.invoke(new CacheSerializableRunnable("Put data") {
         public void run2() throws CacheException {
@@ -2897,7 +2889,8 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
           region.put(key1, value1);
           region.put(key2, value2);
           region.put(key3, value3);
-        }
+          flushIfNecessary(region);
+          }
       });
 
     invokeRepeatingIfNecessary(vm2, new CacheSerializableRunnable("Wait for update") {
@@ -2916,6 +2909,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
           Region region =
             getRootRegion().getSubregion(name);
           region.localDestroyRegion();
+          flushIfNecessary(region);
         }
       });
 
@@ -2980,7 +2974,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
     if (!supportsReplication()) {
       return;
     }
-    pauseIfNecessary(100); // wait for previous tearDown to complete
+    //pauseIfNecessary(100); // wait for previous tearDown to complete
     
     final String name = this.getUniqueName();
     final Object key1 = "KEY1";
@@ -3281,6 +3275,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
         region.put(key1, value1);
         region.put(key2, value2);
         region.put(key3, value3);
+        flushIfNecessary(region);
       }
     };
 
@@ -3328,11 +3323,10 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase
{
           region.localDestroy(key1);
           region.localDestroy(key2);
           region.localDestroy(key3);
+          flushIfNecessary(region);
         }
       });
 
-    pauseIfNecessary(500);
-
     vm0.invoke(new CacheSerializableRunnable("Verify keys/values and listener") {
         public void run2() throws CacheException {
           Region region =
@@ -3405,15 +3399,12 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase
{
         region.put(key1, value1);
         region.put(key2, value2);
         region.put(key3, value3);
+        flushIfNecessary(region);
       }
     };
 
-    pauseIfNecessary();
-
     vm2.invoke(create);
 
-    pauseIfNecessary();
-
     // Make sure that data wasn't pushed
     vm0.invoke(new CacheSerializableRunnable("Verify keys/values") {
         public void run2() throws CacheException {
@@ -4925,9 +4916,10 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase
{
           // as before
           if (i == 301) {
 //            DebuggerSupport.waitForJavaDebugger(getLogWriter(), "About to invalidate region");
-            pauseIfNecessary(300); // wait for previous updates to be processed
+            // wait for previous updates to be processed
+            flushIfNecessary(region);
             region.invalidateRegion();
-            pauseIfNecessary(500);
+            flushIfNecessary(region);
           }
 
           Object key = new Integer(i);
@@ -5402,7 +5394,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
           Region region = getRootRegion().getSubregion(name);
           region.put(key, new IntWrapper(intValue));
 
-          pauseIfNecessary();
+          flushIfNecessary(region);
           assertTrue(serializer.wasInvoked);
         }
       });
@@ -5453,7 +5445,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
           Region region = getRootRegion().getSubregion(name);
           region.put(key2, new LongWrapper(longValue));
 
-          pauseIfNecessary();
+          flushIfNecessary(region);
 
           LongWrapper.LongWrapperSerializer serializer =
             (LongWrapper.LongWrapperSerializer)
@@ -5535,7 +5527,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
           Region region = getRootRegion().getSubregion(name);
           region.put(key, new DSIntWrapper(intValue));
 
-          pauseIfNecessary();
+          flushIfNecessary(region);
         }
       });
 
@@ -5569,7 +5561,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
           Region region = getRootRegion().getSubregion(name);
           region.put(key2, new DSLongWrapper(longValue));
 
-          pauseIfNecessary();
+          flushIfNecessary(region);
         }
       });
     vm2.invoke(get);
@@ -6269,6 +6261,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
           Object value = rgn.get("key");
           assertEquals("LV 1", value);
           getSystem().getLogWriter().info("testTXUpdateLoadNoConflict: loaded Key");
+          flushIfNecessary(rgn);
         }
         catch (CacheException e) {
           fail("While creating region", e);
@@ -6293,7 +6286,6 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
 
       vm0.invoke(create);
 
-      pauseIfNecessary(); // give us a chance to get the update
       {
         TXStateProxy tx = ((TXManagerImpl)txMgr).internalSuspend();
         assertTrue(rgn.containsKey("key"));
@@ -6411,7 +6403,7 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
       assertEquals("new txValue", rgn.getEntry("key").getValue());
 
       txMgr.commit();
-      pauseIfNecessary(); // give other side change to process commit
+      flushIfNecessary(rgn); // give other side change to process commit
       getSystem().getLogWriter().info("testTXUpdateLoadNoConflict: did commit");
       assertEquals("new txValue", rgn.getEntry("key").getValue());
       {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/73d0dcd2/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
index 0e65491..a20cfc5 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
@@ -153,6 +153,14 @@ public abstract class RegionTestCase extends CacheTestCase {
   protected void pauseIfNecessary(int ms) {
   }
   
+  /**
+   * Make sure all messages done on region r have
+   * been processed on the remote side.
+   */
+  protected void flushIfNecessary(Region r) {
+    // Only needed for no-ack regions
+  }
+  
   //////////////////////  Test Methods  //////////////////////
   
   /**


Mime
View raw message