@Test public void testEntrySink() throws Exception { Configuration conf = new Configuration(); RecoveryMode mode = (conf.getBoolean(HConstants.DISTRIBUTED_LOG_REPLAY_KEY, false) ? RecoveryMode.LOG_REPLAY : RecoveryMode.LOG_SPLITTING); EntryBuffers sink = new EntryBuffers(new PipelineController(), 1 * 1024 * 1024); for (int i = 0; i < 1000; i++) { WAL.Entry entry = createTestLogEntry(i); sink.appendEntry(entry); } assertTrue(sink.totalBuffered > 0); long amountInChunk = sink.totalBuffered; // Get a chunk RegionEntryBuffer chunk = sink.getChunkToWrite(); assertEquals(chunk.heapSize(), amountInChunk); // Make sure it got marked that a thread is "working on this" assertTrue(sink.isRegionCurrentlyWriting(TEST_REGION)); // Insert some more entries for (int i = 0; i < 500; i++) { WAL.Entry entry = createTestLogEntry(i); sink.appendEntry(entry); } // Asking for another chunk shouldn't work since the first one // is still writing assertNull(sink.getChunkToWrite()); // If we say we're done writing the first chunk, then we should be able // to get the second sink.doneWriting(chunk); RegionEntryBuffer chunk2 = sink.getChunkToWrite(); assertNotNull(chunk2); assertNotSame(chunk, chunk2); long amountInChunk2 = sink.totalBuffered; // The second chunk had fewer rows than the first assertTrue(amountInChunk2 < amountInChunk); sink.doneWriting(chunk2); assertEquals(0, sink.totalBuffered); }