Source:
<code>public void testCloseAbort() throws Exception { byte[] cf1 = Bytes.toBytes("CF1"); byte[][] families = { cf1 }; Configuration conf = new Configuration(CONF); conf.setBoolean(HRegion.CLOSE_WAIT_ABORT, true); conf.setInt(HRegion.CLOSE_WAIT_TIME, 5*1000); region = initHRegion(tableName, method, conf, families); RegionServerServices rsServices = mock(RegionServerServices.class); region.rsServices = rsServices; final CountDownLatch latch = new CountDownLatch(1); Thread holder = new Thread(new Runnable() { @Override public void run() { try { LOG.info("Starting region operation holder"); region.startRegionOperation(Operation.SCAN); latch.countDown(); int timeRemaining = 10 * 1000; while (timeRemaining > 0) { long start = EnvironmentEdgeManager.currentTime(); try { Thread.sleep(timeRemaining); } catch (InterruptedException e) { LOG.info("Interrupted"); } long end = EnvironmentEdgeManager.currentTime(); timeRemaining -= end - start; LOG.info("Sleeping again, remaining time " + timeRemaining + " ms"); <START> } <END> } catch (Exception e) { throw new RuntimeException(e); } finally { try { region.closeRegionOperation(); } catch (IOException e) { } LOG.info("Stopped region operation holder"); } } }); holder.start(); latch.await(); try { region.close(); } catch (IOException e) { LOG.info("Caught expected exception", e); } holder.join(); region = null; verify(rsServices, atLeast(1)).abort(anyString(),any()); }</code><technical_language>nit: if usage is find diff b/ end start, System.currentTimeMillis() preferred option</technical_language>

Target:
public void testCloseAbort() throws Exception { byte[] cf1 = Bytes.toBytes("CF1"); byte[][] families = { cf1 }; final int SLEEP_TIME = 10 * 1000; Configuration conf = new Configuration(CONF); conf.setBoolean(HRegion.CLOSE_WAIT_ABORT, true); conf.setInt(HRegion.CLOSE_WAIT_TIME, SLEEP_TIME / 2); conf.setInt(HRegion.CLOSE_WAIT_INTERVAL, SLEEP_TIME / 4); region = initHRegion(tableName, method, conf, families); RegionServerServices rsServices = mock(RegionServerServices.class); when(rsServices.getServerName()).thenReturn(ServerName.valueOf("localhost", 1000, 1000)); region.rsServices = rsServices; final CountDownLatch latch = new CountDownLatch(1); Thread holder = new Thread(new Runnable() { @Override public void run() { try { LOG.info("Starting region operation holder"); region.startRegionOperation(Operation.SCAN); latch.countDown(); int timeRemaining = SLEEP_TIME; while (timeRemaining > 0) { long start = EnvironmentEdgeManager.currentTime(); try { Thread.sleep(timeRemaining); } catch (InterruptedException e) { LOG.info("Interrupted"); } long end = EnvironmentEdgeManager.currentTime(); timeRemaining -= end - start; if (timeRemaining < 0) { timeRemaining = 0; } if (timeRemaining > 0) { LOG.info("Sleeping again, remaining time " + timeRemaining + " ms"); } } } catch (Exception e) { throw new RuntimeException(e); } finally { try { region.closeRegionOperation(); } catch (IOException e) { } LOG.info("Stopped region operation holder"); } } }); holder.start(); latch.await(); try { region.close(); } catch (IOException e) { LOG.info("Caught expected exception", e); } region = null; holder.join(); verify(rsServices, atLeast(1)).abort(anyString(),any()); }