Return-Path: X-Original-To: apmail-geode-commits-archive@minotaur.apache.org Delivered-To: apmail-geode-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2B0BE187A6 for ; Fri, 14 Aug 2015 20:39:56 +0000 (UTC) Received: (qmail 42955 invoked by uid 500); 14 Aug 2015 20:39:56 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 42925 invoked by uid 500); 14 Aug 2015 20:39:56 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 42916 invoked by uid 99); 14 Aug 2015 20:39:56 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Aug 2015 20:39:56 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 998E8DDE83 for ; Fri, 14 Aug 2015 20:39:55 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.781 X-Spam-Level: X-Spam-Status: No, score=0.781 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id FbpMps_7IcVW for ; Fri, 14 Aug 2015 20:39:54 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id 0B0B32136C for ; Fri, 14 Aug 2015 20:39:52 +0000 (UTC) Received: (qmail 41932 invoked by uid 99); 14 Aug 2015 20:39:51 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Aug 2015 20:39:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 257B9E188E; Fri, 14 Aug 2015 20:39:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bschuchardt@apache.org To: commits@geode.incubator.apache.org Date: Fri, 14 Aug 2015 20:40:06 -0000 Message-Id: <0db92d061c1c4902a855f8412f43c529@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [17/50] [abbrv] incubator-geode git commit: GEODE-162: remove race condititions and long sleeps from region expiration test methods in RegionTestCase GEODE-162: remove race condititions and long sleeps from region expiration test methods in RegionTestCase Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/3393f5a3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/3393f5a3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/3393f5a3 Branch: refs/heads/feature/GEODE-77 Commit: 3393f5a314b9bcd2de0d4c173703e9a5f791e197 Parents: 0ff54f3 Author: Darrel Schneider Authored: Thu Jul 30 16:40:14 2015 -0700 Committer: Darrel Schneider Committed: Mon Aug 3 14:28:59 2015 -0700 ---------------------------------------------------------------------- .../gemfire/internal/cache/LocalRegion.java | 7 + .../gemfire/cache30/RegionTestCase.java | 132 ++++++++----------- 2 files changed, 60 insertions(+), 79 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3393f5a3/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java index 9ea26a7..495e992 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java @@ -8815,6 +8815,13 @@ public class LocalRegion extends AbstractRegion } return this.entryExpiryTasks.get(re); } + /** + * Used by unit tests to get access to the RegionIdleExpiryTask + * of this region. Returns null if no task exists. + */ + public RegionIdleExpiryTask getRegionIdleExpiryTask() { + return this.regionIdleExpiryTask; + } private void addExpiryTask(RegionEntry re, boolean ifAbsent) { http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3393f5a3/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 a20cfc5..69eeec0 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 @@ -2085,7 +2085,7 @@ public abstract class RegionTestCase extends CacheTestCase { if (now >= tilt) break; if (!region.isDestroyed()) { - pause(100); + pause(10); continue; } if (now >= tilt - SLOP) { @@ -2107,7 +2107,7 @@ public abstract class RegionTestCase extends CacheTestCase { break; Assert.assertTrue(System.currentTimeMillis() <= tilt, "Region failed to destroy"); - pause(100); + pause(10); } } @@ -2704,7 +2704,7 @@ public abstract class RegionTestCase extends CacheTestCase { vm0.invoke(new CacheSerializableRunnable("testRegionTtlInvalidate") { public void run2() throws CacheException { - final int timeout = 50; // ms + final int timeout = 22; // ms final Object key = "KEY"; final Object value = "VALUE"; @@ -2736,8 +2736,8 @@ public abstract class RegionTestCase extends CacheTestCase { finally { ExpiryTask.permitExpiration(); } - waitForInvalidate(entry, tilt); - waitForInvalidate(region.getEntry("k2"), tilt); + waitForInvalidate(entry, tilt, 10); + waitForInvalidate(region.getEntry("k2"), tilt, 10); } }); } @@ -2753,7 +2753,7 @@ public abstract class RegionTestCase extends CacheTestCase { return; final String name = this.getUniqueName(); - final int timeout = 700; // ms + final int timeout = 22; // ms final Object key = "KEY"; final Object value = "VALUE"; @@ -3741,42 +3741,38 @@ public abstract class RegionTestCase extends CacheTestCase { throws CacheException, InterruptedException { final String name = this.getUniqueName(); - final int timeout = 20; // ms - final int hugeTimeout = Integer.MAX_VALUE; - final ExpirationAttributes expire = - new ExpirationAttributes(timeout, ExpirationAction.INVALIDATE); - final ExpirationAttributes hugeExpire = - new ExpirationAttributes(hugeTimeout, ExpirationAction.INVALIDATE); + ; final Object key = "KEY"; final Object value = "VALUE"; AttributesFactory factory = new AttributesFactory(getRegionAttributes()); factory.setStatisticsEnabled(true); RegionAttributes attrs = factory.create(); - Region region = null; - long tilt; + LocalRegion region = null; System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true"); try { - region = createRegion(name, attrs); + region = (LocalRegion) createRegion(name, attrs); region.create(key, value); - tilt = System.currentTimeMillis() + timeout; // Now go from no timeout to a timeout Region.Entry entry = region.getEntry(key); assertEquals(value, entry.getValue()); - region.getAttributesMutator().setRegionIdleTimeout(expire); - waitForInvalidate(entry, tilt); - - // Now go from a big timeout to a short one - region.getAttributesMutator().setRegionIdleTimeout(hugeExpire); + region.getAttributesMutator().setRegionIdleTimeout(new ExpirationAttributes(12000/*ms*/, ExpirationAction.INVALIDATE)); region.put(key, value); - tilt = System.currentTimeMillis() + timeout; - entry = region.getEntry(key); - pause(timeout * 2); - assertEquals(value, entry.getValue()); - region.getAttributesMutator().setRegionIdleTimeout(expire); - waitForInvalidate(entry, tilt); + long tilt = System.currentTimeMillis(); + + ExpiryTask expiryTask = region.getRegionIdleExpiryTask(); + long mediumExpiryTime = expiryTask.getExpirationTime(); + region.getAttributesMutator().setRegionIdleTimeout(new ExpirationAttributes(999000/*ms*/, ExpirationAction.INVALIDATE)); + expiryTask = region.getRegionIdleExpiryTask(); + long hugeExpiryTime = expiryTask.getExpirationTime(); + region.getAttributesMutator().setRegionIdleTimeout(new ExpirationAttributes(20/*ms*/, ExpirationAction.INVALIDATE)); + expiryTask = region.getRegionIdleExpiryTask(); + long shortExpiryTime = expiryTask.getExpirationTime(); + waitForInvalidate(entry, tilt+20, 10); + assertTrue("expected hugeExpiryTime=" + hugeExpiryTime + " to be > than mediumExpiryTime=" + mediumExpiryTime, (hugeExpiryTime - mediumExpiryTime) > 0); + assertTrue("expected mediumExpiryTime=" + mediumExpiryTime + " to be > than shortExpiryTime=" + shortExpiryTime, (mediumExpiryTime - shortExpiryTime) > 0); } finally { System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY); @@ -3791,8 +3787,10 @@ public abstract class RegionTestCase extends CacheTestCase { public void testRegionIdleInvalidate() throws InterruptedException, CacheException { - if(getRegionAttributes().getPartitionAttributes() != null) + if (getRegionAttributes().getPartitionAttributes() != null) { + // PR does not support INVALID ExpirationAction return; + } final String name = this.getUniqueName(); final String subname = this.getUniqueName() + "-SUB"; @@ -3840,70 +3838,46 @@ public abstract class RegionTestCase extends CacheTestCase { tilt = System.currentTimeMillis() + timeout; entry = region.getEntry(key); assertEquals(value, entry.getValue()); - if(!region.getAttributes().getDataPolicy().withPartitioning()){ - // Do not create subregionsif parent region is a Partitioned Region - sub = region.createSubregion(subname, subRegAttrs); - } + sub = region.createSubregion(subname, subRegAttrs); } finally { System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY); ExpiryTask.permitExpiration(); } - waitForInvalidate(entry, tilt); + waitForInvalidate(entry, tilt, 10); assertTrue(list.waitForInvocation(333)); - pause(timeout); - assertFalse(list.wasInvoked()); + // The next phase of the test verifies that a get will cause the + // expiration time to be extended. + // For this phase we don't worry about actually expiring but just + // making sure the expiration time gets extended. + region.getAttributesMutator().setRegionIdleTimeout(new ExpirationAttributes(9000/*ms*/, ExpirationAction.INVALIDATE)); + + LocalRegion lr = (LocalRegion) region; { - long endTime = System.currentTimeMillis() + (timeout * 2); + ExpiryTask expiryTask = lr.getRegionIdleExpiryTask(); region.put(key, value); - do { - tilt = System.currentTimeMillis() + timeout; // *earliest* time it can expire - region.get(key); // access *might* prevent idle expiration, if it occurs early enough. - - // ...but a huge delay could cause an invalidation before we - // had a chance to do the get. - boolean wasInvoked = list.wasInvoked(); - if (!value.equals(entry.getValue()) || wasInvoked) { - long now = System.currentTimeMillis(); // Did it take too long? - assertTrue("Entry invalidated " + (tilt - now) - + " ms prematurely (" + entry.getValue() + ")" + " value="+ value + " entryValue=" + entry.getValue() + " wasInvoked=" + wasInvoked, - now >= tilt); - - // So it invalidated due to machine latencies. Get out. - break; - } - } while (System.currentTimeMillis() < endTime); - } - waitForInvalidate(entry, tilt); - assertTrue(list.waitForInvocation(333)); + long createExpiry = expiryTask.getExpirationTime(); + waitForExpiryClockToChange(lr); + region.put(key, "VALUE2"); + long putExpiry = expiryTask.getExpirationTime(); + assertTrue("expected putExpiry=" + putExpiry + " to be > than createExpiry=" + createExpiry, (putExpiry - createExpiry) > 0); + waitForExpiryClockToChange(lr); + region.get(key); + long getExpiry = expiryTask.getExpirationTime(); + assertTrue("expected getExpiry=" + getExpiry + " to be > than putExpiry=" + putExpiry, (getExpiry - putExpiry) > 0); - region.put(key, value); - assertEquals(value, entry.getValue()); - if(!region.getAttributes().getDataPolicy().withPartitioning()){ - long endTime = System.currentTimeMillis() + (timeout * 2); + waitForExpiryClockToChange(lr); sub.put(key, value); - do { - tilt = System.currentTimeMillis() + timeout; - sub.get(key, value); // get should prevent idle expiration - - // ...but a huge delay could cause an invalidation before we - // had a chance to do the get. - if (!value.equals(entry.getValue()) || list.wasInvoked()) { - long now = System.currentTimeMillis(); // Did it take too long? - assertTrue("Entry invalidated " + (tilt - now) - + " ms prematurely (" + entry.getValue() + ")", - now >= tilt); - - // So it invalidated due to machine latencies. Get out. - break; - } - } while (System.currentTimeMillis() < endTime); + long subPutExpiry = expiryTask.getExpirationTime(); + assertTrue("expected subPutExpiry=" + subPutExpiry + " to be > than getExpiry=" + getExpiry, (subPutExpiry - getExpiry) > 0); + waitForExpiryClockToChange(lr); + sub.get(key); + long subGetExpiry = expiryTask.getExpirationTime(); + assertTrue("expected subGetExpiry=" + subGetExpiry + " to be > than subPutExpiry=" + subPutExpiry, (subGetExpiry - subPutExpiry) > 0); } - waitForInvalidate(entry, tilt); - assertTrue(list.waitForInvocation(333)); } }); } @@ -3920,7 +3894,7 @@ public abstract class RegionTestCase extends CacheTestCase { return; final String name = this.getUniqueName(); - final int timeout = 800; // ms + final int timeout = 22; // ms final Object key = "KEY"; final Object value = "VALUE";