java/kudu-client/src/test/java/org/apache/kudu/client/TestConnectToCluster.java
@Test(timeout=60000)
  public void testConnectToOneOfManyMasters() throws Exception {
    MiniKuduCluster cluster = new MiniKuduCluster.MiniKuduClusterBuilder()
        .numMasters(3)
        .numTservers(0)
        .build();
    int successes = 0;
    try {
      String[] masterAddrs = cluster.getMasterAddresses().split(",", -1);
      assertEquals(3, masterAddrs.length);
      for (String masterAddr : masterAddrs) {
        KuduClient c = null;
        try {
          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"));
        } finally {
          if (c != null) {
            c.close();
          }
        }
      }
    } finally {
      cluster.shutdown();
    }
    // Typically, one of the connections will have succeeded. However, it's possible
    // that 0 succeeded in the case that the masters were slow at electing
    // themselves.
    Assert.assertTrue(successes <= 1);
  }
/**
   * Test for KUDU-2200: if a cluster is running multiple masters, but
   * the user only specifies one of them in the connection string,
   * the resulting exception should clarify their error rather than
   * saying that no leader was found.
   */
Test for KUDU-2200: if a cluster is running multiple masters, but
the user only specifies one of them in the connection string,
the resulting exception should clarify their error rather than
saying that no leader was found.
Test for KUDU - 2200 : if a cluster is running multiple masters but the user only specifies one of them in the connection string the resulting exception should clarify their error rather than saying that no leader was found .
@Test(timeout=60000)
  public void testConnectToOneOfManyMasters() throws Exception {
    MiniKuduCluster cluster = new MiniKuduCluster.MiniKuduClusterBuilder()
        .numMasters(3)
        .numTservers(0)
        .build();
    int successes = 0;
    try {
      String[] masterAddrs = cluster.getMasterAddresses().split(",", -1);
      assertEquals(3, masterAddrs.length);
      for (String masterAddr : masterAddrs) {
        KuduClient c = null;
        try {
          c = new KuduClient.KuduClientBuilder(masterAddr).build();
          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"));
        } finally {
          if (c != null) {
            c.close();
          }
        }
      }
    } finally {
      cluster.shutdown();
    }
    Assert.assertTrue(successes <= 1);
  }
@ Test ( timeout = 60000 ) public void testConnectToOneOfManyMasters ( ) throws Exception { MiniKuduCluster cluster = new MiniKuduCluster . MiniKuduClusterBuilder ( ) . numMasters ( 3 ) . numTservers ( 0 ) . build ( ) ; int successes = 0 ; try { String [ ] masterAddrs = cluster . getMasterAddresses ( ) . split ( "," , - 1 ) ; assertEquals ( 3 , masterAddrs . length ) ; for ( String masterAddr : masterAddrs ) { KuduClient c = null ; try { c = new KuduClient . KuduClientBuilder ( masterAddr ) . build ( ) ; 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" ) ) ; } finally { if ( c != null ) { c . close ( ) ; } } } } finally { cluster . shutdown ( ) ; } Assert . assertTrue ( successes <= 1 ) ; }
Test for KUDU-2200: if a cluster is running multiple masters, but
 the user only specifies one of them in the connection string,
 the resulting exception should clarify their error rather than
 saying that no leader was found.
Test for KUDU - 2200 : if a cluster is running multiple masters but the user only specifies one of them in the connection string the resulting exception should clarify their error rather than saying that no leader was found .
// Call some method which uses the master. This forces us to connect. // Typically, one of the connections will have succeeded. However, it's possible // that 0 succeeded in the case that the masters were slow at electing // themselves.