QueryParser parser = new QueryParser(Version.LUCENE_43, "contents", idxSystem.getAnalyzer());
Query q = null;
try {
q = parser.parse(query);
} catch (Exception e) {
throw new ZoieException(e.getMessage(), e);
}
MemoryStreamDataProvider<String> memoryProvider = new MemoryStreamDataProvider<String>(
ZoieConfig.DEFAULT_VERSION_COMPARATOR);
memoryProvider.setMaxEventsPerMinute(Long.MAX_VALUE);
memoryProvider.setDataConsumer(idxSystem);
memoryProvider.start();
try {
int count = DataForTests.testdata.length;
List<DataEvent<String>> list = new ArrayList<DataEvent<String>>(count);
for (int i = 0; i < count; ++i) {
list.add(new DataEvent<String>(DataForTests.testdata[i], "" + i));
}
memoryProvider.addEvents(list);
idxSystem.syncWithVersion(10000, "" + (count - 1));
int repeat = 20;
int idx = 0;
int[] results = new int[repeat];
int[] expected = new int[repeat];
Arrays.fill(expected, count);
// should be consumed by the idxing system
IndexSearcher searcher = null;
MultiReader reader = null;
List<ZoieMultiReader<IndexReader>> readers = null;
for (int i = 0; i < repeat; ++i) {
try {
readers = idxSystem.getIndexReaders();
reader = new MultiReader(readers.toArray(new IndexReader[readers.size()]), false);
searcher = new IndexSearcher(reader);
TopDocs hits = searcher.search(q, 10);
results[idx++] = hits.totalHits;
} finally {
try {
if (searcher != null) {
searcher = null;
reader.close();
reader = null;
}
} finally {
idxSystem.returnIndexReaders(readers);
}
}
try {
Thread.sleep(30);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
assertEquals("maybe race condition in disk flush", Arrays.toString(expected),
Arrays.toString(results));
} catch (IOException ioe) {
throw new ZoieException(ioe.getMessage());
} finally {
memoryProvider.stop();
idxSystem.shutdown();
deleteDirectory(idxDir);
}