@Test
  public void testRetryBehaviour() throws Exception {
    startHiveServer2WithConf(hiveConf);
    // Get the port number HS2 thrift port is started on
    int thriftPort = hiveConf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT);
    // Check if giving invalid address causes retry in connection attempt
    hiveConf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT, 17000);
    try {
      RetryingThriftCLIServiceClientTest.newRetryingCLIServiceClient(hiveConf);
      fail("Expected to throw exception for invalid port");
    } catch (HiveSQLException sqlExc) {
      assertTrue(sqlExc.getCause() instanceof TTransportException);
      assertTrue(sqlExc.getMessage().contains("3"));
    }
    // Reset port setting
    hiveConf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT, thriftPort);

    hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST, IPStackUtils.transformToIPv6("10.17.207.11"));
    try {
      RetryingThriftCLIServiceClientTest.newRetryingCLIServiceClient(hiveConf);
      fail("Expected to throw exception for invalid host");
    } catch (HiveSQLException sqlExc) {
      assertTrue(sqlExc.getCause() instanceof TTransportException);
      assertTrue(sqlExc.getMessage().contains("3"));
    }
    // Reset host setting
    hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST, IPStackUtils.resolveLoopbackAddress());

    // Create client
    RetryingThriftCLIServiceClient.CLIServiceClientWrapper cliServiceClient
      = RetryingThriftCLIServiceClientTest.newRetryingCLIServiceClient(hiveConf);
    System.out.println("## Created client");

    stopHiveServer2();
    Thread.sleep(5000);

    // submit few queries
    try {
      RetryingThriftCLIServiceClientTest.handlerInst.callCount = 0;
      RetryingThriftCLIServiceClientTest.handlerInst.connectCount = 0;
      cliServiceClient.openSession("anonymous", "anonymous");
    } catch (HiveSQLException exc) {
      exc.printStackTrace();
      if(exc.getCause() instanceof TException){
        assertEquals(1, RetryingThriftCLIServiceClientTest.handlerInst.callCount);
        assertEquals(3, RetryingThriftCLIServiceClientTest.handlerInst.connectCount);
      }
    } finally {
      cliServiceClient.closeTransport();
    }
  }
Test CLI service with a retrying client. All tests should pass. This is to validate that calls
are transferred successfully.
service/src/test/org/apache/hive/service/cli/TestRetryingThriftCLIServiceClient.java