kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [1/2] incubator-kudu git commit: [java] waitForTabletServers should belong to the mini cluster
Date Tue, 26 Jan 2016 01:30:34 GMT
Repository: incubator-kudu
Updated Branches:
  refs/heads/master ffd84cf9c -> 7900bd5ce


[java] waitForTabletServers should belong to the mini cluster

Waiting for the number of tservers to reach a certain point is a
common enough need that it should be part of the mini cluster.

Change-Id: I527b09e3dc530f186a7f5cf141c3f460613cf51c
Reviewed-on: http://gerrit.cloudera.org:8080/1875
Reviewed-by: Todd Lipcon <todd@apache.org>
Tested-by: Todd Lipcon <todd@apache.org>


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

Branch: refs/heads/master
Commit: 76e285e7f267da5b14f87cebf12cc28b4b28bd3b
Parents: ffd84cf
Author: Jean-Daniel Cryans <jdcryans@cloudera.com>
Authored: Fri Jan 22 09:26:45 2016 -0800
Committer: Todd Lipcon <todd@apache.org>
Committed: Mon Jan 25 19:58:10 2016 +0000

----------------------------------------------------------------------
 .../java/org/kududb/client/BaseKuduTest.java    | 20 +--------
 .../java/org/kududb/client/MiniKuduCluster.java | 45 ++++++++++++++++++--
 2 files changed, 44 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/76e285e7/java/kudu-client/src/test/java/org/kududb/client/BaseKuduTest.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/test/java/org/kududb/client/BaseKuduTest.java b/java/kudu-client/src/test/java/org/kududb/client/BaseKuduTest.java
index d1a1410..c6f06b5 100644
--- a/java/kudu-client/src/test/java/org/kududb/client/BaseKuduTest.java
+++ b/java/kudu-client/src/test/java/org/kududb/client/BaseKuduTest.java
@@ -77,6 +77,7 @@ public class BaseKuduTest {
     miniCluster = new MiniKuduCluster.MiniKuduClusterBuilder()
         .numMasters(NUM_MASTERS)
         .numTservers(NUM_TABLET_SERVERS)
+        .defaultTimeoutMs(DEFAULT_SLEEP)
         .build();
     masterAddresses = miniCluster.getMasterAddresses();
     masterHostPorts = miniCluster.getMasterHostPorts();
@@ -85,28 +86,11 @@ public class BaseKuduTest {
     client = new AsyncKuduClient.AsyncKuduClientBuilder(masterAddresses).build();
     syncClient = new KuduClient(client);
     LOG.info("Waiting for tablet servers...");
-    if (!waitForTabletServers(NUM_TABLET_SERVERS)) {
+    if (!miniCluster.waitForTabletServers(NUM_TABLET_SERVERS)) {
       fail("Couldn't get " + NUM_TABLET_SERVERS + " tablet servers running, aborting");
     }
   }
 
-  /**
-   * Wait up to DEFAULT_SLEEP for an expected count of TS to connect to the master
-   * @param expected How many TS are expected
-   * @return true if there are at least as many TS as expected, otherwise false
-   */
-  static boolean waitForTabletServers(int expected) throws Exception {
-    int count = 0;
-    Stopwatch stopwatch = new Stopwatch().start();
-    while (count < expected && stopwatch.elapsedMillis() < DEFAULT_SLEEP) {
-      Thread.sleep(200);
-      Deferred<ListTabletServersResponse> d = client.listTabletServers();
-      d.addErrback(defaultErrorCB);
-      count = d.join(DEFAULT_SLEEP).getTabletServersCount();
-    }
-    return count >= expected;
-  }
-
   @AfterClass
   public static void tearDownAfterClass() throws Exception {
     try {

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/76e285e7/java/kudu-client/src/test/java/org/kududb/client/MiniKuduCluster.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/test/java/org/kududb/client/MiniKuduCluster.java b/java/kudu-client/src/test/java/org/kududb/client/MiniKuduCluster.java
index 4ec0f60..9bd5442 100644
--- a/java/kudu-client/src/test/java/org/kududb/client/MiniKuduCluster.java
+++ b/java/kudu-client/src/test/java/org/kududb/client/MiniKuduCluster.java
@@ -15,6 +15,7 @@ package org.kududb.client;
 
 import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
+import com.google.common.base.Stopwatch;
 import com.google.common.collect.Lists;
 import com.google.common.net.HostAndPort;
 import org.apache.commons.io.FileUtils;
@@ -28,7 +29,6 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
-import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -62,10 +62,37 @@ public class MiniKuduCluster implements AutoCloseable {
   private final List<String> pathsToDelete = new ArrayList<>();
   private final List<HostAndPort> masterHostPorts = new ArrayList<>();
 
+  // Client we can use for common operations.
+  private final KuduClient syncClient;
+  private final int defaultTimeoutMs;
+
   private String masterAddresses;
 
-  private MiniKuduCluster(int numMasters, int numTservers) throws Exception {
+  private MiniKuduCluster(int numMasters, int numTservers, int defaultTimeoutMs) throws Exception
{
+    this.defaultTimeoutMs = defaultTimeoutMs;
+
     startCluster(numMasters, numTservers);
+
+    syncClient = new KuduClient.KuduClientBuilder(getMasterAddresses())
+        .defaultAdminOperationTimeoutMs(defaultTimeoutMs)
+        .defaultOperationTimeoutMs(defaultTimeoutMs)
+        .build();
+  }
+
+  /**
+   * Wait up to this instance's "default timeout" for an expected count of TS to
+   * connect to the master.
+   * @param expected How many TS are expected
+   * @return true if there are at least as many TS as expected, otherwise false
+   */
+  public boolean waitForTabletServers(int expected) throws Exception {
+    int count = 0;
+    Stopwatch stopwatch = new Stopwatch().start();
+    while (count < expected && stopwatch.elapsedMillis() < defaultTimeoutMs)
{
+      Thread.sleep(200);
+      count = syncClient.listTabletServers().getTabletServersCount();
+    }
+    return count >= expected;
   }
 
   /**
@@ -369,6 +396,7 @@ public class MiniKuduCluster implements AutoCloseable {
 
     private int numMasters = 1;
     private int numTservers = 3;
+    private int defaultTimeoutMs = 50000;
 
     public MiniKuduClusterBuilder numMasters(int numMasters) {
       this.numMasters = numMasters;
@@ -380,8 +408,19 @@ public class MiniKuduCluster implements AutoCloseable {
       return this;
     }
 
+    /**
+     * Configures the internal client to use the given timeout for all operations. Also uses
the
+     * timeout for tasks like waiting for tablet servers to check in with the master.
+     * @param defaultTimeoutMs timeout in milliseconds
+     * @return this instance
+     */
+    public MiniKuduClusterBuilder defaultTimeoutMs(int defaultTimeoutMs) {
+      this.defaultTimeoutMs = defaultTimeoutMs;
+      return this;
+    }
+
     public MiniKuduCluster build() throws Exception {
-      return new MiniKuduCluster(numMasters, numTservers);
+      return new MiniKuduCluster(numMasters, numTservers, defaultTimeoutMs);
     }
   }
 


Mime
View raw message