Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MINDEXER-70 fixed DefaultSearchEngine does not release index searcher

Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
Signed-off-by: Tamás Cservenák <cstamas@apache.org>

git-svn-id: https://svn.apache.org/repos/asf/maven/indexer/trunk@1416806 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 80008b3b24bfb029a5f37fbd205cd6ac0ce59684 1 parent 12036f5
@cstamas cstamas authored
View
34 indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java
@@ -275,10 +275,38 @@ private IteratorSearchResponse searchIteratorPaged( IteratorSearchRequest reques
NexusIndexMultiSearcher indexSearcher = new NexusIndexMultiSearcher( multiReader );
- TopScoreDocCollector hits = doSearchWithCeiling( request, indexSearcher, request.getQuery() );
+ try
+ {
+ TopScoreDocCollector hits = doSearchWithCeiling( request, indexSearcher, request.getQuery() );
- return new IteratorSearchResponse( request.getQuery(), hits.getTotalHits(), new DefaultIteratorResultSet(
- request, indexSearcher, contexts, hits.topDocs() ) );
+ return new IteratorSearchResponse( request.getQuery(), hits.getTotalHits(),
+ new DefaultIteratorResultSet( request, indexSearcher, contexts,
+ hits.topDocs() ) );
+ }
+ catch ( IOException e )
+ {
+ try
+ {
+ indexSearcher.release();
+ }
+ catch ( Exception secondary )
+ {
+ // do not mask original exception
+ }
+ throw e;
+ }
+ catch ( RuntimeException e )
+ {
+ try
+ {
+ indexSearcher.release();
+ }
+ catch ( Exception secondary )
+ {
+ // do not mask original exception
+ }
+ throw e;
+ }
}
// ==
View
125 indexer-core/src/test/java/org/apache/maven/index/DefaultSearchEngineTest.java
@@ -0,0 +1,125 @@
+package org.apache.maven.index;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.store.Directory;
+import org.apache.maven.index.context.DefaultIndexingContext;
+import org.apache.maven.index.context.ExistingLuceneIndexMismatchException;
+import org.apache.maven.index.context.IndexCreator;
+import org.apache.maven.index.context.IndexingContext;
+import org.apache.maven.index.util.IndexCreatorSorter;
+
+public class DefaultSearchEngineTest
+ extends AbstractNexusIndexerTest
+{
+
+ private static class CountingIndexingContext
+ extends DefaultIndexingContext
+ {
+ public int count;
+
+ public CountingIndexingContext( String id, String repositoryId, File repository, Directory indexDirectory,
+ String repositoryUrl, String indexUpdateUrl,
+ List<? extends IndexCreator> indexCreators, boolean reclaimIndex )
+ throws IOException, ExistingLuceneIndexMismatchException
+ {
+ super( id, repositoryId, repository, indexDirectory, repositoryUrl, indexUpdateUrl, indexCreators,
+ reclaimIndex );
+ }
+
+ public IndexSearcher acquireIndexSearcher()
+ throws IOException
+ {
+ try
+ {
+ return super.acquireIndexSearcher();
+ }
+ finally
+ {
+ count++;
+ }
+ };
+
+ @Override
+ public void releaseIndexSearcher( IndexSearcher is )
+ throws IOException
+ {
+ try
+ {
+ super.releaseIndexSearcher( is );
+ }
+ finally
+ {
+ count--;
+ }
+ }
+ }
+
+ @Override
+ protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
+ throws Exception
+ {
+ File repo = new File( getBasedir(), "src/test/repo" );
+ context =
+ new CountingIndexingContext( "test-minimal", "test", repo, indexDir, null, null,
+ IndexCreatorSorter.sort( MIN_CREATORS ), false );
+
+ nexusIndexer.scan( context );
+ }
+
+ private SearchEngine searchEngine;
+
+ @Override
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ searchEngine = lookup( SearchEngine.class );
+ }
+
+ @Override
+ protected void tearDown()
+ throws Exception
+ {
+ searchEngine = null;
+ super.tearDown();
+ }
+
+ public void testExceptionInArtifactFilter()
+ throws Exception
+ {
+ Query q = nexusIndexer.constructQuery( MAVEN.GROUP_ID, "com.adobe.flexunit", SearchType.EXACT );
+ IteratorSearchRequest request = new IteratorSearchRequest( q );
+ request.setArtifactInfoFilter( new ArtifactInfoFilter()
+ {
+ public boolean accepts( IndexingContext ctx, ArtifactInfo ai )
+ {
+ throw new RuntimeException();
+ }
+ } );
+ request.setArtifactInfoPostprocessor( new ArtifactInfoPostprocessor()
+ {
+ public void postprocess( IndexingContext ctx, ArtifactInfo ai )
+ {
+ throw new RuntimeException();
+ }
+ } );
+
+ try
+ {
+ searchEngine.forceSearchIteratorPaged( request, Collections.singletonList( context ) );
+ }
+ catch ( RuntimeException e )
+ {
+ // this is the point of this test
+ }
+
+ assertEquals( 0, ( (CountingIndexingContext) context ).count );
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.