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 2016/03/16 23:16:44 UTC

incubator-geode git commit: Add new preTearDownAssertions and postTearDownAssertions callbacks. Add new dunit test using tear down assertions callbacks to verify that overriding getDistributedSystemProperties() results in disconnectAllFromDS during tear

Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-1050 dd3e6c0f8 -> e985efea8


Add new preTearDownAssertions and postTearDownAssertions callbacks.
Add new dunit test using tear down assertions callbacks to verify that overriding getDistributedSystemProperties() results in disconnectAllFromDS during tear down of dunit.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/e985efea
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/e985efea
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/e985efea

Branch: refs/heads/feature/GEODE-1050
Commit: e985efea8207851c653a90c0d48879db63d576d1
Parents: dd3e6c0
Author: Kirk Lund <kl...@apache.org>
Authored: Wed Mar 16 15:15:14 2016 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Wed Mar 16 15:15:14 2016 -0700

----------------------------------------------------------------------
 .../dunit/internal/DistributedTestFixture.java  | 20 ++++++-
 .../internal/JUnit3DistributedTestCase.java     | 20 +++++++
 .../internal/JUnit4DistributedTestCase.java     | 25 ++++++++-
 ...ingGetPropertiesDisconnectsAllDUnitTest.java | 59 ++++++++++++++++++++
 4 files changed, 120 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e985efea/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java
index 34eadf7..46c24b2 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java
@@ -47,13 +47,31 @@ public interface DistributedTestFixture {
   public void preTearDown() throws Exception;
 
   /**
-   * {@code postTearDown()</code> is invoked after {@code DistributedTestCase#tearDown()}.
+   * {@code postTearDown()} is invoked after {@code DistributedTestCase#tearDown()}.
    *
    * <p>Override this as needed. Default implementation is empty.
    */
   public void postTearDown() throws Exception;
 
   /**
+   * {@code preTearDownAssertions()} is invoked before any tear down methods
+   * have been invoked. If this method throws anything, tear down methods will
+   * still be invoked.
+   *
+   * <p>Override this as needed. Default implementation is empty.
+   */
+  public void preTearDownAssertions() throws Exception;
+
+  /**
+   * {@code postTearDownAssertions()} is invoked after all tear down methods
+   * have completed. This method will not be invoked if
+   * {@code preTearDownAssertions()} throws.
+   *
+   * <p>Override this as needed. Default implementation is empty.
+   */
+  public void postTearDownAssertions() throws Exception;
+
+  /**
    * Returns the {@code Properties} used to define the {@code DistributedSystem}.
    *
    * <p>Override this as needed. This method is called by various

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e985efea/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java
index ecdbb5f..2f120de 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java
@@ -225,6 +225,26 @@ public abstract class JUnit3DistributedTestCase extends TestCase implements Dist
   public void postTearDown() throws Exception {
   }
 
+  /**
+   * {@code preTearDownAssertions()} is invoked before any tear down methods
+   * have been invoked. If this method throws anything, tear down methods will
+   * still be invoked.
+   *
+   * <p>Override this as needed. Default implementation is empty.
+   */
+  public void preTearDownAssertions() throws Exception {
+  }
+
+  /**
+   * {@code postTearDownAssertions()} is invoked after all tear down methods
+   * have completed. This method will not be invoked if
+   * {@code preTearDownAssertions()} throws.
+   *
+   * <p>Override this as needed. Default implementation is empty.
+   */
+  public void postTearDownAssertions() throws Exception {
+  }
+
   protected static final void destroyRegions(final Cache cache) { // TODO: this should move to CacheTestCase
     JUnit4DistributedTestCase.destroyRegions(cache);
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e985efea/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
index 921e325..ad1e01a 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
@@ -473,9 +473,14 @@ public class JUnit4DistributedTestCase implements DistributedTestFixture, Serial
    */
   @After
   public final void tearDown() throws Exception {
-    preTearDown();
-    tearDownDistributedTestCase();
-    postTearDown();
+    try {
+      preTearDownAssertions();
+    } finally {
+      preTearDown();
+      tearDownDistributedTestCase();
+      postTearDown();
+    }
+    postTearDownAssertions();
   }
 
   private final void tearDownDistributedTestCase() throws Exception {
@@ -513,6 +518,20 @@ public class JUnit4DistributedTestCase implements DistributedTestFixture, Serial
     }
   }
 
+  @Override
+  public void preTearDownAssertions() throws Exception {
+    if (this.distributedTestFixture != this) {
+      this.distributedTestFixture.preTearDownAssertions();
+    }
+  }
+
+  @Override
+  public void postTearDownAssertions() throws Exception {
+    if (this.distributedTestFixture != this) {
+      this.distributedTestFixture.postTearDownAssertions();
+    }
+  }
+
   private static final void cleanupAllVms() {
     tearDownVM();
     Invoke.invokeInEveryVM(()->tearDownVM());

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e985efea/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/OverridingGetPropertiesDisconnectsAllDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/OverridingGetPropertiesDisconnectsAllDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/OverridingGetPropertiesDisconnectsAllDUnitTest.java
new file mode 100644
index 0000000..75cd760
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/OverridingGetPropertiesDisconnectsAllDUnitTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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 com.gemstone.gemfire.test.dunit.tests;
+
+import static com.gemstone.gemfire.test.dunit.Invoke.*;
+
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.internal.process.ProcessUtils;
+import com.gemstone.gemfire.test.dunit.DistributedTestCase;
+
+/**
+ * Verifies that overriding {@code getDistributedSystemProperties} results
+ * in {@code disconnectAllFromDS} during tear down.
+ */
+public class OverridingGetPropertiesDisconnectsAllDUnitTest extends DistributedTestCase {
+
+  public OverridingGetPropertiesDisconnectsAllDUnitTest(final String name) {
+    super(name);
+  }
+
+  @Override
+  public final void preTearDownAssertions() throws Exception {
+    invokeInEveryVM(() -> assertNotNull(basicGetSystem()));
+  }
+
+  @Override
+  public final void postTearDownAssertions() throws Exception {
+    invokeInEveryVM(() -> assertNull(basicGetSystem()));
+  }
+
+  @Override
+  public final Properties getDistributedSystemProperties() {
+    Properties props = new Properties();
+    props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
+    return props;
+  }
+
+  public void testDisconnects() throws Exception {
+    invokeInEveryVM(() -> assertFalse(getDistributedSystemProperties().isEmpty()));
+    invokeInEveryVM(() -> assertNotNull(getSystem()));
+  }
+}