You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2018/08/17 15:46:40 UTC
[geode] branch develop updated: GEODE-5257: remove unnecessary
assertion that introduced the flakiness. (#2265)
This is an automated email from the ASF dual-hosted git repository.
jinmeiliao 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 2be72bd GEODE-5257: remove unnecessary assertion that introduced the flakiness. (#2265)
2be72bd is described below
commit 2be72bdf0af50b0b79bc4428b3bdf962dca56509
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Fri Aug 17 08:46:34 2018 -0700
GEODE-5257: remove unnecessary assertion that introduced the flakiness. (#2265)
* add withNoCacheServer() to the ServerStarterRule
---
.../ShorteningExpirationTimeRegressionTest.java | 69 ++++++++--------------
.../geode/test/junit/rules/ServerStarterRule.java | 34 +++++++----
2 files changed, 48 insertions(+), 55 deletions(-)
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/cache30/ShorteningExpirationTimeRegressionTest.java b/geode-core/src/integrationTest/java/org/apache/geode/cache30/ShorteningExpirationTimeRegressionTest.java
index 6be212f..8dcdf8c 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/cache30/ShorteningExpirationTimeRegressionTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/cache30/ShorteningExpirationTimeRegressionTest.java
@@ -14,23 +14,16 @@
*/
package org.apache.geode.cache30;
-import static java.util.concurrent.TimeUnit.MINUTES;
-import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.assertj.core.api.Assertions.assertThat;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.awaitility.Awaitility.await;
-import java.util.Properties;
-
-import org.junit.After;
-import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.rules.TestName;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.CustomExpiry;
import org.apache.geode.cache.ExpirationAttributes;
import org.apache.geode.cache.Region;
@@ -38,6 +31,7 @@ import org.apache.geode.cache.Region.Entry;
import org.apache.geode.cache.RegionFactory;
import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.test.junit.rules.ServerStarterRule;
/**
* If a new expiration time is specified that is shorter than an existing one, ensure the new
@@ -52,68 +46,55 @@ public class ShorteningExpirationTimeRegressionTest {
private static final int LONG_WAIT_MS = 2 * 60 * 1000;
private static final int SHORT_WAIT_MS = 1;
-
private static final String KEY = "key";
- private String uniqueName;
- private String regionName;
+ @ClassRule
+ public static ServerStarterRule server =
+ new ServerStarterRule().withNoCacheServer().withAutoStart();
- private Cache cache;
-
- @Rule
- public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+ @ClassRule
+ public static RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
@Rule
public TestName testName = new TestName();
- @Before
- public void setUp() throws Exception {
- Properties config = new Properties();
- config.setProperty(MCAST_PORT, "0");
- config.setProperty(LOCATORS, "");
-
- uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
- regionName = uniqueName + "_region";
-
- cache = new CacheFactory(config).create();
-
+ @BeforeClass
+ public static void setUp() {
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
}
- @After
- public void tearDown() throws Exception {
- if (cache != null) {
- cache.close();
- }
- }
-
@Test
- public void customEntryTimeToLiveCanBeShortened() throws Exception {
- RegionFactory<String, String> rf = cache.createRegionFactory(RegionShortcut.LOCAL);
+ public void customEntryTimeToLiveCanBeShortened() {
+ RegionFactory<String, String> rf = server.getCache().createRegionFactory(RegionShortcut.LOCAL);
rf.setCustomEntryTimeToLive(new CustomExpiryTestClass<>());
rf.setStatisticsEnabled(true);
- Region<String, String> region = rf.create(regionName);
+ Region<String, String> region = rf.create(testName.getMethodName());
+ // this sets the expiration timeout to LONG_WAIT_MS
region.put(KEY, "longExpire");
+ // this sets the expiration timeout to SHORT_WAIT_MS
region.put(KEY, "quickExpire");
- assertThat(region.get(KEY)).isEqualTo("quickExpire");
- await().atMost(1, MINUTES).until(() -> !region.containsValueForKey(KEY));
+ // make sure the entry is invalidated before LONG_WAIT_MS (timeout shortened)
+ await().atMost(LONG_WAIT_MS / 2, MILLISECONDS).until(() -> !region.containsValueForKey(KEY));
}
@Test
public void customEntryIdleTimeoutCanBeShortened() throws Exception {
- RegionFactory<String, String> rf = cache.createRegionFactory(RegionShortcut.LOCAL);
+ RegionFactory<String, String> rf = server.getCache().createRegionFactory(RegionShortcut.LOCAL);
rf.setCustomEntryIdleTimeout(new CustomExpiryTestClass<>());
rf.setStatisticsEnabled(true);
- Region<String, String> region = rf.create(regionName);
+ Region<String, String> region = rf.create(testName.getMethodName());
+ // this sets the expiration timeout to LONG_WAIT_MS
region.put(KEY, "longExpire");
- assertThat(region.get(KEY)).isEqualTo("longExpire");
+ // this sets the expiration timeout to SHORT_WAIT_MS
+ region.get(KEY);
- await().atMost(1, MINUTES).until(() -> !region.containsValueForKey(KEY));
+ // make sure the entry is invalidated before LONG_WAIT_MS (timeout shortened)
+ await().atMost(LONG_WAIT_MS / 2, MILLISECONDS).until(() -> !region.containsValueForKey(KEY));
}
private class CustomExpiryTestClass<K, V> implements CustomExpiry<K, V> {
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/junit/rules/ServerStarterRule.java b/geode-dunit/src/main/java/org/apache/geode/test/junit/rules/ServerStarterRule.java
index 21b78fe..e1e7397 100644
--- a/geode-dunit/src/main/java/org/apache/geode/test/junit/rules/ServerStarterRule.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/junit/rules/ServerStarterRule.java
@@ -41,7 +41,7 @@ import org.apache.geode.pdx.PdxSerializer;
* the configuration of the rule like this: ServerStarterRule server = new ServerStarterRule()
* .withProperty(key, value) .withName(name) .withProperties(properties) .withSecurityManager(class)
* .withJmxManager() .withRestService() .withEmbeddedLocator() .withRegion(type, name) etc, etc. If
- * your rule calls withAutoStart(), the server will be started before your test code.
+ * your rule calls withAutoStart(), the cache and server will be started before your test code.
*
* <p>
* In your test code, you can use the rule to access the server's attributes, like the port
@@ -58,6 +58,7 @@ public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> impl
private boolean pdxPersistent = false;
private PdxSerializer pdxSerializer = null;
private boolean pdxReadSerialized = false;
+ private boolean noCacheServer = false;
private Map<String, RegionShortcut> regions = new HashMap<>();
@@ -122,6 +123,14 @@ public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> impl
return this;
}
+ /**
+ * If your only needs a cache and does not need a server for clients to connect
+ */
+ public ServerStarterRule withNoCacheServer() {
+ this.noCacheServer = true;
+ return this;
+ }
+
public ServerStarterRule withEmbeddedLocator() {
embeddedLocatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
properties.setProperty("start-locator", "localhost[" + embeddedLocatorPort + "]");
@@ -172,18 +181,21 @@ public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> impl
cache = (InternalCache) cf.create();
DistributionConfig config =
((InternalDistributedSystem) cache.getDistributedSystem()).getConfig();
- server = cache.addCacheServer();
- // memberPort is by default zero, which translates to "randomly select an available port,"
- // which is why it is updated after this try block
- server.setPort(memberPort);
- try {
- server.start();
- } catch (IOException e) {
- throw new RuntimeException("unable to start server", e);
- }
- memberPort = server.getPort();
jmxPort = config.getJmxManagerPort();
httpPort = config.getHttpServicePort();
+
+ if (!noCacheServer) {
+ server = cache.addCacheServer();
+ // memberPort is by default zero, which translates to "randomly select an available port,"
+ // which is why it is updated after this try block
+ server.setPort(memberPort);
+ try {
+ server.start();
+ } catch (IOException e) {
+ throw new RuntimeException("unable to start server", e);
+ }
+ memberPort = server.getPort();
+ }
}
@Override