hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject hadoop git commit: HADOOP-14568. GenericTestUtils#waitFor missing parameter verification. Contributed by Yiqun Lin
Date Fri, 23 Jun 2017 13:41:35 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk ca13b224b -> e5db9af8a


HADOOP-14568. GenericTestUtils#waitFor missing parameter verification.
Contributed by Yiqun Lin


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

Branch: refs/heads/trunk
Commit: e5db9af8a00ded73ee1c75bb4c0d5d50e15a305c
Parents: ca13b22
Author: Steve Loughran <stevel@apache.org>
Authored: Fri Jun 23 14:39:58 2017 +0100
Committer: Steve Loughran <stevel@apache.org>
Committed: Fri Jun 23 14:39:58 2017 +0100

----------------------------------------------------------------------
 .../apache/hadoop/test/GenericTestUtils.java    | 19 +++++++++---
 .../hadoop/test/TestGenericTestUtils.java       | 32 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/e5db9af8/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java
index 7b94784..fcc4e3c 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java
@@ -59,6 +59,7 @@ import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
 import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
 import com.google.common.base.Supplier;
 import com.google.common.collect.Sets;
 
@@ -85,6 +86,14 @@ public abstract class GenericTestUtils {
    */
   public static final String DEFAULT_TEST_DATA_PATH = "target/test/data/";
 
+  /**
+   * Error string used in {@link GenericTestUtils#waitFor(Supplier, int, int)}.
+   */
+  public static final String ERROR_MISSING_ARGUMENT =
+      "Input supplier interface should be initailized";
+  public static final String ERROR_INVALID_ARGUMENT =
+      "Total wait time should be greater than check interval time";
+
   @SuppressWarnings("unchecked")
   public static void disableLog(Log log) {
     // We expect that commons-logging is a wrapper around Log4j.
@@ -258,10 +267,12 @@ public abstract class GenericTestUtils {
     }
   }  
 
-  public static void waitFor(Supplier<Boolean> check,
-      int checkEveryMillis, int waitForMillis)
-      throws TimeoutException, InterruptedException
-  {
+  public static void waitFor(Supplier<Boolean> check, int checkEveryMillis,
+      int waitForMillis) throws TimeoutException, InterruptedException {
+    Preconditions.checkNotNull(check, ERROR_MISSING_ARGUMENT);
+    Preconditions.checkArgument(waitForMillis > checkEveryMillis,
+        ERROR_INVALID_ARGUMENT);
+
     long st = Time.now();
     do {
       boolean result = check.get();

http://git-wip-us.apache.org/repos/asf/hadoop/blob/e5db9af8/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/TestGenericTestUtils.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/TestGenericTestUtils.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/TestGenericTestUtils.java
index 86df5d5..b3fc836 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/TestGenericTestUtils.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/TestGenericTestUtils.java
@@ -26,7 +26,10 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Supplier;
+
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 public class TestGenericTestUtils extends GenericTestUtils {
 
@@ -119,4 +122,33 @@ public class TestGenericTestUtils extends GenericTestUtils {
     assertTrue(logCapturer.getOutput().isEmpty());
   }
 
+  @Test
+  public void testWaitingForConditionWithInvalidParams() throws Throwable {
+    // test waitFor method with null supplier interface
+    try {
+      waitFor(null, 0, 0);
+    } catch (NullPointerException e) {
+      assertExceptionContains(GenericTestUtils.ERROR_MISSING_ARGUMENT, e);
+    }
+
+    Supplier<Boolean> simpleSupplier = new Supplier<Boolean>() {
+
+      @Override
+      public Boolean get() {
+        return true;
+      }
+    };
+
+    // test waitFor method with waitForMillis greater than checkEveryMillis
+    waitFor(simpleSupplier, 5, 10);
+    try {
+      // test waitFor method with waitForMillis smaller than checkEveryMillis
+      waitFor(simpleSupplier, 10, 5);
+      fail(
+          "Excepted a failure when the param value of"
+          + " waitForMillis is smaller than checkEveryMillis.");
+    } catch (IllegalArgumentException e) {
+      assertExceptionContains(GenericTestUtils.ERROR_INVALID_ARGUMENT, e);
+    }
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message