Speed up CheckUtilTest 65/78765/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 13 Dec 2018 16:54:35 +0000 (17:54 +0100)
committerRobert Varga <nite@hq.sk>
Thu, 13 Dec 2018 18:21:33 +0000 (18:21 +0000)
Waiting 200 seconds for a simple test is simply not acceptable.
Refactor CheckUtil to expose a waitFutureSuccess() which takes
a timeout and use that for testing the class.

Change-Id: I951dd1f1357eb02360e239b0ba41c10db0bfde7f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
testtool-util/src/main/java/org/opendaylight/protocol/util/CheckUtil.java
testtool-util/src/test/java/org/opendaylight/protocol/util/CheckUtilTest.java

index 8edd0a147c01ecc21e778aa175de8cef30155310..59ef100e09f48f247af459f371ab4ffacdf745b3 100644 (file)
@@ -7,13 +7,13 @@
  */
 package org.opendaylight.protocol.util;
 
+import static com.google.common.base.Verify.verify;
 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
 import com.google.common.base.Stopwatch;
-import com.google.common.base.Verify;
 import com.google.common.util.concurrent.Uninterruptibles;
 import io.netty.util.concurrent.Future;
 import java.util.concurrent.CountDownLatch;
@@ -36,10 +36,15 @@ public final class CheckUtil {
     }
 
     public static <T extends Future<?>> void waitFutureSuccess(final T future) {
+        waitFutureSuccess(future, SLEEP_FOR, TimeUnit.SECONDS);
+    }
+
+    @VisibleForTesting
+    static <T extends Future<?>> void waitFutureSuccess(final T future, final long timeout, final TimeUnit unit) {
         final CountDownLatch latch = new CountDownLatch(1);
         future.addListener(future1 -> latch.countDown());
-        Uninterruptibles.awaitUninterruptibly(latch, SLEEP_FOR, TimeUnit.SECONDS);
-        Verify.verify(future.isSuccess());
+        Uninterruptibles.awaitUninterruptibly(latch, timeout, unit);
+        verify(future.isSuccess());
     }
 
     public static <R, T extends DataObject> R readDataOperational(final DataBroker dataBroker,
index 638e34248d114e5044795d6fc4c0e5b41f04fd4c..478720e1fbc6414c4bc43d4ce1a1ff9c59b859ed 100644 (file)
@@ -27,6 +27,7 @@ import com.google.common.base.VerifyException;
 import io.netty.channel.ChannelFuture;
 import io.netty.util.concurrent.GenericFutureListener;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -64,7 +65,7 @@ public class CheckUtilTest extends AbstractConcurrentDataBrokerTest {
     public void testWaitFutureSuccessFail() {
         when(this.future.isDone()).thenReturn(false);
         doReturn(this.future).when(this.future).addListener(any());
-        waitFutureSuccess(this.future);
+        waitFutureSuccess(this.future, 10L, TimeUnit.MILLISECONDS);
     }
 
     @Test