You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2018/03/29 20:22:11 UTC
[geode] 15/15: GEODE-4876: Cleanup CacheRule tests use of VM and
javadocs
This is an automated email from the ASF dual-hosted git repository.
klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
commit 7be2a7e215a85c9d48ec293c024b54d719946008
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Mon Mar 26 17:42:44 2018 -0700
GEODE-4876: Cleanup CacheRule tests use of VM and javadocs
* rename CacheRuleTest as CacheRuleBuilderDistributedTest
* write new CacheRuleDistributedTest
* fix javadocs of CacheRule
---
.../apache/geode/test/dunit/rules/CacheRule.java | 6 +-
...t.java => CacheRuleBuilderDistributedTest.java} | 53 +++----
...RuleTest.java => CacheRuleDistributedTest.java} | 171 ++++++++++-----------
3 files changed, 117 insertions(+), 113 deletions(-)
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/CacheRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/CacheRule.java
index 42a3923..990f45c 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/CacheRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/CacheRule.java
@@ -119,6 +119,10 @@ public class CacheRule extends DistributedExternalResource {
cache = (InternalCache) new CacheFactory(config).create();
}
+ public void createCache(final CacheFactory cacheFactory) {
+ cache = (InternalCache) cacheFactory.create();
+ }
+
public void createCache(final Properties config) {
cache = (InternalCache) new CacheFactory(config).create();
}
@@ -156,7 +160,7 @@ public class CacheRule extends DistributedExternalResource {
}
/**
- * Builds an instance of SharedCountersRule
+ * Builds an instance of CacheRule.
*/
public static class Builder {
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/CacheRuleTest.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/CacheRuleBuilderDistributedTest.java
similarity index 86%
copy from geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/CacheRuleTest.java
copy to geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/CacheRuleBuilderDistributedTest.java
index d10d4be..72c3f11 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/CacheRuleTest.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/CacheRuleBuilderDistributedTest.java
@@ -15,6 +15,9 @@
package org.apache.geode.test.dunit.rules.tests;
import static org.apache.geode.distributed.ConfigurationProperties.DISTRIBUTED_SYSTEM_ID;
+import static org.apache.geode.test.dunit.VM.getAllVMs;
+import static org.apache.geode.test.dunit.VM.getVM;
+import static org.apache.geode.test.dunit.VM.getVMCount;
import static org.apache.geode.test.junit.runners.TestRunner.runTestWithValidation;
import static org.assertj.core.api.Assertions.assertThat;
@@ -27,7 +30,6 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.rules.CacheRule;
import org.apache.geode.test.dunit.rules.DistributedTestRule;
@@ -35,7 +37,7 @@ import org.apache.geode.test.junit.categories.DistributedTest;
@Category(DistributedTest.class)
@SuppressWarnings("serial")
-public class CacheRuleTest {
+public class CacheRuleBuilderDistributedTest {
@ClassRule
public static DistributedTestRule distributedTestRule = new DistributedTestRule();
@@ -96,7 +98,7 @@ public class CacheRuleTest {
@Test
public void getCache_returnsNullInAllVMs() throws Exception {
assertThat(cacheRule.getCache()).isNull();
- for (VM vm : Host.getHost(0).getAllVMs()) {
+ for (VM vm : getAllVMs()) {
vm.invoke(() -> assertThat(cacheRule.getCache()).isNull());
}
}
@@ -104,7 +106,7 @@ public class CacheRuleTest {
@Test
public void getCacheSingleton_returnsNullInAllVMs() throws Exception {
assertThat(GemFireCacheImpl.getInstance()).isNull();
- for (VM vm : Host.getHost(0).getAllVMs()) {
+ for (VM vm : getAllVMs()) {
vm.invoke(() -> assertThat(GemFireCacheImpl.getInstance()).isNull());
}
}
@@ -121,7 +123,7 @@ public class CacheRuleTest {
@Test
public void getCache_returnsCacheInLocalOnly() throws Exception {
assertThat(cacheRule.getCache()).isNotNull();
- for (VM vm : Host.getHost(0).getAllVMs()) {
+ for (VM vm : getAllVMs()) {
vm.invoke(() -> assertThat(cacheRule.getCache()).isNull());
}
}
@@ -133,19 +135,18 @@ public class CacheRuleTest {
public static class CreateCacheInOneVM implements Serializable {
@Rule
- public CacheRule cacheRule =
- CacheRule.builder().createCacheIn(Host.getHost(0).getVM(0)).build();
+ public CacheRule cacheRule = CacheRule.builder().createCacheIn(getVM(0)).build();
@Test
public void getCache_returnsCacheInOneVM() throws Exception {
assertThat(cacheRule.getCache()).isNull();
- Host.getHost(0).getVM(0).invoke(() -> {
+ getVM(0).invoke(() -> {
assertThat(cacheRule.getCache()).isNotNull();
});
- for (int i = 1; i < Host.getHost(0).getVMCount(); i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
+ for (int i = 1; i < getVMCount(); i++) {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache()).isNull();
});
}
@@ -158,20 +159,20 @@ public class CacheRuleTest {
public static class CreateCacheInTwoVMs implements Serializable {
@Rule
- public CacheRule cacheRule = CacheRule.builder().createCacheIn(Host.getHost(0).getVM(1))
- .createCacheIn(Host.getHost(0).getVM(3)).build();
+ public CacheRule cacheRule =
+ CacheRule.builder().createCacheIn(getVM(1)).createCacheIn(getVM(3)).build();
@Test
public void getCache_returnsCacheInTwoVMs() throws Exception {
assertThat(cacheRule.getCache()).isNull();
- for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
+ for (int i = 0; i < getVMCount(); i++) {
if (i == 1 || i == 3) {
- Host.getHost(0).getVM(i).invoke(() -> {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache()).isNotNull();
});
} else {
- Host.getHost(0).getVM(i).invoke(() -> {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache()).isNull();
});
}
@@ -190,8 +191,8 @@ public class CacheRuleTest {
@Test
public void createCacheInAll_returnsCacheInAll() throws Exception {
assertThat(cacheRule.getCache()).isNotNull();
- for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
+ for (int i = 0; i < getVMCount(); i++) {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache()).isNotNull();
});
}
@@ -209,8 +210,8 @@ public class CacheRuleTest {
@Test
public void createCacheInAllExplicitly_returnsCacheInAll() throws Exception {
assertThat(cacheRule.getCache()).isNotNull();
- for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
+ for (int i = 0; i < getVMCount(); i++) {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache()).isNotNull();
});
}
@@ -227,12 +228,12 @@ public class CacheRuleTest {
@Test
public void createCacheInAll_createsCluster() throws Exception {
- int vmCount = Host.getHost(0).getVMCount();
+ int vmCount = getVMCount();
assertThat(cacheRule.getCache().getDistributionManager().getViewMembers())
.hasSize(vmCount + 2);
for (int i = 0; i < vmCount; i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache().getDistributionManager().getViewMembers())
.hasSize(vmCount + 2);
});
@@ -256,12 +257,12 @@ public class CacheRuleTest {
assertThat(
cacheRule.getCache().getInternalDistributedSystem().getConfig().getDistributedSystemId())
.isEqualTo(1);
- for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
+ for (int i = 0; i < getVMCount(); i++) {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache().getDistributedSystem().getProperties()
.getProperty(DISTRIBUTED_SYSTEM_ID)).isEqualTo("1");
});
- Host.getHost(0).getVM(i).invoke(() -> {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache().getInternalDistributedSystem().getConfig()
.getDistributedSystemId()).isEqualTo(1);
});
@@ -281,8 +282,8 @@ public class CacheRuleTest {
@Test
public void replaceConfig_createsLonersInAll() throws Exception {
assertThat(cacheRule.getCache().getDistributionManager().getViewMembers()).hasSize(1);
- for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
+ for (int i = 0; i < getVMCount(); i++) {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache().getDistributionManager().getViewMembers()).hasSize(1);
});
}
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/CacheRuleTest.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/CacheRuleDistributedTest.java
similarity index 58%
rename from geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/CacheRuleTest.java
rename to geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/CacheRuleDistributedTest.java
index d10d4be..a4748e5 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/CacheRuleTest.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/CacheRuleDistributedTest.java
@@ -14,20 +14,22 @@
*/
package org.apache.geode.test.dunit.rules.tests;
-import static org.apache.geode.distributed.ConfigurationProperties.DISTRIBUTED_SYSTEM_ID;
+import static org.apache.geode.test.dunit.VM.getAllVMs;
+import static org.apache.geode.test.dunit.VM.getVM;
+import static org.apache.geode.test.dunit.VM.getVMCount;
import static org.apache.geode.test.junit.runners.TestRunner.runTestWithValidation;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.Serializable;
import java.util.Properties;
+import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.rules.CacheRule;
import org.apache.geode.test.dunit.rules.DistributedTestRule;
@@ -35,7 +37,7 @@ import org.apache.geode.test.junit.categories.DistributedTest;
@Category(DistributedTest.class)
@SuppressWarnings("serial")
-public class CacheRuleTest {
+public class CacheRuleDistributedTest {
@ClassRule
public static DistributedTestRule distributedTestRule = new DistributedTestRule();
@@ -66,23 +68,13 @@ public class CacheRuleTest {
}
@Test
- public void createCacheInAllExplicitly() throws Exception {
- runTestWithValidation(CreateCacheInAllExplicitly.class);
- }
-
- @Test
public void createCacheInAllCreatesCluster() throws Exception {
runTestWithValidation(CreateCacheInAllCreatesCluster.class);
}
@Test
- public void addConfigAffectsAllVMs() throws Exception {
- runTestWithValidation(AddConfigAffectsAllVMs.class);
- }
-
- @Test
- public void replaceConfigCreatesLonersInAll() throws Exception {
- runTestWithValidation(ReplaceConfigCreatesLonersInAll.class);
+ public void emptyConfigCreatesLonersInAll() throws Exception {
+ runTestWithValidation(EmptyConfigCreatesLonersInAll.class);
}
/**
@@ -91,12 +83,12 @@ public class CacheRuleTest {
public static class DefaultDoesNothing implements Serializable {
@Rule
- public CacheRule cacheRule = CacheRule.builder().build();
+ public CacheRule cacheRule = new CacheRule();
@Test
public void getCache_returnsNullInAllVMs() throws Exception {
assertThat(cacheRule.getCache()).isNull();
- for (VM vm : Host.getHost(0).getAllVMs()) {
+ for (VM vm : getAllVMs()) {
vm.invoke(() -> assertThat(cacheRule.getCache()).isNull());
}
}
@@ -104,7 +96,7 @@ public class CacheRuleTest {
@Test
public void getCacheSingleton_returnsNullInAllVMs() throws Exception {
assertThat(GemFireCacheImpl.getInstance()).isNull();
- for (VM vm : Host.getHost(0).getAllVMs()) {
+ for (VM vm : getAllVMs()) {
vm.invoke(() -> assertThat(GemFireCacheImpl.getInstance()).isNull());
}
}
@@ -116,12 +108,17 @@ public class CacheRuleTest {
public static class CreateCacheInLocal implements Serializable {
@Rule
- public CacheRule cacheRule = CacheRule.builder().createCacheInLocal().build();
+ public CacheRule cacheRule = new CacheRule();
+
+ @Before
+ public void setUp() throws Exception {
+ cacheRule.createCache();
+ }
@Test
public void getCache_returnsCacheInLocalOnly() throws Exception {
assertThat(cacheRule.getCache()).isNotNull();
- for (VM vm : Host.getHost(0).getAllVMs()) {
+ for (VM vm : getAllVMs()) {
vm.invoke(() -> assertThat(cacheRule.getCache()).isNull());
}
}
@@ -133,19 +130,25 @@ public class CacheRuleTest {
public static class CreateCacheInOneVM implements Serializable {
@Rule
- public CacheRule cacheRule =
- CacheRule.builder().createCacheIn(Host.getHost(0).getVM(0)).build();
+ public CacheRule cacheRule = new CacheRule();
+
+ @Before
+ public void setUp() throws Exception {
+ getVM(0).invoke(() -> {
+ cacheRule.createCache();
+ });
+ }
@Test
public void getCache_returnsCacheInOneVM() throws Exception {
assertThat(cacheRule.getCache()).isNull();
- Host.getHost(0).getVM(0).invoke(() -> {
+ getVM(0).invoke(() -> {
assertThat(cacheRule.getCache()).isNotNull();
});
- for (int i = 1; i < Host.getHost(0).getVMCount(); i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
+ for (int i = 1; i < getVMCount(); i++) {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache()).isNull();
});
}
@@ -158,20 +161,29 @@ public class CacheRuleTest {
public static class CreateCacheInTwoVMs implements Serializable {
@Rule
- public CacheRule cacheRule = CacheRule.builder().createCacheIn(Host.getHost(0).getVM(1))
- .createCacheIn(Host.getHost(0).getVM(3)).build();
+ public CacheRule cacheRule = new CacheRule();
+
+ @Before
+ public void setUp() throws Exception {
+ getVM(1).invoke(() -> {
+ cacheRule.createCache();
+ });
+ getVM(3).invoke(() -> {
+ cacheRule.createCache();
+ });
+ }
@Test
public void getCache_returnsCacheInTwoVMs() throws Exception {
assertThat(cacheRule.getCache()).isNull();
- for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
+ for (int i = 0; i < getVMCount(); i++) {
if (i == 1 || i == 3) {
- Host.getHost(0).getVM(i).invoke(() -> {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache()).isNotNull();
});
} else {
- Host.getHost(0).getVM(i).invoke(() -> {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache()).isNull();
});
}
@@ -185,32 +197,23 @@ public class CacheRuleTest {
public static class CreateCacheInAll implements Serializable {
@Rule
- public CacheRule cacheRule = CacheRule.builder().createCacheInAll().build();
-
- @Test
- public void createCacheInAll_returnsCacheInAll() throws Exception {
- assertThat(cacheRule.getCache()).isNotNull();
- for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
- assertThat(cacheRule.getCache()).isNotNull();
+ public CacheRule cacheRule = new CacheRule();
+
+ @Before
+ public void setUp() throws Exception {
+ cacheRule.createCache();
+ for (int i = 0; i < getVMCount(); i++) {
+ getVM(i).invoke(() -> {
+ cacheRule.createCache();
});
}
}
- }
-
- /**
- * Used by test {@link #createCacheInAllExplicitly()}.
- */
- public static class CreateCacheInAllExplicitly implements Serializable {
-
- @Rule
- public CacheRule cacheRule = CacheRule.builder().createCacheInAll().build();
@Test
- public void createCacheInAllExplicitly_returnsCacheInAll() throws Exception {
+ public void createCacheInAll_returnsCacheInAll() throws Exception {
assertThat(cacheRule.getCache()).isNotNull();
- for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
+ for (int i = 0; i < getVMCount(); i++) {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache()).isNotNull();
});
}
@@ -222,17 +225,29 @@ public class CacheRuleTest {
*/
public static class CreateCacheInAllCreatesCluster implements Serializable {
+ private int vmCount;
+
@Rule
- public CacheRule cacheRule = CacheRule.builder().createCacheInAll().build();
+ public CacheRule cacheRule = new CacheRule();
+
+ @Before
+ public void setUp() throws Exception {
+ vmCount = getVMCount();
+
+ cacheRule.createCache();
+ for (int i = 0; i < vmCount; i++) {
+ getVM(i).invoke(() -> {
+ cacheRule.createCache();
+ });
+ }
+ }
@Test
public void createCacheInAll_createsCluster() throws Exception {
- int vmCount = Host.getHost(0).getVMCount();
-
assertThat(cacheRule.getCache().getDistributionManager().getViewMembers())
.hasSize(vmCount + 2);
for (int i = 0; i < vmCount; i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache().getDistributionManager().getViewMembers())
.hasSize(vmCount + 2);
});
@@ -241,48 +256,32 @@ public class CacheRuleTest {
}
/**
- * Used by test {@link #addConfigAffectsAllVMs()}.
+ * Used by test {@link #emptyConfigCreatesLonersInAll()}.
*/
- public static class AddConfigAffectsAllVMs implements Serializable {
+ public static class EmptyConfigCreatesLonersInAll implements Serializable {
+
+ private Properties config;
@Rule
- public CacheRule cacheRule =
- CacheRule.builder().addConfig(DISTRIBUTED_SYSTEM_ID, "1").createCacheInAll().build();
+ public CacheRule cacheRule = new CacheRule();
- @Test
- public void addConfig_affectsAllVMs() throws Exception {
- assertThat(cacheRule.getCache().getDistributedSystem().getProperties()
- .getProperty(DISTRIBUTED_SYSTEM_ID)).isEqualTo("1");
- assertThat(
- cacheRule.getCache().getInternalDistributedSystem().getConfig().getDistributedSystemId())
- .isEqualTo(1);
- for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
- assertThat(cacheRule.getCache().getDistributedSystem().getProperties()
- .getProperty(DISTRIBUTED_SYSTEM_ID)).isEqualTo("1");
- });
- Host.getHost(0).getVM(i).invoke(() -> {
- assertThat(cacheRule.getCache().getInternalDistributedSystem().getConfig()
- .getDistributedSystemId()).isEqualTo(1);
+ @Before
+ public void setUp() throws Exception {
+ config = new Properties();
+
+ cacheRule.createCache(config);
+ for (int i = 0; i < getVMCount(); i++) {
+ getVM(i).invoke(() -> {
+ cacheRule.createCache(config);
});
}
}
- }
-
- /**
- * Used by test {@link #replaceConfigCreatesLonersInAll()}.
- */
- public static class ReplaceConfigCreatesLonersInAll implements Serializable {
-
- @Rule
- public CacheRule cacheRule =
- CacheRule.builder().replaceConfig(new Properties()).createCacheInAll().build();
@Test
- public void replaceConfig_createsLonersInAll() throws Exception {
+ public void emptyConfig_createsLonersInAll() throws Exception {
assertThat(cacheRule.getCache().getDistributionManager().getViewMembers()).hasSize(1);
- for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
+ for (int i = 0; i < getVMCount(); i++) {
+ getVM(i).invoke(() -> {
assertThat(cacheRule.getCache().getDistributionManager().getViewMembers()).hasSize(1);
});
}
--
To stop receiving notification emails like this one, please contact
klund@apache.org.