@Test
  public void testSessionLifeAfterTransportClose() throws Exception {
    try {
      startHiveServer2WithConf(hiveConf);
      CLIService service = null;
      for (Service s : hiveServer2.getServices()) {
        if (s instanceof CLIService) {
          service = (CLIService) s;
        }
      }
      if (service == null) {
        service = new CLIService(hiveServer2, true);
      }
      RetryingThriftCLIServiceClient.CLIServiceClientWrapper client
        = RetryingThriftCLIServiceClientTest.newRetryingCLIServiceClient(hiveConf);
      Map<String, String> conf = new HashMap<>();
      conf.put(HiveConf.ConfVars.HIVE_SERVER2_CLOSE_SESSION_ON_DISCONNECT.varname, "false");
      SessionHandle sessionHandle = client.openSession("anonymous", "anonymous", conf);
      assertNotNull(sessionHandle);
      HiveSession session = service.getSessionManager().getSession(sessionHandle);
      OperationHandle op1 = session.executeStatementAsync("show databases", null);
      assertNotNull(op1);
      client.closeTransport();
      // Verify that session wasn't closed on transport close.
      assertEquals(session, service.getSessionManager().getSession(sessionHandle));
      // Should be able to execute without failure in the session whose transport has been closed.
      OperationHandle op2 = session.executeStatementAsync("show databases", null);
      assertNotNull(op2);
      // Make new client, since transport was closed for the last one.
      client = RetryingThriftCLIServiceClientTest.newRetryingCLIServiceClient(hiveConf);
      client.closeSession(sessionHandle);
      // operations will be lost once owning session is closed.
      for (OperationHandle op: new OperationHandle[]{op1, op2}) {
        try {
          client.getOperationStatus(op, false);
          fail("Should have failed.");
        } catch (HiveSQLException ignored) {

        }
      }
    } finally {
      stopHiveServer2();
    }
  }
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