@BeforeClass
  public static void setUpBeforeClass() throws Exception {
    kdc = SimpleKdcServerUtil.getRunningSimpleKdcServer(
      new File(TEST_UTIL.getDataTestDir().toString()), HBaseTestingUtil::randomFreePort);
    File keytabDir = Paths.get(TEST_UTIL.getRandomDir().toString()).toAbsolutePath().toFile();
    Assert.assertTrue(keytabDir.mkdirs());

    clientPrincipal = "client@" + kdc.getKdcConfig().getKdcRealm();
    clientKeytab = new File(keytabDir, clientPrincipal + ".keytab");
    kdc.createAndExportPrincipals(clientKeytab, clientPrincipal);

    String hostname = InetAddress.getLoopbackAddress().getHostName();
    serverPrincipal = "hbase/" + hostname + "@" + kdc.getKdcConfig().getKdcRealm();
    serverKeytab = new File(keytabDir, serverPrincipal.replace('/', '_') + ".keytab");

    // Setup separate SPNEGO keytab
    spnegoServerPrincipal = "HTTP/" + hostname + "@" + kdc.getKdcConfig().getKdcRealm();
    spnegoServerKeytab = new File(keytabDir, spnegoServerPrincipal.replace('/', '_') + ".keytab");
    kdc.createAndExportPrincipals(spnegoServerKeytab, spnegoServerPrincipal);
    kdc.createAndExportPrincipals(serverKeytab, serverPrincipal);

    TEST_UTIL.getConfiguration().setBoolean(Constants.USE_HTTP_CONF_KEY, true);
    addSecurityConfigurations(TEST_UTIL.getConfiguration());

    TestThriftHttpServer.setUpBeforeClass();
  }
Start the HBase Thrift HTTP server on a random port through the command-line interface and talk
to it from client side with SPNEGO security enabled.
hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftSpnegoHttpServer.java