Source:
<code>public void testMasterShutdownBeforeStartingAnyRegionServer() throws Exception { LocalHBaseCluster hbaseCluster = null; try { htu = new HBaseTestingUtility( createMasterShutdownBeforeStartingAnyRegionServerConfiguration()); final StartMiniClusterOption options = StartMiniClusterOption.builder() .numDataNodes(1) .numMasters(1) .numRegionServers(0) .masterClass(HMaster.class) .rsClass(MiniHBaseCluster.MiniHBaseClusterRegionServer.class) .createRootDir(true) .build(); htu.startMiniDFSCluster(options.getNumDataNodes()); htu.startMiniZKCluster(options.getNumZkServers()); htu.createRootDir(); hbaseCluster = new LocalHBaseCluster(htu.getConfiguration(), options.getNumMasters(), options.getNumRegionServers(), options.getMasterClass(), options.getRsClass()); final MasterThread masterThread = hbaseCluster.getMasters().get(0); masterThread.start(); final CompletableFuture<Void> shutdownFuture = CompletableFuture.runAsync(() -> { final long timeout = TimeUnit.MINUTES.toMillis(10); assertNotEquals("timeout waiting for server manager to become available.", -1, htu.waitFor(timeout, () -> masterThread.getMaster().getServerManager() != null)); LOG.debug("Attempting to establish connection."); <START> try (final Connection conn = htu.getConnection()) { <END> conn.getAdmin().shutdown(); LOG.info("Shutdown RPC sent."); } catch (IOException | CompletionException e) { LOG.warn("Failed to establish connection.", e); } catch (Throwable e) { LOG.warn("Something unexpected happened.", e); } }); shutdownFuture.join(); masterThread.join(); } finally { if (hbaseCluster != null) { hbaseCluster.shutdown(); } if (htu != null) { htu.shutdownMiniCluster(); htu = null; } } }</code><technical_language>htu.getConnection() is managed mini cluster, remove try-with-resources block? run weird issues in teardown.</technical_language>

Target:
public void testMasterShutdownBeforeStartingAnyRegionServer() throws Exception { LocalHBaseCluster hbaseCluster = null; try { htu = new HBaseTestingUtility( createMasterShutdownBeforeStartingAnyRegionServerConfiguration()); final StartMiniClusterOption options = StartMiniClusterOption.builder() .numDataNodes(1) .numMasters(1) .numRegionServers(0) .masterClass(HMaster.class) .rsClass(MiniHBaseCluster.MiniHBaseClusterRegionServer.class) .createRootDir(true) .build(); htu.startMiniDFSCluster(options.getNumDataNodes()); htu.startMiniZKCluster(options.getNumZkServers()); htu.createRootDir(); hbaseCluster = new LocalHBaseCluster(htu.getConfiguration(), options.getNumMasters(), options.getNumRegionServers(), options.getMasterClass(), options.getRsClass()); final MasterThread masterThread = hbaseCluster.getMasters().get(0); masterThread.start(); final CompletableFuture<Void> shutdownFuture = CompletableFuture.runAsync(() -> { final long timeout = TimeUnit.MINUTES.toMillis(10); assertNotEquals("timeout waiting for server manager to become available.", -1, htu.waitFor(timeout, () -> masterThread.getMaster().getServerManager() != null)); LOG.debug("Attempting to establish connection."); try { htu.getConnection().getAdmin().shutdown(); LOG.info("Shutdown RPC sent."); } catch (IOException | CompletionException e) { LOG.warn("Failed to establish connection.", e); } catch (Throwable e) { LOG.warn("Something unexpected happened.", e); throw new RuntimeException(e); } }); shutdownFuture.join(); masterThread.join(); } finally { if (hbaseCluster != null) { hbaseCluster.shutdown(); } if (htu != null) { htu.shutdownMiniCluster(); htu = null; } } }