You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by up...@apache.org on 2018/09/13 17:55:24 UTC

[geode] branch develop updated: GEODE-5094: Replace flaky expiration with prexisting better one

This is an automated email from the ASF dual-hosted git repository.

upthewaterspout pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new b7df388  GEODE-5094: Replace flaky expiration with prexisting better one
b7df388 is described below

commit b7df38854cbe8215b5c11ae0ae62eeec6394612c
Author: Dan Smith <up...@apache.org>
AuthorDate: Mon Sep 10 16:56:09 2018 -0700

    GEODE-5094: Replace flaky expiration with prexisting better one
    
    ProxyJUnitTest.testExpiration used small timeouts and was flaky. It
    looks like it was probably a near duplicate of a test that was already
    refactored into RegionExpirationIntegrationTest. Removing the test and
    parameterizing RegionExpirationIntegrationTest instead.
---
 .../org/apache/geode/cache/ProxyJUnitTest.java     | 107 ---------------------
 .../cache/RegionExpirationIntegrationTest.java     |  20 +++-
 2 files changed, 17 insertions(+), 110 deletions(-)

diff --git a/geode-core/src/integrationTest/java/org/apache/geode/cache/ProxyJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/cache/ProxyJUnitTest.java
index 2a0e4cc..de92e5a 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/cache/ProxyJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/cache/ProxyJUnitTest.java
@@ -39,7 +39,6 @@ import org.apache.geode.internal.cache.CachePerfStats;
 import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.LocalRegion;
 import org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID;
-import org.apache.geode.internal.util.StopWatch;
 
 /**
  * Unit test for basic DataPolicy.EMPTY feature. NOTE: these tests using a loner DistributedSystem
@@ -1042,112 +1041,6 @@ public class ProxyJUnitTest {
   }
 
   /**
-   * Make sure a proxy region expiration behaves as expected
-   */
-  @Test
-  public void testExpiration() throws Exception {
-    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
-    try {
-      // now make sure they don't on proxy
-      {
-        AttributesFactory af = new AttributesFactory();
-        af.setStatisticsEnabled(true);
-        af.setEntryIdleTimeout(new ExpirationAttributes(1, ExpirationAction.LOCAL_INVALIDATE));
-        af.setEntryTimeToLive(new ExpirationAttributes(2, ExpirationAction.LOCAL_DESTROY));
-        af.setDataPolicy(DataPolicy.EMPTY);
-        try {
-          af.create();
-          fail("expected IllegalStateException");
-        } catch (IllegalStateException expected) {
-        }
-      }
-
-      // make sure regionIdleTimeout works on proxy
-      {
-        CacheListener cl1 = new CacheListenerAdapter() {
-          public void afterRegionDestroy(RegionEvent e) {
-            clInvokeCount++;
-          }
-
-          public void afterRegionInvalidate(RegionEvent e) {
-            clInvokeCount++;
-          }
-        };
-        AttributesFactory af = new AttributesFactory();
-        af.setStatisticsEnabled(true);
-        final int EXPIRE_MS = 500;
-        af.setRegionIdleTimeout(
-            new ExpirationAttributes(EXPIRE_MS, ExpirationAction.LOCAL_DESTROY));
-        af.addCacheListener(cl1);
-        af.setDataPolicy(DataPolicy.EMPTY);
-        clearCallbackState();
-        Region r = this.c.createRegion("rEMPTY", af.create());
-        assertTrue(clInvokeCount == 0);
-        r.put("key", "value");
-        long endTime = System.currentTimeMillis() + (EXPIRE_MS * 2);
-        do {
-          r.get("key");
-        } while (System.currentTimeMillis() < endTime);
-        assertEquals(0, this.clInvokeCount);
-        Thread.sleep(EXPIRE_MS * 2);
-        boolean done = false;
-        try {
-          for (StopWatch time = new StopWatch(true); !done
-              && time.elapsedTimeMillis() < 1000; done = (ProxyJUnitTest.this.clInvokeCount == 1)) {
-            Thread.sleep(200);
-          }
-        } catch (InterruptedException e) {
-          Thread.currentThread().interrupt();
-        }
-        assertTrue("waiting for invocation", done);
-      }
-
-      // make sure regionTimeToLive works on proxy
-      {
-        CacheListener cl1 = new CacheListenerAdapter() {
-          public void afterRegionDestroy(RegionEvent e) {
-            clInvokeCount++;
-          }
-
-          public void afterRegionInvalidate(RegionEvent e) {
-            clInvokeCount++;
-          }
-        };
-        AttributesFactory af = new AttributesFactory();
-        af.setStatisticsEnabled(true);
-        final int EXPIRE_MS = 500;
-        af.setRegionTimeToLive(new ExpirationAttributes(EXPIRE_MS, ExpirationAction.LOCAL_DESTROY));
-        af.addCacheListener(cl1);
-        af.setDataPolicy(DataPolicy.EMPTY);
-        clearCallbackState();
-        Region r = this.c.createRegion("rEMPTY", af.create());
-        assertTrue(clInvokeCount == 0);
-        r.put("key", "value");
-        long endTime = System.currentTimeMillis() + (EXPIRE_MS * 2);
-        do {
-          r.put("key", "value");
-        } while (System.currentTimeMillis() < endTime);
-        assertEquals(0, this.clInvokeCount);
-        Thread.sleep(EXPIRE_MS * 2);
-        boolean done = false;
-        try {
-          for (StopWatch time = new StopWatch(true); !done
-              && time.elapsedTimeMillis() < 1000; done = (ProxyJUnitTest.this.clInvokeCount == 1)) {
-            Thread.sleep(200);
-          }
-        } catch (InterruptedException e) {
-          Thread.currentThread().interrupt();
-        }
-        assertTrue("waiting for invocation", done);
-      }
-
-    } finally {
-      System.clearProperty(LocalRegion.EXPIRY_MS_PROPERTY);
-      assertEquals(null, System.getProperty(LocalRegion.EXPIRY_MS_PROPERTY));
-    }
-  }
-
-  /**
    * Make sure a disk region and proxy play nice.
    */
   @Test
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/cache/RegionExpirationIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/cache/RegionExpirationIntegrationTest.java
index 46bc02b..64b39c2 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/cache/RegionExpirationIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/cache/RegionExpirationIntegrationTest.java
@@ -35,14 +35,25 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TestName;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 import org.mockito.InOrder;
 
+import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
 
-/**
- * Extracted from {@link RegionExpirationDistributedTest}.
- */
+
+@RunWith(Parameterized.class)
+@Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
 public class RegionExpirationIntegrationTest {
 
+  @Parameterized.Parameter(0)
+  public DataPolicy dataPolicy;
+
+  @Parameterized.Parameters(name = "{0}")
+  public static Object[] data() {
+    return new Object[] {DataPolicy.NORMAL, DataPolicy.EMPTY};
+  }
+
   private Cache cache;
   private String regionName;
   private CacheListener<String, String> spyCacheListener;
@@ -66,6 +77,7 @@ public class RegionExpirationIntegrationTest {
 
     RegionFactory<String, String> regionFactory = cache.createRegionFactory(LOCAL);
     regionFactory.setRegionTimeToLive(new ExpirationAttributes(firstTtlSeconds, DESTROY));
+    regionFactory.setDataPolicy(dataPolicy);
     Region<String, String> region = regionFactory.create(regionName);
 
     region.getAttributesMutator()
@@ -84,6 +96,7 @@ public class RegionExpirationIntegrationTest {
 
     RegionFactory<String, String> regionFactory = cache.createRegionFactory(LOCAL);
     regionFactory.setRegionTimeToLive(new ExpirationAttributes(firstTtlSeconds, DESTROY));
+    regionFactory.setDataPolicy(dataPolicy);
     Region<String, String> region = regionFactory.create(regionName);
 
     region.getAttributesMutator()
@@ -101,6 +114,7 @@ public class RegionExpirationIntegrationTest {
     RegionFactory<String, String> regionFactory = cache.createRegionFactory(LOCAL);
     regionFactory.setRegionTimeToLive(new ExpirationAttributes(ttlSeconds, DESTROY));
     regionFactory.setRegionIdleTimeout(new ExpirationAttributes(idleSeconds, INVALIDATE));
+    regionFactory.setDataPolicy(dataPolicy);
     regionFactory.addCacheListener(spyCacheListener);
     Region<String, String> region = regionFactory.create(regionName);