List of usage examples for org.apache.commons.lang.mutable MutableBoolean wait
public final void wait() throws InterruptedException
From source file:org.apache.hadoop.hbase.regionserver.TestSplitWalDataLoss.java
@Test public void test() throws IOException, InterruptedException { final HRegionServer rs = testUtil.getRSForFirstRegionInTable(tableName); final HRegion region = (HRegion) rs.getOnlineRegions(tableName).get(0); HRegion spiedRegion = spy(region);// w ww .j a v a2 s . c o m final MutableBoolean flushed = new MutableBoolean(false); final MutableBoolean reported = new MutableBoolean(false); doAnswer(new Answer<FlushResult>() { @Override public FlushResult answer(InvocationOnMock invocation) throws Throwable { synchronized (flushed) { flushed.setValue(true); flushed.notifyAll(); } synchronized (reported) { while (!reported.booleanValue()) { reported.wait(); } } rs.getWAL(region.getRegionInfo()).abortCacheFlush(region.getRegionInfo().getEncodedNameAsBytes()); throw new DroppedSnapshotException("testcase"); } }).when(spiedRegion).internalFlushCacheAndCommit(Matchers.<WAL>any(), Matchers.<MonitoredTask>any(), Matchers.<PrepareFlushResult>any(), Matchers.<Collection<Store>>any()); rs.onlineRegions.put(rs.onlineRegions.keySet().iterator().next(), spiedRegion); Connection conn = testUtil.getConnection(); try (Table table = conn.getTable(tableName)) { table.put(new Put(Bytes.toBytes("row0")).addColumn(family, qualifier, Bytes.toBytes("val0"))); } long oldestSeqIdOfStore = region.getOldestSeqIdOfStore(family); Log.info("CHANGE OLDEST " + oldestSeqIdOfStore); assertTrue(oldestSeqIdOfStore > HConstants.NO_SEQNUM); rs.cacheFlusher.requestFlush(spiedRegion, false); synchronized (flushed) { while (!flushed.booleanValue()) { flushed.wait(); } } try (Table table = conn.getTable(tableName)) { table.put(new Put(Bytes.toBytes("row1")).addColumn(family, qualifier, Bytes.toBytes("val1"))); } long now = EnvironmentEdgeManager.currentTime(); rs.tryRegionServerReport(now - 500, now); synchronized (reported) { reported.setValue(true); reported.notifyAll(); } while (testUtil.getRSForFirstRegionInTable(tableName) == rs) { Thread.sleep(100); } try (Table table = conn.getTable(tableName)) { Result result = table.get(new Get(Bytes.toBytes("row0"))); assertArrayEquals(Bytes.toBytes("val0"), result.getValue(family, qualifier)); } }