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/04/23 05:46:44 UTC
[geode] 06/13: GEODE-5060: Delete DistributedDisconnectRule
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 f144fb40c1b0aa62f2b6f884fba4bd140f595f68
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Thu Apr 12 12:54:33 2018 -0700
GEODE-5060: Delete DistributedDisconnectRule
DistributedTestRule.TearDown makes DistributedDisconnectRule redundant.
---
.../CatchingUnexpectedExceptionExampleTest.java | 14 +-
.../examples/LocatorPortClusterExampleTest.java | 8 +-
.../dunit/rules/DistributedDisconnectRule.java | 138 ---------------
...edDisconnectRuleAsClassRuleDistributedTest.java | 172 -------------------
.../DistributedDisconnectRuleDistributedTest.java | 187 ---------------------
5 files changed, 5 insertions(+), 514 deletions(-)
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/examples/CatchingUnexpectedExceptionExampleTest.java b/geode-core/src/test/java/org/apache/geode/test/dunit/examples/CatchingUnexpectedExceptionExampleTest.java
index e170dab..fbcab50 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/examples/CatchingUnexpectedExceptionExampleTest.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/examples/CatchingUnexpectedExceptionExampleTest.java
@@ -20,7 +20,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.Serializable;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -32,7 +31,6 @@ import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.RegionFactory;
import org.apache.geode.internal.cache.LocalRegion;
import org.apache.geode.test.dunit.SerializableRunnable;
-import org.apache.geode.test.dunit.rules.DistributedDisconnectRule;
import org.apache.geode.test.dunit.rules.DistributedTestRule;
import org.apache.geode.test.junit.categories.DistributedTest;
@@ -40,18 +38,14 @@ import org.apache.geode.test.junit.categories.DistributedTest;
@SuppressWarnings("serial")
public class CatchingUnexpectedExceptionExampleTest implements Serializable {
- @ClassRule
- public static DistributedTestRule distributedTestRule = new DistributedTestRule();
-
@Rule
- public DistributedDisconnectRule disconnectRule =
- new DistributedDisconnectRule.Builder().disconnectAfter(true).build();
+ public DistributedTestRule distributedTestRule = new DistributedTestRule();
/**
* Don't do this! Catch Exception and invoke fail => anti-pattern
*/
@Test
- public void createRegion_withTryCatch_dontDoThis() throws Exception {
+ public void createRegion_withTryCatch_DO_NOT_DO_THIS() throws Exception {
getVM(0).invoke(new SerializableRunnable("Create Region") {
@Override
public void run() {
@@ -71,7 +65,7 @@ public class CatchingUnexpectedExceptionExampleTest implements Serializable {
* Use "throws Exception" is better!
*/
@Test
- public void createRegion_withThrowsException_thisIsBetter() throws Exception {
+ public void createRegion_withThrowsException_THIS_IS_BETTER() throws Exception {
getVM(0).invoke(new SerializableRunnable("Create Region") {
@Override
public void run() throws Exception {
@@ -87,7 +81,7 @@ public class CatchingUnexpectedExceptionExampleTest implements Serializable {
* Use lambda without having to specify run() with throws Exception -- best!
*/
@Test
- public void createRegion_withLambda_thisIsBest() throws Exception {
+ public void createRegion_withLambda_THIS_IS_BEST() throws Exception {
getVM(0).invoke("Create Region", () -> {
Cache cache = new CacheFactory().create();
RegionFactory regionFactory = cache.createRegionFactory(new AttributesFactory().create());
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/examples/LocatorPortClusterExampleTest.java b/geode-core/src/test/java/org/apache/geode/test/dunit/examples/LocatorPortClusterExampleTest.java
index e391357..a448bf1 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/examples/LocatorPortClusterExampleTest.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/examples/LocatorPortClusterExampleTest.java
@@ -26,7 +26,6 @@ import java.util.Properties;
import org.junit.After;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -34,7 +33,6 @@ import org.junit.experimental.categories.Category;
import org.apache.geode.cache.CacheFactory;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.rules.DistributedDisconnectRule;
import org.apache.geode.test.dunit.rules.DistributedTestRule;
import org.apache.geode.test.junit.categories.DistributedTest;
@@ -42,12 +40,8 @@ import org.apache.geode.test.junit.categories.DistributedTest;
@SuppressWarnings("serial")
public class LocatorPortClusterExampleTest implements Serializable {
- @ClassRule
- public static DistributedTestRule distributedTestRule = new DistributedTestRule();
-
@Rule
- public DistributedDisconnectRule disconnectRule =
- new DistributedDisconnectRule.Builder().disconnectAfter(true).build();
+ public DistributedTestRule distributedTestRule = new DistributedTestRule();
private static InternalCache cache;
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedDisconnectRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedDisconnectRule.java
deleted file mode 100755
index 41f7fc9..0000000
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedDisconnectRule.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.test.dunit.rules;
-
-import static java.util.concurrent.TimeUnit.MINUTES;
-
-import com.google.common.base.Stopwatch;
-
-import org.apache.geode.admin.internal.AdminDistributedSystemImpl;
-import org.apache.geode.distributed.internal.InternalDistributedSystem;
-import org.apache.geode.test.dunit.SerializableRunnable;
-
-/**
- * JUnit Rule that disconnects DistributedSystem in all VMs.
- *
- * <p>
- * DistributedDisconnectRule can be used in DistributedTests to disconnect all VMs before or after
- * each test:
- *
- * <pre>
- * {@literal @}Rule
- * public DistributedDisconnectRule distributedDisconnectRule = new DistributedDisconnectRule();
- *
- * {@literal @}Test
- * public void createCacheInEveryDUnitVM() throws Exception {
- * cache = (InternalCache) new CacheFactory().create();
- * assertThat(cache.isClosed()).isFalse();
- * assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
- *
- * for (VM vm: Host.getHost(0).getAllVMs()) {
- * vm.invoke(() -> {
- * cache = (InternalCache) new CacheFactory().create();
- * assertThat(cache.isClosed()).isFalse();
- * assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
- * });
- * }
- * }
- * </pre>
- */
-public class DistributedDisconnectRule extends DistributedExternalResource {
-
- private final boolean disconnectBefore;
- private final boolean disconnectAfter;
-
- public static Builder builder() {
- return new Builder();
- }
-
- public DistributedDisconnectRule(final Builder builder) {
- this(new RemoteInvoker(), builder);
- }
-
- public DistributedDisconnectRule(final RemoteInvoker invoker, final Builder builder) {
- super(invoker);
- this.disconnectBefore = builder.disconnectBefore;
- this.disconnectAfter = builder.disconnectAfter;
- }
-
- @Override
- protected void before() throws Throwable {
- if (this.disconnectBefore) {
- invoker().invokeInEveryVMAndController(serializableRunnable());
- }
- }
-
- @Override
- protected void after() {
- if (this.disconnectAfter) {
- invoker().invokeInEveryVMAndController(serializableRunnable());
- }
- }
-
- private static SerializableRunnable serializableRunnable() {
- return new SerializableRunnable() {
- @Override
- public void run() {
- disconnect();
- }
- };
- }
-
- public static void disconnect() {
- Stopwatch stopwatch = Stopwatch.createStarted();
- InternalDistributedSystem system = InternalDistributedSystem.getConnectedInstance();
-
- while (system != null && stopwatch.elapsed(MINUTES) < 10) {
- system = InternalDistributedSystem.getConnectedInstance();
- try {
- system.disconnect();
- } catch (Exception ignore) {
- // ignored
- }
- }
-
- AdminDistributedSystemImpl adminSystem = AdminDistributedSystemImpl.getConnectedInstance();
- if (adminSystem != null) {
- adminSystem.disconnect();
- }
- }
-
- /**
- * Builds an instance of DistributedDisconnectRule
- */
- public static class Builder {
- private boolean disconnectBefore;
- private boolean disconnectAfter;
-
- public Builder() {
- // nothing
- }
-
- public Builder disconnectBefore(final boolean disconnectBefore) {
- this.disconnectBefore = disconnectBefore;
- return this;
- }
-
- public Builder disconnectAfter(final boolean disconnectAfter) {
- this.disconnectAfter = disconnectAfter;
- return this;
- }
-
- public DistributedDisconnectRule build() {
- return new DistributedDisconnectRule(this);
- }
- }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/DistributedDisconnectRuleAsClassRuleDistributedTest.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/DistributedDisconnectRuleAsClassRuleDistributedTest.java
deleted file mode 100644
index 5a52574..0000000
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/DistributedDisconnectRuleAsClassRuleDistributedTest.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.test.dunit.rules.tests;
-
-import static org.apache.geode.test.dunit.VM.getAllVMs;
-import static org.apache.geode.test.dunit.rules.DistributedDisconnectRule.disconnect;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.After;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.Result;
-import org.junit.runners.MethodSorters;
-
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.internal.cache.InternalCache;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.rules.DistributedDisconnectRule;
-import org.apache.geode.test.dunit.rules.DistributedTestRule;
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.rules.RuleList;
-import org.apache.geode.test.junit.runners.TestRunner;
-
-@Category(DistributedTest.class)
-public class DistributedDisconnectRuleAsClassRuleDistributedTest {
-
- @After
- public void tearDown() throws Exception {
- disconnect();
- DisconnectBefore.cache = null;
- DisconnectAfter.cache = null;
-
- for (VM vm : Host.getHost(0).getAllVMs()) {
- vm.invoke(() -> {
- disconnect();
- DisconnectBefore.cache = null;
- DisconnectAfter.cache = null;
- });
- }
- }
-
- @Test
- public void disconnectBeforeShouldDisconnectAllBeforeTests() throws Exception {
- Result result = TestRunner.runTest(DisconnectBefore.class);
-
- assertThat(result.wasSuccessful()).isTrue();
-
- assertThat(DisconnectBefore.cache.getInternalDistributedSystem().isConnected()).isTrue();
- assertThat(DisconnectBefore.cache.isClosed()).isFalse();
-
- for (VM vm : Host.getHost(0).getAllVMs()) {
- vm.invoke(() -> {
- assertThat(DisconnectBefore.cache.getInternalDistributedSystem().isConnected()).isTrue();
- assertThat(DisconnectBefore.cache.isClosed()).isFalse();
- });
- }
- }
-
- @Test
- public void disconnectAfterShouldDisconnectAllAfterTests() throws Exception {
- Result result = TestRunner.runTest(DisconnectAfter.class);
-
- assertThat(result.wasSuccessful()).isTrue();
-
- assertThat(DisconnectAfter.cache.getInternalDistributedSystem().isConnected()).isFalse();
- assertThat(DisconnectAfter.cache.isClosed()).isTrue();
-
- for (VM vm : Host.getHost(0).getAllVMs()) {
- vm.invoke(() -> {
- assertThat(DisconnectAfter.cache.getInternalDistributedSystem().isConnected()).isFalse();
- assertThat(DisconnectAfter.cache.isClosed()).isTrue();
- });
- }
- }
-
- /**
- * Used by test {@link #disconnectBeforeShouldDisconnectAllBeforeTests()}
- */
- public static class DisconnectBefore {
-
- @ClassRule
- public static RuleList rules = new RuleList().add(new DistributedTestRule())
- .add(new DistributedDisconnectRule.Builder().disconnectBefore(true).build());
-
- static InternalCache cache;
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- cache = (InternalCache) new CacheFactory().create();
- assertThat(cache.isClosed()).isFalse();
- assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
-
- for (VM vm : getAllVMs()) {
- vm.invoke(() -> {
- cache = (InternalCache) new CacheFactory().create();
- assertThat(cache.isClosed()).isFalse();
- assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
- });
- }
- }
-
- @Test
- public void everyDUnitVMShouldStillBeConnected() throws Exception {
- assertThat(cache.isClosed()).isFalse();
- assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
-
- for (VM vm : getAllVMs()) {
- vm.invoke(() -> {
- assertThat(cache.isClosed()).isFalse();
- assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
- });
- }
- }
- }
-
- /**
- * Used by test {@link #disconnectAfterShouldDisconnectAllAfterTests()}
- */
- @FixMethodOrder(MethodSorters.NAME_ASCENDING)
- public static class DisconnectAfter {
-
- @ClassRule
- public static RuleList rules = new RuleList().add(new DistributedTestRule())
- .add(new DistributedDisconnectRule.Builder().disconnectAfter(true).build());
-
- static InternalCache cache;
-
- @Test
- public void createCacheInEveryVM() throws Exception {
- cache = (InternalCache) new CacheFactory().create();
- assertThat(cache.isClosed()).isFalse();
- assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
-
- for (VM vm : getAllVMs()) {
- vm.invoke(() -> {
- cache = (InternalCache) new CacheFactory().create();
- assertThat(cache.isClosed()).isFalse();
- assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
- });
- }
- }
-
- @Test
- public void everyVMShouldStillBeConnected() throws Exception {
- assertThat(cache.isClosed()).isFalse();
- assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
-
- for (VM vm : getAllVMs()) {
- vm.invoke(() -> {
- assertThat(cache.isClosed()).isFalse();
- assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
- });
- }
- }
- }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/DistributedDisconnectRuleDistributedTest.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/DistributedDisconnectRuleDistributedTest.java
deleted file mode 100644
index 01bbcee..0000000
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/tests/DistributedDisconnectRuleDistributedTest.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.test.dunit.rules.tests;
-
-import static org.apache.geode.test.dunit.VM.getAllVMs;
-import static org.apache.geode.test.dunit.rules.DistributedDisconnectRule.disconnect;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.After;
-import org.junit.ClassRule;
-import org.junit.FixMethodOrder;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.Result;
-import org.junit.runners.MethodSorters;
-
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.internal.cache.InternalCache;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.rules.DistributedDisconnectRule;
-import org.apache.geode.test.dunit.rules.DistributedTestRule;
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.runners.TestRunner;
-
-@Category(DistributedTest.class)
-public class DistributedDisconnectRuleDistributedTest {
-
- private static InternalCache cache;
-
- @ClassRule
- public static DistributedTestRule distributedTestRule = new DistributedTestRule();
-
- @After
- public void tearDown() throws Exception {
- disconnect();
- cache = null;
-
- for (VM vm : getAllVMs()) {
- vm.invoke(() -> {
- disconnect();
- cache = null;
- });
- }
- }
-
- @Test
- public void disconnectShouldDisconnect() throws Exception {
- cache = (InternalCache) new CacheFactory().create();
- assertThat(cache.isClosed()).isFalse();
- assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
-
- disconnect();
-
- assertThat(cache.isClosed()).isTrue();
- assertThat(cache.getInternalDistributedSystem().isConnected()).isFalse();
- }
-
- @Test
- public void disconnectBeforeShouldDisconnectBeforeEachTest() throws Exception {
- createCacheInEveryVM();
- assertThatConnectedInEveryVM();
-
- Result result = TestRunner.runTest(DisconnectBefore.class);
-
- assertThat(result.wasSuccessful()).isTrue();
- assertThatConnectedInEveryVM();
- }
-
- @Test
- public void disconnectAfterShouldDisconnectAfterEachTest() throws Exception {
- createCacheInEveryVM();
- assertThatConnectedInEveryVM();
-
- Result result = TestRunner.runTest(DisconnectAfter.class);
-
- assertThat(result.wasSuccessful()).isTrue();
- assertThatDisconnectedInEveryVM();
- }
-
- static void createCacheInEveryVM() throws Exception {
- cache = (InternalCache) new CacheFactory().create();
-
- for (VM vm : getAllVMs()) {
- vm.invoke(() -> {
- cache = (InternalCache) new CacheFactory().create();
- });
- }
- }
-
- static void assertThatConnectedInEveryVM() throws Exception {
- assertThat(cache.isClosed()).isFalse();
- assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
-
- for (VM vm : getAllVMs()) {
- vm.invoke(() -> {
- assertThat(cache.isClosed()).isFalse();
- assertThat(cache.getInternalDistributedSystem().isConnected()).isTrue();
- });
- }
- }
-
- static void assertThatDisconnectedInEveryVM() throws Exception {
- assertThat(cache.getInternalDistributedSystem().isConnected()).isFalse();
- assertThat(cache.isClosed()).isTrue();
-
- for (VM vm : getAllVMs()) {
- vm.invoke(() -> {
- assertThat(cache.getInternalDistributedSystem().isConnected()).isFalse();
- assertThat(cache.isClosed()).isTrue();
- });
- }
- }
-
- /**
- * Used by test {@link #disconnectBeforeShouldDisconnectBeforeEachTest()}
- */
- @FixMethodOrder(MethodSorters.NAME_ASCENDING)
- public static class DisconnectBefore {
-
- @ClassRule
- public static DistributedTestRule distributedTestRule = new DistributedTestRule();
-
- @Rule
- public DistributedDisconnectRule distributedDisconnectRule =
- new DistributedDisconnectRule.Builder().disconnectBefore(true).build();
-
- @Test
- public void test001CreateCacheInEveryVM() throws Exception {
- assertThatDisconnectedInEveryVM();
- createCacheInEveryVM();
- assertThatConnectedInEveryVM();
- }
-
- @Test
- public void test002EveryVMShouldHaveDisconnected() throws Exception {
- assertThatDisconnectedInEveryVM();
- createCacheInEveryVM();
- assertThatConnectedInEveryVM();
- }
- }
-
- /**
- * Used by test {@link #disconnectAfterShouldDisconnectAfterEachTest()}
- */
- @FixMethodOrder(MethodSorters.NAME_ASCENDING)
- public static class DisconnectAfter {
-
- @ClassRule
- public static DistributedTestRule distributedTestRule = new DistributedTestRule();
-
- @Rule
- public DistributedDisconnectRule distributedDisconnectRule =
- new DistributedDisconnectRule.Builder().disconnectAfter(true).build();
-
- @Test
- public void test001AlreadyHasCacheInEveryVM() throws Exception {
- assertThatConnectedInEveryVM();
- }
-
- @Test
- public void test002CreateCacheInEveryVM() throws Exception {
- assertThatDisconnectedInEveryVM();
- createCacheInEveryVM();
- assertThatConnectedInEveryVM();
- }
-
- @Test
- public void test003EveryVMShouldHaveDisconnected() throws Exception {
- assertThatDisconnectedInEveryVM();
- createCacheInEveryVM();
- assertThatConnectedInEveryVM();
- }
- }
-}
--
To stop receiving notification emails like this one, please contact
klund@apache.org.