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 F094F18283 for ; Fri, 24 Jul 2015 18:48:41 +0000 (UTC) Received: (qmail 25386 invoked by uid 500); 24 Jul 2015 18:48:41 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 25355 invoked by uid 500); 24 Jul 2015 18:48:41 -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 25346 invoked by uid 99); 24 Jul 2015 18:48:41 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jul 2015 18:48:41 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 6DB121A7861 for ; Fri, 24 Jul 2015 18:48:41 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.77 X-Spam-Level: X-Spam-Status: No, score=0.77 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id WDDtIG_YGECF for ; Fri, 24 Jul 2015 18:48:26 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id 677652C69A for ; Fri, 24 Jul 2015 18:48:26 +0000 (UTC) Received: (qmail 24657 invoked by uid 99); 24 Jul 2015 18:48:26 -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, 24 Jul 2015 18:48:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0A7CFE684A; Fri, 24 Jul 2015 18:48:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dschneider@apache.org To: commits@geode.incubator.apache.org Date: Fri, 24 Jul 2015 18:48:29 -0000 Message-Id: <38224f6cae2841ed9c13bc4ca72ceeed@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [5/7] incubator-geode git commit: optimized testCustomEntryIdleTimeout3 optimized testCustomEntryIdleTimeout3 Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/af1b99fe Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/af1b99fe Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/af1b99fe Branch: refs/heads/develop Commit: af1b99fe1775140e2112e69640e1b6934b0419ab Parents: 01cc589 Author: Darrel Schneider Authored: Tue Jul 21 14:58:20 2015 -0700 Committer: Darrel Schneider Committed: Thu Jul 23 17:14:08 2015 -0700 ---------------------------------------------------------------------- .../gemfire/cache30/RegionTestCase.java | 152 +++++++------------ 1 file changed, 55 insertions(+), 97 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/af1b99fe/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 ff24434..78e8889 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 @@ -3038,22 +3038,22 @@ public abstract class RegionTestCase extends CacheTestCase { } /** - * Expire an entry with a custom idle time. Set a new idle time, create the - * same entry again, make sure it observes the new idle time. + * Configure custome entry expiration with an idle time. + * Create an entry and records its scheduled expiration time. + * Then mutate the region expiration configuration and confirm + * that the entry's expiration time is rescheduled. */ public void testCustomEntryIdleTimeout3() { - final String name = this.getUniqueName(); - final int timeout1 = 200; // ms - final int timeout2 = 2000; + // test no longer waits for this expiration to happen + final int timeout1 = 500 * 1000; // ms + final int timeout2 = 2000 * 1000; // ms final String key1 = "KEY1"; final String value1 = "VALUE1"; - final String value2 = "VALUE2"; AttributesFactory factory = new AttributesFactory(getRegionAttributes()); ExpirationAttributes expire1 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE); -// factory.setEntryIdleTimeout(expire); factory.setCustomEntryIdleTimeout(new TestExpiry(key1, expire1)); factory.setStatisticsEnabled(true); TestCacheListener list = new TestCacheListener() { @@ -3065,104 +3065,62 @@ public abstract class RegionTestCase extends CacheTestCase { factory.addCacheListener(list); RegionAttributes attrs = factory.create(); - Region region = null; + LocalRegion region; System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true"); try { - region = createRegion(name, attrs); - } - finally { - if(region.getAttributes().getPartitionAttributes() == null) - System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY); + region = (LocalRegion) createRegion(name, attrs); + } finally { + System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY); } - // DebuggerSupport.waitForJavaDebugger(getLogWriter(), "Set breakpoint in invalidate"); - ExpiryTask.suspendExpiration(); - Region.Entry entry = null; - long tilt; - try { - region.create(key1, value1); - tilt = System.currentTimeMillis() + timeout1; - assertTrue(list.waitForInvocation(5000)); - entry = region.getEntry(key1); - Assert.assertTrue(value1.equals(entry.getValue())); - } - finally { - ExpiryTask.permitExpiration(); - } - waitForInvalidate(entry, tilt); - if (!getRegionAttributes().getDataPolicy().withPartitioning()) { - // Disk regions are VERY slow, so we need to wait for the event... - WaitCriterion wc = new WaitCriterion() { - public boolean done() { - return eventCount == 1; - } - public String description() { - return "eventCount never became 1"; - } - }; - DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true); - } - eventCount = 0; + region.create(key1, value1); + EntryExpiryTask eet = region.getEntryExpiryTask(key1); + final long firstExpiryTime = eet.getExpirationTime(); - // Do it again with a put (I guess) - ExpiryTask.suspendExpiration(); - try { - region.put(key1, value1); - tilt = System.currentTimeMillis() + timeout1; - entry = region.getEntry(key1); - Assert.assertTrue(value1.equals(entry.getValue())); - assertTrue(list.waitForInvocation(5000)); - } - finally { - ExpiryTask.permitExpiration(); - } - waitForInvalidate(entry, tilt); - if (!getRegionAttributes().getDataPolicy().withPartitioning()) { - // Disk regions are VERY slow, so we need to wait for the event... - WaitCriterion wc = new WaitCriterion() { - public boolean done() { - return eventCount == 1; - } - public String description() { - return "eventCount never became 1"; - } - }; - DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true); - } - eventCount = 0; - - // Change custom expiry for this region now... AttributesMutator mutt = region.getAttributesMutator(); - ExpirationAttributes expire2 = - new ExpirationAttributes(timeout2, ExpirationAction.INVALIDATE); + ExpirationAttributes expire2 = new ExpirationAttributes(timeout2, ExpirationAction.INVALIDATE); mutt.setCustomEntryIdleTimeout(new TestExpiry(key1, expire2)); - - ExpiryTask.suspendExpiration(); - try { - region.put(key1, value2); - tilt = System.currentTimeMillis() + timeout2; - entry = region.getEntry(key1); - Assert.assertTrue(value2.equals(entry.getValue())); - assertTrue(list.waitForInvocation(5000)); - } - finally { - if(region.getAttributes().getPartitionAttributes() != null) - System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY); - ExpiryTask.permitExpiration(); - } - waitForInvalidate(entry, tilt); - if (!getRegionAttributes().getDataPolicy().withPartitioning()) { - // Disk regions are VERY slow, so we need to wait for the event... - WaitCriterion wc = new WaitCriterion() { - public boolean done() { - return eventCount == 1; - } - public String description() { - return "eventCount never became 1"; - } - }; - DistributedTestCase.waitForCriterion(wc, 10 * 1000, 100, true); + eet = region.getEntryExpiryTask(key1); + final long secondExpiryTime = eet.getExpirationTime(); + if ((secondExpiryTime - firstExpiryTime) <= 0) { + fail("expiration time should have been greater after changing region config from 500 to 2000. firstExpiryTime=" + firstExpiryTime + " secondExpiryTime=" + secondExpiryTime); } + + // now set back to be more recent + mutt = region.getAttributesMutator(); + ExpirationAttributes expire3 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE); + mutt.setCustomEntryIdleTimeout(new TestExpiry(key1, expire3)); + eet = region.getEntryExpiryTask(key1); + final long thirdExpiryTime = eet.getExpirationTime(); + assertEquals(firstExpiryTime, thirdExpiryTime); + // confirm that it still has not expired + assertEquals(0, eventCount); + + // now set it to a really short time and make sure it expires immediately + waitForExpiryClockToChange(region); + final Region.Entry entry = region.getEntry(key1); + mutt = region.getAttributesMutator(); + ExpirationAttributes expire4 = new ExpirationAttributes(1, ExpirationAction.INVALIDATE); + mutt.setCustomEntryIdleTimeout(new TestExpiry(key1, expire4)); + WaitCriterion wc = new WaitCriterion() { + public boolean done() { + return fetchEntryValue(entry) == null; + } + public String description() { + return "entry never became invalid"; + } + }; + DistributedTestCase.waitForCriterion(wc, 10 * 1000, 10, true); + + WaitCriterion waitForEventCountToBeOne = new WaitCriterion() { + public boolean done() { + return eventCount == 1; + } + public String description() { + return "eventCount never became 1"; + } + }; + DistributedTestCase.waitForCriterion(waitForEventCountToBeOne, 10 * 1000, 10, true); eventCount = 0; }