java/kudu-client/src/test/java/org/apache/kudu/client/TestConnectToCluster.java
@Test(timeout = 10000)
  public void testAggregateResponses() throws Exception {
    NonRecoverableException reusableNRE = new NonRecoverableException(
        Status.RuntimeError(""));
    RecoverableException reusableRE = new RecoverableException(
        Status.RuntimeError(""));
    NoLeaderFoundException retryResponse =
        new NoLeaderFoundException(Status.RuntimeError(""));
    // We don't test for a particular good response, so as long as we pass something that's not an
    // exception to runTest() we're good.
    Object successResponse = new Object();

    // Success cases.

    // Normal case.
    runTest(
        makeCTMR(LEADER),
        makeCTMR(FOLLOWER),
        makeCTMR(FOLLOWER),
        successResponse);

    // Permutation works too.
    runTest(
        makeCTMR(FOLLOWER),
        makeCTMR(LEADER),
        makeCTMR(FOLLOWER),
        successResponse);

    // Multiple leaders, that's fine since it might be a TOCTOU situation, or one master
    // is confused. Raft handles this if the client then tries to do something that requires a
    // replication on the master-side.
    runTest(
        makeCTMR(LEADER),
        makeCTMR(LEADER),
        makeCTMR(FOLLOWER),
        successResponse);

    // Mixed bag, still works because there's a leader.
    runTest(
        reusableNRE,
        makeCTMR(FOLLOWER),
        makeCTMR(LEADER),
        successResponse);

    // All unreachable except one leader, still good.
    runTest(
        reusableNRE,
        reusableNRE,
        makeCTMR(LEADER),
        successResponse);

    // Permutation of the previous.
    runTest(
        reusableNRE,
        makeCTMR(LEADER),
        reusableNRE,
        successResponse);

    // Retry cases.

    // Just followers means we retry.
    runTest(
        makeCTMR(FOLLOWER),
        makeCTMR(FOLLOWER),
        makeCTMR(FOLLOWER),
        retryResponse);

    // One NRE but we have responsive masters, retry.
    runTest(
        makeCTMR(FOLLOWER),
        makeCTMR(FOLLOWER),
        reusableNRE,
        retryResponse);

    // One good master but no leader, retry.
    runTest(
        reusableNRE,
        makeCTMR(FOLLOWER),
        reusableNRE,
        retryResponse);

    // Different case but same outcome.
    runTest(
        reusableRE,
        reusableNRE,
        makeCTMR(FOLLOWER),
        retryResponse);

    // All recoverable means retry.
    runTest(
        reusableRE,
        reusableRE,
        reusableRE,
        retryResponse);

    // Just one recoverable still means retry.
    runTest(
        reusableRE,
        reusableNRE,
        reusableNRE,
        retryResponse);

    // Failure case.

    // Can't recover anything, give up.
    runTest(
        reusableNRE,
        reusableNRE,
        reusableNRE,
        reusableNRE);
  }
/**
   * Unit test which checks that the ConnectToCluster aggregates the
   * responses from the different masters properly and returns the
   * response from the located leader.
   */
Unit test which checks that the ConnectToCluster aggregates the
responses from the different masters properly and returns the
response from the located leader.
Unit test which checks that the ConnectToCluster aggregates the responses from the different masters properly and returns the response from the located leader .
@Test(timeout = 10000)
  public void testAggregateResponses() throws Exception {
    NonRecoverableException reusableNRE = new NonRecoverableException(
        Status.RuntimeError(""));
    RecoverableException reusableRE = new RecoverableException(
        Status.RuntimeError(""));
    NoLeaderFoundException retryResponse =
        new NoLeaderFoundException(Status.RuntimeError(""));
    Object successResponse = new Object();
    runTest(
        makeCTMR(LEADER),
        makeCTMR(FOLLOWER),
        makeCTMR(FOLLOWER),
        successResponse);
    runTest(
        makeCTMR(FOLLOWER),
        makeCTMR(LEADER),
        makeCTMR(FOLLOWER),
        successResponse);
    runTest(
        makeCTMR(LEADER),
        makeCTMR(LEADER),
        makeCTMR(FOLLOWER),
        successResponse);
    runTest(
        reusableNRE,
        makeCTMR(FOLLOWER),
        makeCTMR(LEADER),
        successResponse);
    runTest(
        reusableNRE,
        reusableNRE,
        makeCTMR(LEADER),
        successResponse);
    runTest(
        reusableNRE,
        makeCTMR(LEADER),
        reusableNRE,
        successResponse);
    runTest(
        makeCTMR(FOLLOWER),
        makeCTMR(FOLLOWER),
        makeCTMR(FOLLOWER),
        retryResponse);
    runTest(
        makeCTMR(FOLLOWER),
        makeCTMR(FOLLOWER),
        reusableNRE,
        retryResponse);
    runTest(
        reusableNRE,
        makeCTMR(FOLLOWER),
        reusableNRE,
        retryResponse);
    runTest(
        reusableRE,
        reusableNRE,
        makeCTMR(FOLLOWER),
        retryResponse);
    runTest(
        reusableRE,
        reusableRE,
        reusableRE,
        retryResponse);
    runTest(
        reusableRE,
        reusableNRE,
        reusableNRE,
        retryResponse);
    runTest(
        reusableNRE,
        reusableNRE,
        reusableNRE,
        reusableNRE);
  }
@ Test ( timeout = 10000 ) public void testAggregateResponses ( ) throws Exception { NonRecoverableException reusableNRE = new NonRecoverableException ( Status . RuntimeError ( "" ) ) ; RecoverableException reusableRE = new RecoverableException ( Status . RuntimeError ( "" ) ) ; NoLeaderFoundException retryResponse = new NoLeaderFoundException ( Status . RuntimeError ( "" ) ) ; Object successResponse = new Object ( ) ; runTest ( makeCTMR ( LEADER ) , makeCTMR ( FOLLOWER ) , makeCTMR ( FOLLOWER ) , successResponse ) ; runTest ( makeCTMR ( FOLLOWER ) , makeCTMR ( LEADER ) , makeCTMR ( FOLLOWER ) , successResponse ) ; runTest ( makeCTMR ( LEADER ) , makeCTMR ( LEADER ) , makeCTMR ( FOLLOWER ) , successResponse ) ; runTest ( reusableNRE , makeCTMR ( FOLLOWER ) , makeCTMR ( LEADER ) , successResponse ) ; runTest ( reusableNRE , reusableNRE , makeCTMR ( LEADER ) , successResponse ) ; runTest ( reusableNRE , makeCTMR ( LEADER ) , reusableNRE , successResponse ) ; runTest ( makeCTMR ( FOLLOWER ) , makeCTMR ( FOLLOWER ) , makeCTMR ( FOLLOWER ) , retryResponse ) ; runTest ( makeCTMR ( FOLLOWER ) , makeCTMR ( FOLLOWER ) , reusableNRE , retryResponse ) ; runTest ( reusableNRE , makeCTMR ( FOLLOWER ) , reusableNRE , retryResponse ) ; runTest ( reusableRE , reusableNRE , makeCTMR ( FOLLOWER ) , retryResponse ) ; runTest ( reusableRE , reusableRE , reusableRE , retryResponse ) ; runTest ( reusableRE , reusableNRE , reusableNRE , retryResponse ) ; runTest ( reusableNRE , reusableNRE , reusableNRE , reusableNRE ) ; }
Unit test which checks that the ConnectToCluster aggregates the
 responses from the different masters properly and returns the
 response from the located leader.
Unit test which checks that the ConnectToCluster aggregates the responses from the different masters properly and returns the response from the located leader .
// We don't test for a particular good response, so as long as we pass something that's not an // exception to runTest() we're good. // Success cases. // Normal case. // Permutation works too. // Multiple leaders, that's fine since it might be a TOCTOU situation, or one master // is confused. Raft handles this if the client then tries to do something that requires a // replication on the master-side. // Mixed bag, still works because there's a leader. // All unreachable except one leader, still good. // Permutation of the previous. // Retry cases. // Just followers means we retry. // One NRE but we have responsive masters, retry. // One good master but no leader, retry. // Different case but same outcome. // All recoverable means retry. // Just one recoverable still means retry. // Failure case. // Can't recover anything, give up.