Directory newIndexDir = FSDirectory.open( newIndex );
DefaultIndexUpdater.unpackIndexArchive( new ByteArrayInputStream( os.toByteArray() ), newIndexDir, context );
IndexingContext newContext =
nexusIndexer.addIndexingContext( "test-new", "test", null, newIndexDir, null, null, DEFAULT_CREATORS );
assertEquals( context.getTimestamp().getTime(), newContext.getTimestamp().getTime() );
assertEquals( context.getTimestamp(), newContext.getTimestamp() );
// make sure context has the same artifacts
Query query = nexusIndexer.constructQuery( MAVEN.GROUP_ID, "qdox", SearchType.SCORED );
FlatSearchRequest request = new FlatSearchRequest( query, newContext );
FlatSearchResponse response = nexusIndexer.searchFlat( request );
Collection<ArtifactInfo> r = response.getResults();
assertEquals( 2, r.size() );
List<ArtifactInfo> list = new ArrayList<ArtifactInfo>( r );
assertEquals( 2, list.size() );
ArtifactInfo ai = list.get( 0 );
assertEquals( "1.6.1", ai.version );
ai = list.get( 1 );
assertEquals( "1.5", ai.version );
assertEquals( "test", ai.repository );
Date timestamp = newContext.getTimestamp();
newContext.close( false );
newIndexDir = FSDirectory.open( newIndex );
DefaultIndexUpdater.unpackIndexArchive( new ByteArrayInputStream( os.toByteArray() ), newIndexDir, context );
newContext =
nexusIndexer.addIndexingContext( "test-new", "test", null, newIndexDir, null, null, DEFAULT_CREATORS );
assertEquals( timestamp, newContext.getTimestamp() );
newContext.close( true );
assertFalse( new File( newIndex, "timestamp" ).exists() );
}