private void RunTest(Random random, Directory dir)
{
// Run for ~1 seconds
long stopTime = Environment.TickCount + 1000;
SnapshotDeletionPolicy dp = DeletionPolicy;
IndexWriter writer = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).SetIndexDeletionPolicy(dp).SetMaxBufferedDocs(2));
// Verify we catch misuse:
try
{
dp.Snapshot();
Assert.Fail("did not hit exception");
}
catch (InvalidOperationException ise)
{
// expected
}
dp = (SnapshotDeletionPolicy)writer.Config.DelPolicy;
writer.Commit();
ThreadClass t = new ThreadAnonymousInnerClassHelper(stopTime, writer, NewField);
t.Start();
// While the above indexing thread is running, take many
// backups:
do
{
BackupIndex(dir, dp);
Thread.Sleep(20);
} while (t.IsAlive);
t.Join();
// Add one more document to force writer to commit a
// final segment, so deletion policy has a chance to
// delete again:
Document doc = new Document();
FieldType customType = new FieldType(TextField.TYPE_STORED);
customType.StoreTermVectors = true;
customType.StoreTermVectorPositions = true;
customType.StoreTermVectorOffsets = true;
doc.Add(NewField("content", "aaa", customType));
writer.AddDocument(doc);
// Make sure we don't have any leftover files in the
// directory:
writer.Dispose();
TestIndexWriter.AssertNoUnreferencedFiles(dir, "some files were not deleted but should have been");
}