Query q=null;
try
{
q=parser.parse(query);
} catch (ParseException e) {
throw new ZoieException(e.getMessage(),e);
}
MemoryStreamDataProvider<String, DefaultZoieVersion> memoryProvider=new MemoryStreamDataProvider<String, DefaultZoieVersion>();
memoryProvider.setMaxEventsPerMinute(Long.MAX_VALUE);
memoryProvider.setDataConsumer(idxSystem);
memoryProvider.start();
try
{
int count=TestData.testdata.length;
List<DataEvent<String,DefaultZoieVersion>> list=new ArrayList<DataEvent<String,DefaultZoieVersion>>(count);
DefaultZoieVersion zvt = null;
for (int i=0;i<count;++i)
{
zvt = new DefaultZoieVersion();
zvt.setVersionId(i);
list.add(new DataEvent<String,DefaultZoieVersion>(TestData.testdata[i], zvt));
}
memoryProvider.addEvents(list);
idxSystem.syncWthVersion(10000, zvt);
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
Searcher searcher=null;
MultiReader reader= null;
List<ZoieIndexReader<IndexReader>> readers = null;
for (int i=0;i<repeat;++i)
{
try
{
readers=idxSystem.getIndexReaders();
reader=new MultiReader(readers.toArray(new IndexReader[readers.size()]),false);
// for(int j=0; j<readers.size(); j++)
// {
// IndexReader ir = readers.get(j);
// Map<String, String> commitData = IndexReader.getCommitUserData(ir.directory()); // = new HashMap<String,String>();
// System.out.println("j:" + j + "ZoieTest: directory: " + ir.directory());
// System.out.println("j:" + j + "ZoieTest: commitData(ZoieVersion): " + commitData);
// }
searcher=new IndexSearcher(reader);
TopDocs hits=searcher.search(q,10);
results[idx++] = hits.totalHits;
}
finally
{
try{
if (searcher != null){
searcher.close();
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();