### Question:
DirectoryReferenceCounter extends Directory { public DirectoryReferenceCounter(Directory directory, DirectoryReferenceFileGC gc) { this.directory = directory; this.gc = gc; } DirectoryReferenceCounter(Directory directory, DirectoryReferenceFileGC gc); void deleteFile(String name); IndexOutput createOutput(String name); IndexInput openInput(String name); IndexInput openInput(String name, int bufferSize); @SuppressWarnings("deprecation") void touchFile(String name); @SuppressWarnings("deprecation") void sync(String name); void sync(Collection<String> names); void clearLock(String name); void close(); void setLockFactory(LockFactory lockFactory); String getLockID(); void copy(Directory to, String src, String dest); boolean fileExists(String name); @SuppressWarnings("deprecation") long fileModified(String name); long fileLength(String name); LockFactory getLockFactory(); String[] listAll(); Lock makeLock(String name); String toString();  }### Answer:
@Test public void testDirectoryReferenceCounter() throws CorruptIndexException, LockObtainFailedException, IOException, InterruptedException { Directory directory = wrap(new RAMDirectory()); DirectoryReferenceFileGC gc = new DirectoryReferenceFileGC(); gc.init(); DirectoryReferenceCounter counter = new DirectoryReferenceCounter(directory, gc); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_36, new KeywordAnalyzer()); IndexWriter writer = new IndexWriter(counter, conf); int size = 100; IndexReader[] readers = new IndexReader[size]; for (int i = 0; i < size; i++) { writer.addDocument(getDoc()); writer.forceMerge(1); readers[i] = IndexReader.open(writer, true); } for (int i = 0; i < size; i++) { assertEquals(i + 1, readers[i].numDocs()); checkReader(readers[i], i); } String[] listAll = directory.listAll(); for (int i = 0; i < size - 1; i++) { readers[i].close(); } for (int i = 0; i < 1000; i++) { gc.run(); Thread.sleep(1); } IndexReader last = readers[size - 1]; assertEquals(100, last.numDocs()); assertTrue(listAll.length > directory.listAll().length); last.close(); writer.close(); gc.close(); }