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 2017/10/02 19:04:52 UTC

[geode] branch develop updated: GEODE-3715: improve javadocs of DistributedTest rules

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


The following commit(s) were added to refs/heads/develop by this push:
     new 75c8a74  GEODE-3715: improve javadocs of DistributedTest rules
75c8a74 is described below

commit 75c8a74b7a976d14ce33b84f4a187cafd64aacb7
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Mon Oct 2 11:50:52 2017 -0700

    GEODE-3715: improve javadocs of DistributedTest rules
---
 .../geode/test/dunit/cache/rules/CacheRule.java    | 31 ++++++++++--
 .../test/dunit/rules/DistributedTestRule.java      |  6 ++-
 .../geode/test/dunit/rules/SharedCountersRule.java | 59 ++++++++++++++++++++++
 3 files changed, 90 insertions(+), 6 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/cache/rules/CacheRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/cache/rules/CacheRule.java
index 7a6cfa1..7d81ebd 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/cache/rules/CacheRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/cache/rules/CacheRule.java
@@ -18,7 +18,6 @@ import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
 import static org.apache.geode.test.dunit.DistributedTestUtils.getLocators;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
@@ -29,6 +28,32 @@ import org.apache.geode.test.dunit.Disconnect;
 import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.dunit.rules.DistributedExternalResource;
 
+/**
+ * JUnit Rule that creates Cache instances in DistributedTest VMs without {@code CacheTestCase}.
+ *
+ * <p>
+ * {@code CacheRule} follows the standard convention of using a {@code Builder} for configuration as
+ * introduced in the JUnit {@code Timeout} rule.
+ *
+ * <p>
+ * {@code CacheRule} can be used in DistributedTests as a {@code Rule}:
+ *
+ * <pre>
+ * {@literal @}ClassRule
+ * public static DistributedTestRule distributedTestRule = new DistributedTestRule();
+ *
+ * {@literal @}Rule
+ * public CacheRule cacheRule = CacheRule.builder().createCacheInAll().build();
+ *
+ * {@literal @}Test
+ * public void everyVMShouldHaveACache() {
+ *   assertThat(cacheRule.getCache()).isNotNull();
+ *   for (VM vm : Host.getHost(0).getAllVMs()) {
+ *     vm.invoke(() -> assertThat(cacheRule.getCache()).isNotNull());
+ *   }
+ * }
+ * </pre>
+ */
 @SuppressWarnings({"serial", "unused"})
 public class CacheRule extends DistributedExternalResource {
 
@@ -84,10 +109,6 @@ public class CacheRule extends DistributedExternalResource {
     return cache.getInternalDistributedSystem();
   }
 
-  public static InternalCache getCacheForTesting() {
-    return cache;
-  }
-
   private static void createCache(final Properties config) {
     cache = (InternalCache) new CacheFactory(config).create();
   }
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedTestRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedTestRule.java
index 9aaf0b9..563c7d1 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedTestRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/DistributedTestRule.java
@@ -24,7 +24,11 @@ import org.apache.geode.test.dunit.standalone.DUnitLauncher;
  * to implement {@code Serializable}.
  *
  * <p>
- * DistributedTestRule can be used in DistributedTests:
+ * {@code DistributedTestRule} follows the standard convention of using a {@code Builder} for
+ * configuration as introduced in the JUnit {@code Timeout} rule.
+ *
+ * <p>
+ * {@code DistributedTestRule} can be used in DistributedTests as a {@code ClassRule}:
  *
  * <pre>
  * {@literal @}ClassRule
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/SharedCountersRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/SharedCountersRule.java
index f94ac9a..5602bcb 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/SharedCountersRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/SharedCountersRule.java
@@ -25,6 +25,36 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.geode.test.dunit.VM;
 
+/**
+ * JUnit Rule that provides SharedCounters in DistributedTest VMs.
+ *
+ * <p>
+ * {@code SharedCountersRule} follows the standard convention of using a {@code Builder} for
+ * configuration as introduced in the JUnit {@code Timeout} rule.
+ *
+ * <p>
+ * {@code SharedCountersRule} can be used in DistributedTests as a {@code Rule}:
+ *
+ * <pre>
+ * {@literal @}ClassRule
+ * public static DistributedTestRule distributedTestRule = new DistributedTestRule();
+ *
+ * {@literal @}Rule
+ * public CacheRule cacheRule = CacheRule.builder().createCacheInAll().build();
+ *
+ * {@literal @}Rule
+ * public SharedCountersRule sharedCountersRule = SharedCountersRule.builder().withId(ID1).build();
+ *
+ * {@literal @}Test
+ * public void everyVMShouldHaveACache() {
+ *   sharedCountersRule.increment(ID1);
+ *   for (VM vm : Host.getHost(0).getAllVMs()) {
+ *     vm.invoke(() -> sharedCountersRule.increment(ID1));
+ *   }
+ *   assertThat(sharedCountersRule.getTotal(ID1)).isEqualTo(5);
+ * }
+ * </pre>
+ */
 @SuppressWarnings({"serial", "unused"})
 public class SharedCountersRule extends DistributedExternalResource {
 
@@ -59,36 +89,59 @@ public class SharedCountersRule extends DistributedExternalResource {
     invoker().invokeInEveryVM(() -> counters = null);
   }
 
+  /**
+   * Initialize an {@code AtomicInteger} with value of zero identified by {@code id} in every
+   * {@code VM}.
+   */
   public SharedCountersRule initialize(final Serializable id) {
     AtomicInteger value = new AtomicInteger();
     invoker().invokeInEveryVM(() -> counters.putIfAbsent(id, value));
     return this;
   }
 
+  /**
+   * Returns the {@code AtomicInteger} identified by the specified {@code id}.
+   */
   public AtomicInteger reference(final Serializable id) {
     return counters.get(id);
   }
 
+  /**
+   * Increments the {@code AtomicInteger} identified by the specified {@code id}.
+   */
   public SharedCountersRule increment(final Serializable id) {
     counters.get(id).incrementAndGet();
     return this;
   }
 
+  /**
+   * Increments the {@code AtomicInteger} by the specified {@code delta} which may be a positive or
+   * negative integer.
+   */
   public SharedCountersRule increment(final Serializable id, final int delta) {
     counters.get(id).addAndGet(delta);
     return this;
   }
 
+  /**
+   * Increments the {@code AtomicInteger} identified by the specified {@code id}.
+   */
   public SharedCountersRule decrement(final Serializable id) {
     counters.get(id).decrementAndGet();
     return this;
   }
 
+  /**
+   * Decrements the {@code AtomicInteger} by the specified {@code delta}.
+   */
   public SharedCountersRule decrement(final Serializable id, final int delta) {
     counters.get(id).addAndGet(-delta);
     return this;
   }
 
+  /**
+   * Returns the total value of the {@code AtomicInteger} combined across every VM.
+   */
   public int getTotal(final Serializable id) {
     int total = counters.get(id).get();
     for (VM vm : getHost(0).getAllVMs()) {
@@ -97,6 +150,9 @@ public class SharedCountersRule extends DistributedExternalResource {
     return total;
   }
 
+  /**
+   * Returns the local value of the {@code AtomicInteger} identified by the specified {@code id}.
+   */
   public int getLocal(final Serializable id) {
     return counters.get(id).get();
   }
@@ -112,6 +168,9 @@ public class SharedCountersRule extends DistributedExternalResource {
       // nothing
     }
 
+    /**
+     * Initialize specified id when {@code SharedCountersRule} is built.
+     */
     public Builder withId(final Serializable id) {
       ids.add(id);
       return this;

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].