improve verbosity of TestNRTThreads

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1050084 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2010-12-16 18:11:29 +00:00
parent ef8e74541a
commit c9a903a4f9
1 changed files with 26 additions and 2 deletions

View File

@ -20,6 +20,7 @@ package org.apache.lucene.index;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
@ -34,6 +35,7 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.Bits;
@ -113,6 +115,9 @@ public class TestNRTThreads extends LuceneTestCase {
final AtomicBoolean failed = new AtomicBoolean();
final AtomicInteger addCount = new AtomicInteger();
final AtomicInteger delCount = new AtomicInteger();
final List<String> delIDs = Collections.synchronizedList(new ArrayList<String>());
final long stopTime = System.currentTimeMillis() + RUN_TIME_SEC*1000;
Thread[] threads = new Thread[NUM_INDEX_THREADS];
for(int thread=0;thread<NUM_INDEX_THREADS;thread++) {
@ -152,7 +157,11 @@ public class TestNRTThreads extends LuceneTestCase {
for(String id : toDeleteIDs) {
writer.deleteDocuments(new Term("id", id));
}
delCount.addAndGet(toDeleteIDs.size());
final int count = delCount.addAndGet(toDeleteIDs.size());
if (VERBOSE) {
System.out.println(Thread.currentThread().getName() + ": tot " + count + " deletes");
}
delIDs.addAll(toDeleteIDs);
toDeleteIDs.clear();
}
addCount.getAndIncrement();
@ -163,6 +172,9 @@ public class TestNRTThreads extends LuceneTestCase {
throw new RuntimeException(exc);
}
}
if (VERBOSE) {
System.out.println(Thread.currentThread().getName() + ": indexing done");
}
}
};
threads[thread].setDaemon(true);
@ -315,8 +327,20 @@ public class TestNRTThreads extends LuceneTestCase {
if (VERBOSE) {
System.out.println("TEST: done join [" + (System.currentTimeMillis()-t0) + " ms]; addCount=" + addCount + " delCount=" + delCount);
}
final IndexReader r2 = writer.getReader();
final IndexSearcher s = new IndexSearcher(r2);
for(String id : delIDs) {
final TopDocs hits = s.search(new TermQuery(new Term("id", id)), 1);
if (hits.totalHits != 0) {
fail("doc id=" + id + " is supposed to be deleted, but got docID=" + hits.scoreDocs[0].doc);
}
}
assertEquals("index=" + writer.segString() + " addCount=" + addCount + " delCount=" + delCount, addCount.get() - delCount.get(), r2.numDocs());
r2.close();
writer.commit();
assertEquals("index=" + writer.segString(), addCount.get() - delCount.get(), writer.numDocs());
assertEquals("index=" + writer.segString() + " addCount=" + addCount + " delCount=" + delCount, addCount.get() - delCount.get(), writer.numDocs());
writer.close(false);
dir.close();