TestThreadSafepublic class TestThreadSafe extends TestCase
Fields Summary |
---|
Random | r | Directory | dir1 | Directory | dir2 | IndexReader | ir1 | IndexReader | ir2 | String | failure | String[] | words |
Methods Summary |
---|
void | buildDir(org.apache.lucene.store.Directory dir, int nDocs, int maxFields, int maxFieldLen)
IndexWriter iw = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
iw.setMaxBufferedDocs(10);
for (int j=0; j<nDocs; j++) {
Document d = new Document();
int nFields = r.nextInt(maxFields);
for (int i=0; i<nFields; i++) {
int flen = r.nextInt(maxFieldLen);
StringBuffer sb = new StringBuffer("^ ");
while (sb.length() < flen) sb.append(" " + words[r.nextInt(words.length)]);
sb.append(" $");
Field.Store store = Field.Store.YES; // make random later
Field.Index index = Field.Index.TOKENIZED; // make random later
d.add(new Field("f"+i, sb.toString(), store, index));
}
iw.addDocument(d);
}
iw.close();
| void | doTest(int iter, int nThreads)
Thr[] tarr = new Thr[nThreads];
for (int i=0; i<nThreads; i++) {
tarr[i] = new Thr(iter, new Random(), 1);
tarr[i].start();
}
for (int i=0; i<nThreads; i++) {
tarr[i].join();
}
if (failure!=null) {
TestCase.fail(failure);
}
| public void | testLazyLoadThreadSafety()
dir1 = new RAMDirectory();
// test w/ field sizes bigger than the buffer of an index input
buildDir(dir1, 15, 5, 2000);
// do many small tests so the thread locals go away inbetween
for (int i=0; i<100; i++) {
ir1 = IndexReader.open(dir1);
doTest(10,100);
}
| void | validateField(org.apache.lucene.document.Fieldable f)
String val = f.stringValue();
if (!val.startsWith("^") || !val.endsWith("$")) {
throw new RuntimeException("Invalid field:" + f.toString() + " val=" +val);
}
|
|