From 7f9e6e70e9212b34feca40edc49533b753e1fb9d Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 27 Jun 2011 07:53:59 +0000 Subject: [PATCH] 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 --- .../ArchivaIndexingTaskExecutorTest.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java index bdbc23feb..9a2831169 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java @@ -80,8 +80,6 @@ public class ArchivaIndexingTaskExecutorTest private IndexingContext context; - private NexusIndexer nexusIndexer; - @Inject PlexusSisuBridge plexusSisuBridge; @@ -114,9 +112,7 @@ public class ArchivaIndexingTaskExecutorTest indexingExecutor.setIndexerEngine( indexerEngine ); indexingExecutor.setIndexPacker( indexPacker ); - nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); - - context = ArtifactIndexingTask.createContext( repositoryConfig, nexusIndexer ); + context = ArtifactIndexingTask.createContext( repositoryConfig, indexer ); } @@ -125,8 +121,13 @@ public class ArchivaIndexingTaskExecutorTest public void tearDown() throws Exception { - context.close( true ); - indexer.removeIndexingContext( context, true ); + //context.close( true ); + //indexer.removeIndexingContext( context, true ); + + for (IndexingContext indexingContext : indexer.getIndexingContexts().values()) + { + indexer.removeIndexingContext( indexingContext, true ); + } // delete created index in the repository 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" ) ), Occur.SHOULD ); - IndexingContext context = indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), + if (!indexer.getIndexingContexts().containsKey( repositoryConfig.getId() )) + { + IndexingContext context = indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), new File( repositoryConfig.getLocation() ), new File( repositoryConfig.getLocation(), ".indexer" ), null, null, ArchivaNexusIndexerUtil.FULL_INDEX ); - context.setSearchable( true ); + context.setSearchable( true ); + } + FlatSearchRequest request = new FlatSearchRequest( q ); FlatSearchResponse response = indexer.searchFlat( request ); @@ -179,7 +184,6 @@ public class ArchivaIndexingTaskExecutorTest assertEquals( "archiva-index-methods-jar-test", artifactInfo.artifactId ); assertEquals( "test-repo", artifactInfo.repository ); - context.close( true ); } @Test @@ -202,7 +206,7 @@ public class ArchivaIndexingTaskExecutorTest indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ), 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 ); searcher.close(); @@ -234,7 +238,7 @@ public class ArchivaIndexingTaskExecutorTest indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ), 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 ); @@ -248,7 +252,7 @@ public class ArchivaIndexingTaskExecutorTest searcher.close(); - context = ArtifactIndexingTask.createContext( repositoryConfig, nexusIndexer ); + context = ArtifactIndexingTask.createContext( repositoryConfig, indexer ); // remove added artifact from index 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" ) ), Occur.SHOULD ); - searcher = nexusIndexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher(); + searcher = indexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher(); topDocs = searcher.search( q, null, 10 );