Buggy code:
public class TestFlushByRamOrCountsPolicy extends LuceneTestCase { private static LineFileDocs lineDocFile ; @ BeforeClass public static void beforeClass ( ) throws Exception { } @ AfterClass public static void afterClass ( ) throws Exception { } public void testFlushByRam ( ) throws IOException , InterruptedException { } public void testFlushByRamLargeBuffer ( ) throws IOException , InterruptedException { } protected void runFlushByRam ( int numThreads , double maxRamMB , boolean ensureNotStalled ) throws IOException , InterruptedException { } public void testFlushDocCount ( ) throws IOException , InterruptedException { } public void testRandom ( ) throws IOException , InterruptedException { } public void testStallControl ( ) throws IOException , InterruptedException { int [ ] numThreads = new int [ ] { 4 + ( random ( ) . nextInt ( 8 ) ) , 1 } ; final int numDocumentsToIndex = 50 + ( random ( ) . nextInt ( 50 ) ) ; for ( int i = 0 ; i < ( numThreads . length ) ; i ++ ) { AtomicInteger numDocs = new AtomicInteger ( numDocumentsToIndex ) ; <START_BUG> MockDirectoryWrapper dir = newDirectory ( ) ; <END_BUG> dir . setThrottling ( SOMETIMES ) ; IndexWriterConfig iwc = newIndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ( ) ) ) ; iwc . setMaxBufferedDocs ( DISABLE_AUTO_FLUSH ) ; iwc . setMaxBufferedDeleteTerms ( DISABLE_AUTO_FLUSH ) ; FlushPolicy flushPolicy = new FlushByRamOrCountsPolicy ( ) ; iwc . setFlushPolicy ( flushPolicy ) ; DocumentsWriterPerThreadPool threadPool = new ThreadAffinityDocumentsWriterThreadPool ( ( ( numThreads [ i ] ) == 1 ? 1 : 2 ) ) ; iwc . setIndexerThreadPool ( threadPool ) ; iwc . setRAMBufferSizeMB ( 0.25 ) ; IndexWriter writer = new IndexWriter ( dir , iwc ) ; TestFlushByRamOrCountsPolicy . IndexThread [ ] threads = new TestFlushByRamOrCountsPolicy . IndexThread [ numThreads [ i ] ] ; for ( int x = 0 ; x < ( threads . length ) ; x ++ ) { threads [ x ] = new TestFlushByRamOrCountsPolicy . IndexThread ( numDocs , numThreads [ i ] , writer , TestFlushByRamOrCountsPolicy . lineDocFile , false ) ; threads [ x ] . start ( ) ; } for ( int x = 0 ; x < ( threads . length ) ; x ++ ) { threads [ x ] . join ( ) ; } DocumentsWriter docsWriter = writer . getDocsWriter ( ) ; assertNotNull ( docsWriter ) ; DocumentsWriterFlushControl flushControl = docsWriter . flushControl ; assertEquals ( "<seq2seq4repair_space>all<seq2seq4repair_space>flushes<seq2seq4repair_space>must<seq2seq4repair_space>be<seq2seq4repair_space>due" , 0 , flushControl . flushBytes ( ) ) ; assertEquals ( numDocumentsToIndex , writer . numDocs ( ) ) ; assertEquals ( numDocumentsToIndex , writer . maxDoc ( ) ) ; if ( ( numThreads [ i ] ) == 1 ) { assertFalse ( ( "single<seq2seq4repair_space>thread<seq2seq4repair_space>must<seq2seq4repair_space>not<seq2seq4repair_space>block<seq2seq4repair_space>numThreads:<seq2seq4repair_space>" + ( numThreads [ i ] ) ) , docsWriter . flushControl . stallControl . hasBlocked ( ) ) ; } if ( ( docsWriter . flushControl . peakNetBytes ) > ( ( ( 2.0 * ( iwc . getRAMBufferSizeMB ( ) ) ) * 1024.0 ) * 1024.0 ) ) { assertTrue ( docsWriter . flushControl . stallControl . wasStalled ( ) ) ; } assertActiveBytesAfter ( flushControl ) ; writer . close ( true ) ; dir . close ( ) ; } } protected void assertActiveBytesAfter ( DocumentsWriterFlushControl flushControl ) { } public class IndexThread extends Thread { IndexWriter writer ; LiveIndexWriterConfig iwc ; LineFileDocs docs ; private AtomicInteger pendingDocs ; private final boolean doRandomCommit ; public IndexThread ( AtomicInteger pendingDocs , int numThreads , IndexWriter writer , LineFileDocs docs , boolean doRandomCommit ) { } public void run ( ) { } } private static class MockDefaultFlushPolicy extends FlushByRamOrCountsPolicy { long peakBytesWithoutFlush = Integer . MIN_VALUE ; long peakDocCountWithoutFlush = Integer . MIN_VALUE ; boolean hasMarkedPending = false ; @ Override public void onDelete ( DocumentsWriterFlushControl control , ThreadState state ) { } @ Override public void onInsert ( DocumentsWriterFlushControl control , ThreadState state ) { } } static void findPending ( DocumentsWriterFlushControl flushControl , ArrayList < ThreadState > pending , ArrayList < ThreadState > notPending ) { } }

Fix:
MockDirectoryWrapper dir = newMockDirectory ( ) ;