indexer.addArtifactToIndex( createArtifactContext( repositoryId, "commons-lang", "commons-lang", "2.2", null ),
context );
Query q = indexer.constructQuery( MAVEN.ARTIFACT_ID, "commons-lang", SearchType.SCORED );
FlatSearchResponse response1 = indexer.searchFlat( new FlatSearchRequest( q ) );
Collection<ArtifactInfo> content1 = response1.getResults();
assertEquals( content1.toString(), 1, content1.size() );
// updated index
Directory tempIndexDirectory = new RAMDirectory();
IndexingContext tempContext =
indexer.addIndexingContext( repositoryId + "temp", repositoryId, null, tempIndexDirectory, repositoryUrl,
null, MIN_CREATORS );
indexer.addArtifactToIndex( createArtifactContext( repositoryId, "commons-lang", "commons-lang", "2.3", null ),
tempContext );
indexer.addArtifactToIndex( createArtifactContext( repositoryId, "commons-lang", "commons-lang", "2.4", null ),
tempContext );
FlatSearchResponse response2 = indexer.searchFlat( new FlatSearchRequest( q, tempContext ) );
Collection<ArtifactInfo> tempContent = response2.getResults();
assertEquals( tempContent.toString(), 2, tempContent.size() );
// RAMDirectory is closed with context, forcing timestamp update
tempContext.updateTimestamp( true );
// A change in RAMDirectory and Directory behavior in general: it will copy the Index files ONLY
// So we must make sure that timestamp file is transferred correctly.
RAMDirectory tempDir2 = new RAMDirectory();
IndexUtils.copyDirectory( tempContext.getIndexDirectory(), tempDir2 );
Date newIndexTimestamp = tempContext.getTimestamp();
indexer.removeIndexingContext( tempContext, false );
context.replace( tempDir2 );
assertEquals( newIndexTimestamp, context.getTimestamp() );
FlatSearchResponse response3 = indexer.searchFlat( new FlatSearchRequest( q ) );
Collection<ArtifactInfo> content2 = response3.getResults();
assertEquals( content2.toString(), 2, content2.size() );
}