kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danburk...@apache.org
Subject [1/3] kudu git commit: java: refactor ITClientStress for more reusable code
Date Wed, 12 Jul 2017 18:27:06 GMT
Repository: kudu
Updated Branches:
  refs/heads/master bce46e12f -> 69ee17dc7


java: refactor ITClientStress for more reusable code

Change-Id: I263b5681b52df0fa496cce2f58c0605c66810e64
Reviewed-on: http://gerrit.cloudera.org:8080/7360
Tested-by: Kudu Jenkins
Reviewed-by: Jean-Daniel Cryans <jdcryans@apache.org>
Reviewed-by: Alexey Serbin <aserbin@cloudera.com>


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

Branch: refs/heads/master
Commit: ac2a2852ed6b593f9ea6a56190b2e1bea4122964
Parents: bce46e1
Author: Todd Lipcon <todd@apache.org>
Authored: Wed Jul 5 17:50:50 2017 -0700
Committer: Jean-Daniel Cryans <jdcryans@apache.org>
Committed: Wed Jul 12 18:13:07 2017 +0000

----------------------------------------------------------------------
 .../org/apache/kudu/client/ITClientStress.java  | 84 +++++++++++++-------
 1 file changed, 55 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/ac2a2852/java/kudu-client/src/test/java/org/apache/kudu/client/ITClientStress.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/ITClientStress.java b/java/kudu-client/src/test/java/org/apache/kudu/client/ITClientStress.java
index 7e57a1c..89f2fa3 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/ITClientStress.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/ITClientStress.java
@@ -18,71 +18,97 @@ package org.apache.kudu.client;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.Closeable;
+import java.io.IOException;
+import java.util.concurrent.Callable;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 
 import com.google.common.base.Stopwatch;
+import com.google.common.base.Supplier;
+
 import org.junit.Test;
 
 import org.apache.kudu.util.CapturingLogAppender;
 
 public class ITClientStress extends BaseKuduTest {
 
-  /**
-   * Regression test for KUDU-1963. This simulates the behavior of the
-   * Impala 2.8 front-end under a high-concurrency workload. Each query
-   * starts a new client, fetches scan tokens, and closes the client.
-   */
-  @Test(timeout=60000)
-  public void testManyShortClientsGeneratingScanTokens() throws Exception {
-    final String TABLE_NAME = "testManyClients";
-    final int SECONDS_TO_RUN = 10;
-    final int NUM_THREADS = 80;
-    createFourTabletsTableWithNineRows(TABLE_NAME);
+  private void runTasks(int numThreads, int secondsToRun,
+      Supplier<Callable<Void>> taskFactory) throws InterruptedException, IOException
{
+    // Capture any exception thrown by the tasks.
+    final AtomicReference<Throwable> thrown = new AtomicReference<>(null);
 
     // Setup a pool with synchronous handoff.
     SynchronousQueue<Runnable> queue = new SynchronousQueue<>();
     ThreadPoolExecutor pool = new ThreadPoolExecutor(
-        NUM_THREADS, NUM_THREADS, 100, TimeUnit.MILLISECONDS,
+        numThreads, numThreads, 100, TimeUnit.MILLISECONDS,
         queue, new ThreadPoolExecutor.CallerRunsPolicy());
 
-    // Capture any exception thrown by the tasks.
-    final AtomicReference<Throwable> thrown = new AtomicReference<>(null);
-
     // Capture logs so we can check that no exceptions are logged.
     CapturingLogAppender cla = new CapturingLogAppender();
-    try (Closeable c = cla.attach()) {
-      // Submit tasks for the prescribed amount of time.
+    try (Closeable c = cla.attach()){
       Stopwatch s = Stopwatch.createStarted();
-      while (s.elapsed(TimeUnit.SECONDS) < SECONDS_TO_RUN &&
-             thrown.get() == null) {
-        pool.submit(new Runnable() {
+      while (s.elapsed(TimeUnit.SECONDS) < secondsToRun &&
+          thrown.get() == null) {
+        final Callable<Void> task = taskFactory.get();
+        // Wrap the task so that if it throws an exception, we stop and
+        // fail the test.
+        Runnable wrapped = new Runnable() {
           @Override
           public void run() {
-            try (AsyncKuduClient client =
-                  new AsyncKuduClient.AsyncKuduClientBuilder(masterAddresses)
-                  .defaultAdminOperationTimeoutMs(DEFAULT_SLEEP)
-                  .build()) {
-              KuduTable t = client.openTable(TABLE_NAME).join();
-              new KuduScanToken.KuduScanTokenBuilder(client, t).build();
+            try {
+              task.call();
             } catch (Throwable t) {
               thrown.set(t);
             }
           }
-        });
+        };
+        pool.submit(wrapped);
       }
+    } finally {
       pool.shutdown();
-      pool.awaitTermination(10, TimeUnit.SECONDS);
+      assertTrue(pool.awaitTermination(10, TimeUnit.SECONDS));
+      assertNull(thrown.get());
     }
-    assertNull(thrown.get());
     assertFalse("log contained NPE",
         cla.getAppendedText().contains("NullPointerException"));
     assertFalse("log contained SSLException",
         cla.getAppendedText().contains("SSLException"));
   }
 
+  /**
+   * Regression test for KUDU-1963. This simulates the behavior of the
+   * Impala 2.8 front-end under a high-concurrency workload. Each query
+   * starts a new client, fetches scan tokens, and closes the client.
+   */
+  @Test(timeout=60000)
+  public void testManyShortClientsGeneratingScanTokens() throws Exception {
+    final String TABLE_NAME = "testManyClients";
+    final int SECONDS_TO_RUN = 10;
+    final int NUM_THREADS = 80;
+    createFourTabletsTableWithNineRows(TABLE_NAME);
+
+    runTasks(NUM_THREADS, SECONDS_TO_RUN, new Supplier<Callable<Void>>() {
+      @Override
+      public Callable<Void> get() {
+        return new Callable<Void>() {
+          @Override
+          public Void call() throws Exception {
+            try (AsyncKuduClient client =
+                  new AsyncKuduClient.AsyncKuduClientBuilder(masterAddresses)
+                  .defaultAdminOperationTimeoutMs(DEFAULT_SLEEP)
+                  .build()) {
+              KuduTable t = client.openTable(TABLE_NAME).join();
+              new KuduScanToken.KuduScanTokenBuilder(client, t).build();
+            }
+            return null;
+          }
+        };
+      }
+    });
+  }
 }


Mime
View raw message