### Question:
DbImpl implements DB { void backgroundCompaction() throws IOException { checkState(mutex.isHeldByCurrentThread()); compactMemTableInternal(); Compaction compaction; if (manualCompaction != null) { compaction = versions.compactRange(manualCompaction.level, new InternalKey(manualCompaction.begin, MAX_SEQUENCE_NUMBER, VALUE), new InternalKey(manualCompaction.end, 0, DELETION) ); } else { compaction = versions.pickCompaction(); } if (compaction == null) { } else if (manualCompaction == null && compaction.isTrivialMove()) { checkState(compaction.getLevelInputs().size() == 1); FileMetaData fileMetaData = compaction.getLevelInputs().get(0); compaction.getEdit().deleteFile(compaction.getLevel(), fileMetaData.getNumber()); compaction.getEdit().addFile(compaction.getLevel() + 1, fileMetaData); versions.logAndApply(compaction.getEdit()); } else { CompactionState compactionState = new CompactionState(compaction); doCompactionWork(compactionState); cleanupCompaction(compactionState); } if (manualCompaction != null) { manualCompaction = null; } } DbImpl(File databaseDir, Options options); @Override void close(); @Override String getProperty(String name); void flushMemTable(); void compactRange(int level, Slice start, Slice end); void checkBackgroundException(); @Override byte[] get(byte[] key); @Override byte[] get(byte[] key, ReadOptions options); @Override void put(byte[] key, byte[] value); @Override Snapshot put(byte[] key, byte[] value, WriteOptions options); @Override void delete(byte[] key); @Override Snapshot delete(byte[] key, WriteOptions options); @Override void write(WriteBatch updates); @Override Snapshot write(WriteBatch updates, WriteOptions options); Snapshot writeInternal(WriteBatchImpl updates, WriteOptions options); @Override WriteBatch createWriteBatch(); @Override SeekingIteratorAdapter iterator(); @Override SeekingIteratorAdapter iterator(ReadOptions options); @Override Snapshot getSnapshot(); void compactMemTable(); @Override long[] getApproximateSizes(Range... ranges); long getApproximateSizes(Range range); long getMaxNextLevelOverlappingBytes(); @Override void suspendCompactions(); @Override void resumeCompactions(); @Override void compactRange(byte[] begin, byte[] end); static final String TAG; }### Answer:
@Test public void testBackgroundCompaction() throws Exception { Options options = new Options(); options.maxOpenFiles(100); options.createIfMissing(true); DbImpl db = new DbImpl(this.databaseDir, options); Random random = new Random(301); for (int i = 0; i < 200000 * STRESS_FACTOR; i++) { db.put( randomString(random, 64).getBytes(), new byte[] { 0x01 }, new WriteOptions().sync(false) ); db.get(randomString(random, 64).getBytes()); if ((i % 50000) == 0 && i != 0) { System.out.println(i + " rows written"); } } }