File idxDir=getIdxDir();
DefaultZoieVersionFactory defaultZoieVersionFactory = new DefaultZoieVersionFactory();
final ZoieSystem<IndexReader,String,DefaultZoieVersion> idxSystem=createZoie(idxDir,true,defaultZoieVersionFactory);
idxSystem.start();
DirectoryManager dirMgr = new DefaultDirectoryManager(idxDir,defaultZoieVersionFactory);
String query="zoie";
QueryParser parser=new QueryParser(Version.LUCENE_CURRENT,"contents",idxSystem.getAnalyzer());
Query q=null;
try
{
q=parser.parse(query);
}
catch (ParseException e)
{
throw new ZoieException(e.getMessage(),e);
}
try
{
List<DataEvent<String,DefaultZoieVersion>> list;
DefaultZoieVersion zvt = null;
list=new ArrayList<DataEvent<String,DefaultZoieVersion>>(TestData.testdata.length);
for (int i=0;i<TestData.testdata.length;++i)
{
zvt = new DefaultZoieVersion();
zvt.setVersionId(i);
list.add(new DataEvent<String,DefaultZoieVersion>(TestData.testdata[i],zvt));
}
idxSystem.consume(list);
idxSystem.flushEvents(100000);
DefaultZoieVersion versionExported = new DefaultZoieVersion();
versionExported.setVersionId(zvt.getVersionId());
assertEquals("index version mismatch after first flush", TestData.testdata.length - 1, zvt.getVersionId());
int hits = countHits(idxSystem, q);
RandomAccessFile exportFile;
FileChannel channel;
exportFile = new RandomAccessFile(new File(getTmpDir(), "zoie_export.dat"), "rw");
channel = exportFile.getChannel();
idxSystem.exportSnapshot(channel);
channel.close();
exportFile.close();
exportFile = null;
channel = null;
list=new ArrayList<DataEvent<String,DefaultZoieVersion>>(TestData.testdata2.length);
for (int i=0; i < TestData.testdata2.length; ++i)
{
zvt = new DefaultZoieVersion();
zvt.setVersionId(TestData.testdata.length+i);
list.add(new DataEvent<String, DefaultZoieVersion>(TestData.testdata.length + TestData.testdata2[i],zvt));
}
idxSystem.consume(list);
idxSystem.flushEvents(100000);
zvt = (DefaultZoieVersion)dirMgr.getVersion();
assertEquals("index version mismatch after second flush", TestData.testdata.length + TestData.testdata2.length - 1, zvt.getVersionId());
assertEquals("should have no hits", 0, countHits(idxSystem, q));
exportFile = new RandomAccessFile(new File(getTmpDir(), "zoie_export.dat"), "r");
channel = exportFile.getChannel();
idxSystem.importSnapshot(channel);
idxSystem.flushEvents(10000);
channel.close();
exportFile.close();
assertEquals("count is wrong", hits, countHits(idxSystem, q));
zvt = (DefaultZoieVersion)dirMgr.getVersion();
assertEquals("imported version is wrong", versionExported.getVersionId(), zvt.getVersionId()); }
catch(ZoieException e)
{
throw e;