This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new ffa292c  [java] use KuduTestHarness in TestConnectToCluster
ffa292c is described below

commit ffa292c77a85bf7f01352eb3278c48ad5dd0f373
Author: Alexey Serbin <[email protected]>
AuthorDate: Thu Mar 12 14:59:24 2020 -0700

    [java] use KuduTestHarness in TestConnectToCluster
    
    Change-Id: Ia845b073d68380946e1b5e59c56508007a154702
    Reviewed-on: http://gerrit.cloudera.org:8080/15423
    Reviewed-by: Grant Henke <[email protected]>
    Tested-by: Kudu Jenkins
---
 .../org/apache/kudu/client/ConnectToCluster.java   | 10 +---
 .../apache/kudu/client/TestConnectToCluster.java   | 56 +++++++++-------------
 2 files changed, 23 insertions(+), 43 deletions(-)

diff --git 
a/java/kudu-client/src/main/java/org/apache/kudu/client/ConnectToCluster.java 
b/java/kudu-client/src/main/java/org/apache/kudu/client/ConnectToCluster.java
index 429e34e..f11da51 100644
--- 
a/java/kudu-client/src/main/java/org/apache/kudu/client/ConnectToCluster.java
+++ 
b/java/kudu-client/src/main/java/org/apache/kudu/client/ConnectToCluster.java
@@ -81,6 +81,7 @@ final class ConnectToCluster {
   ConnectToCluster(List<HostAndPort> masterAddrs) {
     this.masterAddrs = masterAddrs;
     this.responseD = new Deferred<>();
+    this.numMasters = masterAddrs.size();
   }
 
   @InterfaceAudience.LimitedPrivate("Test")
@@ -93,15 +94,6 @@ final class ConnectToCluster {
     return exceptionsReceived;
   }
 
-  /**
-   * Set the number of masters.
-   * Only used for testing.
-   * @param numMasters the number of masters.
-   */
-  public void setNumMasters(int numMasters) {
-    this.numMasters = numMasters;
-  }
-
   private static Deferred<ConnectToMasterResponsePB> connectToMaster(
       final KuduTable masterTable,
       final RpcProxy masterProxy,
diff --git 
a/java/kudu-client/src/test/java/org/apache/kudu/client/TestConnectToCluster.java
 
b/java/kudu-client/src/test/java/org/apache/kudu/client/TestConnectToCluster.java
index 4b1d4a3..cdb080e 100644
--- 
a/java/kudu-client/src/test/java/org/apache/kudu/client/TestConnectToCluster.java
+++ 
b/java/kudu-client/src/test/java/org/apache/kudu/client/TestConnectToCluster.java
@@ -34,8 +34,9 @@ import org.junit.Test;
 
 import org.apache.kudu.consensus.Metadata;
 import org.apache.kudu.master.Master.ConnectToMasterResponsePB;
+import org.apache.kudu.test.KuduTestHarness;
+import org.apache.kudu.test.KuduTestHarness.MasterServerConfig;
 import org.apache.kudu.test.cluster.MiniKuduCluster;
-import org.apache.kudu.test.junit.RetryRule;
 
 public class TestConnectToCluster {
 
@@ -45,7 +46,7 @@ public class TestConnectToCluster {
       new HostAndPort("2", 9000));
 
   @Rule
-  public RetryRule retryRule = new RetryRule();
+  public KuduTestHarness harness = new KuduTestHarness();
 
   /**
    * Test that the client properly falls back to the old GetMasterRegistration
@@ -53,18 +54,11 @@ public class TestConnectToCluster {
    * ConnectToMaster RPC.
    */
   @Test(timeout = 60000)
+  @MasterServerConfig(flags = { "--master_support_connect_to_master_rpc=0" })
   public void testFallbackConnectRpc() throws Exception {
-    try (MiniKuduCluster cluster = new MiniKuduCluster.MiniKuduClusterBuilder()
-         .addMasterServerFlag("--master_support_connect_to_master_rpc=0")
-         .numMasterServers(1)
-         .numTabletServers(0)
-         .build();
-         KuduClient c = new 
KuduClient.KuduClientBuilder(cluster.getMasterAddressesAsString())
-             .build()) {
-      // Call some method which uses the master. This forces us to connect
-      // and verifies that the fallback works.
-      c.listTabletServers();
-    }
+    // Call some method which uses the master. This forces us to connect
+    // and verifies that the fallback works.
+    harness.getClient().listTabletServers();
   }
 
   /**
@@ -76,26 +70,21 @@ public class TestConnectToCluster {
   @Test(timeout = 60000)
   public void testConnectToOneOfManyMasters() throws Exception {
     int successes = 0;
-    try (MiniKuduCluster cluster = new MiniKuduCluster.MiniKuduClusterBuilder()
-         .numMasterServers(3)
-         .numTabletServers(0)
-         .build()) {
-      String[] masterAddrs = cluster.getMasterAddressesAsString().split(",", 
-1);
-      assertEquals(3, masterAddrs.length);
-      for (String masterAddr : masterAddrs) {
-        try (KuduClient c = new 
KuduClient.KuduClientBuilder(masterAddr).build()) {
-          // Call some method which uses the master. This forces us to connect.
-          c.listTabletServers();
-          successes++;
-        } catch (Exception e) {
-          Assert.assertTrue("unexpected exception: " + e.toString(),
-              e.toString().matches(
-                  ".*Client configured with 1 master\\(s\\) " +
-                  "\\(.+?\\) but cluster indicates it expects 3 master\\(s\\) 
" +
-                  "\\(.+?,.+?,.+?\\).*"));
-          Assert.assertThat(Joiner.on("\n").join(e.getStackTrace()),
-              CoreMatchers.containsString("testConnectToOneOfManyMasters"));
-        }
+    String[] masterAddrs = harness.getMasterAddressesAsString().split(",", -1);
+    assertEquals(3, masterAddrs.length);
+    for (String masterAddr : masterAddrs) {
+      try (KuduClient c = new 
KuduClient.KuduClientBuilder(masterAddr).build()) {
+        // Call some method which uses the master. This forces us to connect.
+        c.listTabletServers();
+        successes++;
+      } catch (Exception e) {
+        Assert.assertTrue("unexpected exception: " + e.toString(),
+            e.toString().matches(
+                ".*Client configured with 1 master\\(s\\) " +
+                "\\(.+?\\) but cluster indicates it expects 3 master\\(s\\) " +
+                "\\(.+?,.+?,.+?\\).*"));
+        Assert.assertThat(Joiner.on("\n").join(e.getStackTrace()),
+            CoreMatchers.containsString("testConnectToOneOfManyMasters"));
       }
     }
 
@@ -248,7 +237,6 @@ public class TestConnectToCluster {
     // add the responses. We then check for the right response.
 
     ConnectToCluster grrm = new ConnectToCluster(MASTERS);
-    grrm.setNumMasters(MASTERS.size());
 
     Callback<Void, ConnectToMasterResponsePB> cb0 = 
grrm.callbackForNode(MASTERS.get(0));
     Callback<Void, ConnectToMasterResponsePB> cb1 = 
grrm.callbackForNode(MASTERS.get(1));

Reply via email to