You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2015/07/25 01:16:00 UTC
[37/50] incubator-geode git commit: GEODE-148: change
testUpdateResetIdleTime and testEntryIdleReset to not run so long
GEODE-148: change testUpdateResetIdleTime and testEntryIdleReset to not run so long
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/77daa48c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/77daa48c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/77daa48c
Branch: refs/heads/feature/GEODE-86
Commit: 77daa48ced6d60641841d44c7878cc31663327b0
Parents: 3bfee73
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Mon Jul 20 17:24:46 2015 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Jul 23 17:14:07 2015 -0700
----------------------------------------------------------------------
.../gemfire/internal/cache/AbstractRegion.java | 2 +-
.../gemfire/internal/cache/ExpiryTask.java | 2 +-
.../gemfire/internal/cache/LocalRegion.java | 14 +++
.../internal/cache/RegionIdleExpiryTask.java | 2 +-
.../internal/cache/RegionTTLExpiryTask.java | 2 +-
.../gemfire/cache30/MultiVMRegionTestCase.java | 89 +++++++++-----------
.../gemfire/cache30/RegionTestCase.java | 81 +++++++-----------
.../test/java/dunit/DistributedTestCase.java | 11 +++
8 files changed, 101 insertions(+), 102 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/77daa48c/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegion.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegion.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegion.java
index 1dcd918..90dcb41 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegion.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegion.java
@@ -2004,7 +2004,7 @@ public abstract class AbstractRegion implements Region, RegionAttributes,
return this.cache;
}
- protected final long cacheTimeMillis() {
+ public final long cacheTimeMillis() {
return this.cache.getDistributedSystem().getClock().cacheTimeMillis();
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/77daa48c/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
index 4e1f64b..ccab3aa 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/ExpiryTask.java
@@ -92,7 +92,7 @@ public abstract class ExpiryTask extends SystemTimer.SystemTimerTask {
* region expires, due to either time-to-live or idle-timeout (whichever
* will occur first), or 0 if neither are used.
*/
- long getExpirationTime() throws EntryNotFoundException {
+ public long getExpirationTime() throws EntryNotFoundException {
long ttl = getTTLExpirationTime();
long idle = getIdleExpirationTime();
if (ttl == 0) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/77daa48c/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 eab46ab..9ea26a7 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
@@ -8802,6 +8802,20 @@ public class LocalRegion extends AbstractRegion
}
}
+ /**
+ * Used by unit tests to get access to the EntryExpiryTask
+ * of the given key. Returns null if the entry exists but
+ * does not have an expiry task.
+ * @throws EntryNotFoundException if no entry exists key.
+ */
+ public EntryExpiryTask getEntryExpiryTask(Object key) {
+ RegionEntry re = this.getRegionEntry(key);
+ if (re == null) {
+ throw new EntryNotFoundException("Entry for key " + key + " does not exist.");
+ }
+ return this.entryExpiryTasks.get(re);
+ }
+
private void addExpiryTask(RegionEntry re, boolean ifAbsent)
{
if (isProxy()) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/77daa48c/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/RegionIdleExpiryTask.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/RegionIdleExpiryTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/RegionIdleExpiryTask.java
index 30d839a..fbcb12c 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/RegionIdleExpiryTask.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/RegionIdleExpiryTask.java
@@ -27,7 +27,7 @@ class RegionIdleExpiryTask extends RegionExpiryTask {
* will occur first), or 0 if neither are used.
*/
@Override
- long getExpirationTime() throws EntryNotFoundException {
+ public long getExpirationTime() throws EntryNotFoundException {
// if this is an invalidate action and region has already been invalidated,
// then don't expire again until the full timeout from now.
ExpirationAction action = getAction();
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/77daa48c/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/RegionTTLExpiryTask.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/RegionTTLExpiryTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/RegionTTLExpiryTask.java
index 909af7d..8534e21 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/RegionTTLExpiryTask.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/RegionTTLExpiryTask.java
@@ -27,7 +27,7 @@ class RegionTTLExpiryTask extends RegionExpiryTask {
* will occur first), or 0 if neither are used.
*/
@Override
- long getExpirationTime() throws EntryNotFoundException {
+ public long getExpirationTime() throws EntryNotFoundException {
// if this is an invalidate action and region has already been invalidated,
// then don't expire again until the full timeout from now.
ExpirationAction action = getAction();
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/77daa48c/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 97208ca..8f0c522 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
@@ -82,6 +82,7 @@ import com.gemstone.gemfire.internal.HeapDataOutputStream;
import com.gemstone.gemfire.internal.InternalDataSerializer;
import com.gemstone.gemfire.internal.InternalInstantiator;
import com.gemstone.gemfire.internal.Version;
+import com.gemstone.gemfire.internal.cache.EntryExpiryTask;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.LocalRegion;
import com.gemstone.gemfire.internal.cache.PartitionedRegion;
@@ -106,6 +107,7 @@ import dunit.RMIException;
import dunit.SerializableCallable;
import dunit.SerializableRunnable;
import dunit.VM;
+import dunit.DistributedTestCase.WaitCriterion;
/**
@@ -4071,11 +4073,11 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
* Tests to makes sure that a distributed update resets the
* expiration timer.
*/
- public void testUpdateResetsIdleTime()
- throws InterruptedException {
+ public void testUpdateResetsIdleTime() throws InterruptedException {
final String name = this.getUniqueName();
- final int timeout = 2;
+ // test no longer waits for this timeout to expire
+ final int timeout = 90; // seconds
final Object key = "KEY";
final Object value = "VALUE";
@@ -4089,8 +4091,8 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
factory.setStatisticsEnabled(true);
ExpirationAttributes expire =
- new ExpirationAttributes(timeout,
- ExpirationAction.DESTROY);
+ new ExpirationAttributes(timeout,
+ ExpirationAction.DESTROY);
factory.setEntryIdleTimeout(expire);
if(getRegionAttributes().getPartitionAttributes() != null){
createRegion(name, factory.create());
@@ -4101,20 +4103,21 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
});
vm0.invoke(new CacheSerializableRunnable("Create with Idle") {
- public void run2() throws CacheException {
- AttributesFactory factory = new AttributesFactory(getRegionAttributes());
- factory.setStatisticsEnabled(true);
- ExpirationAttributes expire =
+ public void run2() throws CacheException {
+ AttributesFactory factory = new AttributesFactory(getRegionAttributes());
+ factory.setStatisticsEnabled(true);
+ ExpirationAttributes expire =
new ExpirationAttributes(timeout,
- ExpirationAction.DESTROY);
- factory.setEntryIdleTimeout(expire);
- Region region =
- createRegion(name, factory.create());
- region.create(key, null);
- }
- });
-
- pause((timeout * 1000) / 2);
+ ExpirationAction.DESTROY);
+ factory.setEntryIdleTimeout(expire);
+ LocalRegion region =
+ (LocalRegion) createRegion(name, factory.create());
+ region.create(key, null);
+ EntryExpiryTask eet = region.getEntryExpiryTask(key);
+ region.create("createExpiryTime", eet.getExpirationTime());
+ waitForExpiryClockToChange(region);
+ }
+ });
vm1.invoke(new CacheSerializableRunnable("Update entry") {
public void run2() throws CacheException {
@@ -4124,40 +4127,30 @@ public abstract class MultiVMRegionTestCase extends RegionTestCase {
}
});
- final long tilt1 = System.currentTimeMillis();
- pause(((timeout * 1000) / 2) + 125);
-
vm0.invoke(new CacheSerializableRunnable("Verify reset") {
- public void run2() throws CacheException {
- Region region =
- getRootRegion().getSubregion(name);
- Region.Entry entry = region.getEntry(key);
- if (entry == null) {
- assertTrue(System.currentTimeMillis() >= tilt1);
- fail("testUpdateResetsIdleTime: machine too slow to validate");
- }
- assertEquals(value, entry.getValue());
- }
- });
+ public void run2() throws CacheException {
+ final LocalRegion region =
+ (LocalRegion) getRootRegion().getSubregion(name);
- pause((timeout * 1000) + 500);
+ // wait for update to reach us from vm1 (needed if no-ack)
+ WaitCriterion waitForUpdate = new WaitCriterion() {
+ public boolean done() {
+ return value.equals(region.get(key));
+ }
+ public String description() {
+ return "never saw update of " + key;
+ }
+ };
+ DistributedTestCase.waitForCriterion(waitForUpdate, 3000, 10, true);
- vm0.invoke(new CacheSerializableRunnable("Verify destroy") {
- public void run2() throws CacheException {
- WaitCriterion wc = new WaitCriterion() {
- public boolean done() {
- Region region =
- getRootRegion().getSubregion(name);
- Region.Entry entry = region.getEntry(key);
- return entry == null;
- }
- public String description() {
- return "Entry never destroyed";
- }
- };
- DistributedTestCase.waitForCriterion(wc, 60 * 1000, 1000, true);
+ EntryExpiryTask eet = region.getEntryExpiryTask(key);
+ long createExpiryTime = (Long) region.get("createExpiryTime");
+ long updateExpiryTime = eet.getExpirationTime();
+ if (updateExpiryTime - createExpiryTime <= 0L) {
+ fail("update did not reset the expiration time. createExpiryTime=" + createExpiryTime + " updateExpiryTime=" + updateExpiryTime);
}
- });
+ }
+ });
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/77daa48c/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 c24791b..1c1b59c 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
@@ -45,6 +45,7 @@ import com.gemstone.gemfire.cache.RegionDestroyedException;
import com.gemstone.gemfire.cache.RegionEvent;
import com.gemstone.gemfire.cache.RegionReinitializedException;
import com.gemstone.gemfire.internal.Assert;
+import com.gemstone.gemfire.internal.cache.EntryExpiryTask;
import com.gemstone.gemfire.internal.cache.EntrySnapshot;
import com.gemstone.gemfire.internal.cache.ExpiryTask;
import com.gemstone.gemfire.internal.cache.LocalRegion;
@@ -3736,7 +3737,8 @@ public abstract class RegionTestCase extends CacheTestCase {
public void testEntryIdleReset() throws Exception {
final String name = this.getUniqueName();
- final int timeout = 2000; // ms
+ // Test no longer waits for this timeout to expire
+ final int timeout = 90; // seconds
final String key = "KEY";
final String value = "VALUE";
@@ -3745,60 +3747,39 @@ public abstract class RegionTestCase extends CacheTestCase {
new ExpirationAttributes(timeout, ExpirationAction.DESTROY);
factory.setEntryIdleTimeout(expire);
factory.setStatisticsEnabled(true);
- TestCacheListener list = new TestCacheListener() {
- public void afterCreate2(EntryEvent e) { }
- public void afterDestroy2(EntryEvent e) { }
- };
- factory.setCacheListener(list);
RegionAttributes attrs = factory.create();
- Region region = null;
- System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
- try {
- region = createRegion(name, attrs);
+ LocalRegion region = (LocalRegion) createRegion(name, attrs);
+ region.create(key, null);
+ EntryExpiryTask eet = region.getEntryExpiryTask(key);
+ long createExpiryTime = eet.getExpirationTime();
- ExpiryTask.suspendExpiration();
- Region.Entry entry = null;
- long tilt;
- try {
- region.create(key, null);
- tilt = System.currentTimeMillis() + timeout;
- assertTrue(list.wasInvoked());
- entry = region.getEntry(key);
- }
- finally {
- ExpiryTask.permitExpiration();
- }
+ waitForExpiryClockToChange(region);
+ region.get(key); // touch
+ assertSame(eet, region.getEntryExpiryTask(key));
+ long getExpiryTime = eet.getExpirationTime();
+ if (getExpiryTime - createExpiryTime <= 0L) {
+ fail("get did not reset the expiration time. createExpiryTime=" + createExpiryTime + " getExpiryTime=" + getExpiryTime);
+ }
+
+ waitForExpiryClockToChange(region);
+ region.put(key, value); // touch
+ assertSame(eet, region.getEntryExpiryTask(key));
+ long putExpiryTime = eet.getExpirationTime();
+ if (putExpiryTime - getExpiryTime <= 0L) {
+ fail("put did not reset the expiration time. getExpiryTime=" + getExpiryTime + " putExpiryTime=" + putExpiryTime);
+ }
- pause(timeout / 2);
- long now = System.currentTimeMillis();
- if (region.getEntry(key) == null && now < tilt) {
- fail("Entry for key " + key + " destroyed " + (tilt - now) + " ms prematurely");
- }
- region.get(key); // touch
- waitForDestroy(entry, tilt);
- assertNull(region.getEntry(key));
+ // TODO other ops that should be validated?
- ExpiryTask.suspendExpiration();
- try {
- region.put(key, value);
- tilt = System.currentTimeMillis() + timeout;
- entry = region.getEntry(key);
- assertNotNull(entry.getValue());
- }
- finally {
- ExpiryTask.permitExpiration();
- }
- pause(timeout / 2);
- now = System.currentTimeMillis();
- if (region.getEntry(key) == null && now < tilt) {
- fail("Entry for key " + key + " destroyed " + (tilt - now) + " ms prematurely");
- }
- region.put(key, value); // touch
- waitForDestroy(entry, tilt);
- }
- finally {
- System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
+ // Now verify operations that do not modify the expiry time
+
+ waitForExpiryClockToChange(region);
+ region.invalidate(key); // touch
+ assertSame(eet, region.getEntryExpiryTask(key));
+ long invalidateExpiryTime = eet.getExpirationTime();
+ if (invalidateExpiryTime != putExpiryTime) {
+ fail("invalidate did reset the expiration time. putExpiryTime=" + putExpiryTime + " invalidateExpiryTime=" + invalidateExpiryTime);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/77daa48c/gemfire-core/src/test/java/dunit/DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/dunit/DistributedTestCase.java b/gemfire-core/src/test/java/dunit/DistributedTestCase.java
index e6f0941..564e7ef 100755
--- a/gemfire-core/src/test/java/dunit/DistributedTestCase.java
+++ b/gemfire-core/src/test/java/dunit/DistributedTestCase.java
@@ -54,6 +54,7 @@ import com.gemstone.gemfire.internal.SocketCreator;
import com.gemstone.gemfire.internal.admin.ClientStatsManager;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.InitialImageOperation;
+import com.gemstone.gemfire.internal.cache.LocalRegion;
import com.gemstone.gemfire.internal.cache.tier.InternalBridgeMembership;
import com.gemstone.gemfire.internal.cache.tier.sockets.CacheServerTestUtil;
import com.gemstone.gemfire.internal.cache.tier.sockets.ClientProxyMembershipID;
@@ -974,6 +975,16 @@ public abstract class DistributedTestCase extends TestCase implements java.io.Se
}
+ /**
+ * Blocks until the clock used for expiration on the given region changes.
+ */
+ public static final void waitForExpiryClockToChange(LocalRegion lr) {
+ long startTime = lr.cacheTimeMillis();
+ do {
+ Thread.yield();
+ } while (startTime == lr.cacheTimeMillis());
+ }
+
/** pause for specified ms interval
* Make sure system clock has advanced by the specified number of millis before
* returning.