public virtual void TestDeleteUnusedUpdatesFiles()
{
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.Add(new StringField("id", "d0", Store.NO));
doc.Add(new BinaryDocValuesField("f", ToBytes(1L)));
writer.AddDocument(doc);
// create first gen of update files
writer.UpdateBinaryDocValue(new Term("id", "d0"), "f", ToBytes(2L));
writer.Commit();
int numFiles = dir.ListAll().Length;
DirectoryReader r = DirectoryReader.Open(dir);
BytesRef scratch = new BytesRef();
Assert.AreEqual(2L, GetValue(((AtomicReader)r.Leaves[0].Reader).GetBinaryDocValues("f"), 0, scratch));
r.Dispose();
// create second gen of update files, first gen should be deleted
writer.UpdateBinaryDocValue(new Term("id", "d0"), "f", ToBytes(5L));
writer.Commit();
Assert.AreEqual(numFiles, dir.ListAll().Length);
r = DirectoryReader.Open(dir);
Assert.AreEqual(5L, GetValue(((AtomicReader)r.Leaves[0].Reader).GetBinaryDocValues("f"), 0, scratch));
r.Dispose();
writer.Dispose();
dir.Dispose();
}