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:52:30 UTC

[04/50] [abbrv] incubator-geode git commit: GEODE-408: Fixed race condition in tests

GEODE-408: Fixed race condition in tests

- For local functions stats might be checked before they are actually
  updated.


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

Branch: refs/heads/feature/GEODE-328
Commit: ec307d2cb3e6c21fe04abf8a000189e5dd2fcafe
Parents: 5c7bbd0
Author: Jens Deppe <jd...@gopivotal.com>
Authored: Wed Oct 21 14:01:40 2015 -0700
Committer: Jens Deppe <jd...@gopivotal.com>
Committed: Wed Oct 21 16:02:33 2015 -0700

----------------------------------------------------------------------
 .../cache/execute/FunctionServiceStats.java     |  3 +-
 .../execute/FunctionServiceStatsDUnitTest.java  | 43 ++++++++++++++++++--
 2 files changed, 40 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ec307d2c/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceStats.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceStats.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceStats.java
index 26ebf5e..f491f7d 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceStats.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceStats.java
@@ -13,7 +13,6 @@ import com.gemstone.gemfire.StatisticsFactory;
 import com.gemstone.gemfire.StatisticsType;
 import com.gemstone.gemfire.StatisticsTypeFactory;
 import com.gemstone.gemfire.distributed.internal.DistributionStats;
-import com.gemstone.gemfire.internal.NanoTimer;
 import com.gemstone.gemfire.internal.StatisticsTypeFactoryImpl;
 
 public class FunctionServiceStats {
@@ -406,7 +405,7 @@ public class FunctionServiceStats {
       // Increment function execution with haveResult = true complete processing time
       this._stats.incLong(_functionExecutionsHasResultCompletedProcessingTimeId, elapsed);
     }
-    
+
   }
   
   /**

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ec307d2c/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceStatsDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceStatsDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceStatsDUnitTest.java
index 20b1e00..3cf714d 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceStatsDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceStatsDUnitTest.java
@@ -155,7 +155,26 @@ public class FunctionServiceStatsDUnitTest extends PRClientServerTestBase{
       return Boolean.TRUE;
     }
   };
-  
+
+  /*
+   * This helper method prevents race conditions in local functions. Typically, when
+   * calling ResultCollector.getResult() one might expect the function to have completed.
+   * For local functions this is true, however, at this point the function stats may
+   * not have been updated yet thus any code which checks stats after calling getResult()
+   * may get wrong data.
+   */
+  private void waitNoFunctionsRunning(FunctionServiceStats stats) {
+    int count = 100;
+    while (stats.getFunctionExecutionsRunning() > 0 && count > 0) {
+      count--;
+      try {
+        Thread.sleep(50);
+      } catch (InterruptedException ex) {
+        // Ignored
+      }
+    }
+  }
+
   /*
    * 1-client 3-Servers 
    * Function : TEST_FUNCTION2 
@@ -250,6 +269,8 @@ public class FunctionServiceStatsDUnitTest extends PRClientServerTestBase{
         InternalDistributedSystem iDS = (InternalDistributedSystem)cache.getDistributedSystem();
         FunctionServiceStats functionServiceStats = iDS
             .getFunctionServiceStats();
+        waitNoFunctionsRunning(functionServiceStats);
+
         assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats
             .getFunctionExecutionCalls());
         assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats
@@ -286,7 +307,9 @@ public class FunctionServiceStatsDUnitTest extends PRClientServerTestBase{
             .getDistributedSystem();
         FunctionServiceStats functionServiceStats = iDS
             .getFunctionServiceStats();
-        //functions are executed 3 times 
+        waitNoFunctionsRunning(functionServiceStats);
+
+        //functions are executed 3 times
         noOfExecutionCalls_Aggregate +=3;
         assertTrue(functionServiceStats
             .getFunctionExecutionCalls() >= noOfExecutionCalls_Aggregate);
@@ -507,7 +530,8 @@ public class FunctionServiceStatsDUnitTest extends PRClientServerTestBase{
             .getDistributedSystem();
         FunctionServiceStats functionServiceStats = iDS
             .getFunctionServiceStats();
-        
+        waitNoFunctionsRunning(functionServiceStats);
+
         assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats
             .getFunctionExecutionCalls());
         assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats
@@ -609,6 +633,8 @@ public class FunctionServiceStatsDUnitTest extends PRClientServerTestBase{
             .getDistributedSystem();
         FunctionServiceStats functionServiceStats = iDS
             .getFunctionServiceStats();
+        waitNoFunctionsRunning(functionServiceStats);
+
         assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats
             .getFunctionExecutionCalls());
         assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats
@@ -646,6 +672,8 @@ public class FunctionServiceStatsDUnitTest extends PRClientServerTestBase{
             .getDistributedSystem();
         FunctionServiceStats functionServiceStats = iDS
             .getFunctionServiceStats();
+        waitNoFunctionsRunning(functionServiceStats);
+
         // functions are executed 2 times
         noOfExecutionCalls_Aggregate += 2;
         assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats
@@ -827,6 +855,8 @@ public class FunctionServiceStatsDUnitTest extends PRClientServerTestBase{
         InternalDistributedSystem iDS = ((InternalDistributedSystem)getCache()
             .getDistributedSystem());
         FunctionServiceStats functionServiceStats = iDS.getFunctionServiceStats();
+        waitNoFunctionsRunning(functionServiceStats);
+
         assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats
             .getFunctionExecutionCalls());
         assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats
@@ -860,6 +890,8 @@ public class FunctionServiceStatsDUnitTest extends PRClientServerTestBase{
             .getDistributedSystem());
         //3 Function Executions took place 
         FunctionServiceStats functionServiceStats = iDS.getFunctionServiceStats();
+        waitNoFunctionsRunning(functionServiceStats);
+
         noOfExecutionCalls_Aggregate += 3;
         noOfExecutionsCompleted_Aggregate += 3;
         assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats
@@ -1119,7 +1151,8 @@ public class FunctionServiceStatsDUnitTest extends PRClientServerTestBase{
         "checkFunctionExecutionStatsForMember1") {
       public Object call() throws Exception {
         FunctionServiceStats functionServiceStats = ds.getFunctionServiceStats();
-        
+        waitNoFunctionsRunning(functionServiceStats);
+
         assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats
             .getFunctionExecutionCalls());
         assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats
@@ -1140,6 +1173,8 @@ public class FunctionServiceStatsDUnitTest extends PRClientServerTestBase{
         "checkFunctionExecutionStatsForOtherMember") {
       public Object call() throws Exception {
         FunctionServiceStats functionServiceStats = ds.getFunctionServiceStats();
+        waitNoFunctionsRunning(functionServiceStats);
+
         // One function Execution took place on there members
         //noOfExecutionCalls_Aggregate++;
         //noOfExecutionsCompleted_Aggregate++;