take of already existing context to prevent lucene locks

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1140038 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-06-27 07:53:59 +00:00
parent 8233856ae4
commit 7f9e6e70e9
1 changed files with 18 additions and 14 deletions

View File

@ -80,8 +80,6 @@ public class ArchivaIndexingTaskExecutorTest
private IndexingContext context; private IndexingContext context;
private NexusIndexer nexusIndexer;
@Inject @Inject
PlexusSisuBridge plexusSisuBridge; PlexusSisuBridge plexusSisuBridge;
@ -114,9 +112,7 @@ public class ArchivaIndexingTaskExecutorTest
indexingExecutor.setIndexerEngine( indexerEngine ); indexingExecutor.setIndexerEngine( indexerEngine );
indexingExecutor.setIndexPacker( indexPacker ); indexingExecutor.setIndexPacker( indexPacker );
nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); context = ArtifactIndexingTask.createContext( repositoryConfig, indexer );
context = ArtifactIndexingTask.createContext( repositoryConfig, nexusIndexer );
} }
@ -125,8 +121,13 @@ public class ArchivaIndexingTaskExecutorTest
public void tearDown() public void tearDown()
throws Exception throws Exception
{ {
context.close( true ); //context.close( true );
indexer.removeIndexingContext( context, true ); //indexer.removeIndexingContext( context, true );
for (IndexingContext indexingContext : indexer.getIndexingContexts().values())
{
indexer.removeIndexingContext( indexingContext, true );
}
// delete created index in the repository // delete created index in the repository
File indexDir = new File( repositoryConfig.getLocation(), ".indexer" ); File indexDir = new File( repositoryConfig.getLocation(), ".indexer" );
@ -159,11 +160,15 @@ public class ArchivaIndexingTaskExecutorTest
indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ), indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
Occur.SHOULD ); Occur.SHOULD );
if (!indexer.getIndexingContexts().containsKey( repositoryConfig.getId() ))
{
IndexingContext context = indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), IndexingContext context = indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
new File( repositoryConfig.getLocation() ), new File( repositoryConfig.getLocation() ),
new File( repositoryConfig.getLocation(), ".indexer" ), new File( repositoryConfig.getLocation(), ".indexer" ),
null, null, ArchivaNexusIndexerUtil.FULL_INDEX ); null, null, ArchivaNexusIndexerUtil.FULL_INDEX );
context.setSearchable( true ); context.setSearchable( true );
}
FlatSearchRequest request = new FlatSearchRequest( q ); FlatSearchRequest request = new FlatSearchRequest( q );
FlatSearchResponse response = indexer.searchFlat( request ); FlatSearchResponse response = indexer.searchFlat( request );
@ -179,7 +184,6 @@ public class ArchivaIndexingTaskExecutorTest
assertEquals( "archiva-index-methods-jar-test", artifactInfo.artifactId ); assertEquals( "archiva-index-methods-jar-test", artifactInfo.artifactId );
assertEquals( "test-repo", artifactInfo.repository ); assertEquals( "test-repo", artifactInfo.repository );
context.close( true );
} }
@Test @Test
@ -202,7 +206,7 @@ public class ArchivaIndexingTaskExecutorTest
indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ), indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
Occur.SHOULD ); Occur.SHOULD );
IndexSearcher searcher = nexusIndexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher(); IndexSearcher searcher = indexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher();
TopDocs topDocs = searcher.search( q, null, 10 ); TopDocs topDocs = searcher.search( q, null, 10 );
searcher.close(); searcher.close();
@ -234,7 +238,7 @@ public class ArchivaIndexingTaskExecutorTest
indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ), indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
Occur.SHOULD ); Occur.SHOULD );
IndexSearcher searcher = nexusIndexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher(); IndexSearcher searcher = indexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher();
TopDocs topDocs = searcher.search( q, null, 10 ); TopDocs topDocs = searcher.search( q, null, 10 );
@ -248,7 +252,7 @@ public class ArchivaIndexingTaskExecutorTest
searcher.close(); searcher.close();
context = ArtifactIndexingTask.createContext( repositoryConfig, nexusIndexer ); context = ArtifactIndexingTask.createContext( repositoryConfig, indexer );
// remove added artifact from index // remove added artifact from index
task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.DELETE, context ); task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.DELETE, context );
@ -264,7 +268,7 @@ public class ArchivaIndexingTaskExecutorTest
indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ), indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
Occur.SHOULD ); Occur.SHOULD );
searcher = nexusIndexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher(); searcher = indexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher();
topDocs = searcher.search( q, null, 10 ); topDocs = searcher.search( q, null, 10 );