You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2012/12/04 09:06:52 UTC
svn commit: r1416806 - in /maven/indexer/trunk/indexer-core/src:
main/java/org/apache/maven/index/DefaultSearchEngine.java
test/java/org/apache/maven/index/DefaultSearchEngineTest.java
Author: cstamas
Date: Tue Dec 4 08:06:51 2012
New Revision: 1416806
URL: http://svn.apache.org/viewvc?rev=1416806&view=rev
Log:
MINDEXER-70 fixed DefaultSearchEngine does not release index searcher
Signed-off-by: Igor Fedorenko <ig...@ifedorenko.com>
Signed-off-by: Tamás Cservenák <cs...@apache.org>
Added:
maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/DefaultSearchEngineTest.java
Modified:
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java
Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java?rev=1416806&r1=1416805&r2=1416806&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java Tue Dec 4 08:06:51 2012
@@ -275,10 +275,38 @@ public class DefaultSearchEngine
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;
+ }
}
// ==
Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/DefaultSearchEngineTest.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/DefaultSearchEngineTest.java?rev=1416806&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/DefaultSearchEngineTest.java (added)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/DefaultSearchEngineTest.java Tue Dec 4 08:06:51 2012
@@ -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 );
+ }
+}