mirror of https://github.com/apache/archiva.git
fix unit tests by using NexusIndexer facade to manipulate index datas : adding/removing artifacts
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1140232 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7f9e6e70e9
commit
f124a475e9
|
@ -22,6 +22,10 @@
|
||||||
<groupId>org.apache.maven.indexer</groupId>
|
<groupId>org.apache.maven.indexer</groupId>
|
||||||
<artifactId>indexer-core</artifactId>
|
<artifactId>indexer-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.inject</groupId>
|
<groupId>javax.inject</groupId>
|
||||||
<artifactId>javax.inject</artifactId>
|
<artifactId>javax.inject</artifactId>
|
||||||
|
@ -39,5 +43,6 @@
|
||||||
<artifactId>slf4j-simple</artifactId>
|
<artifactId>slf4j-simple</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -21,20 +21,20 @@ package org.apache.archiva.scheduler.indexing;
|
||||||
|
|
||||||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
|
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
|
||||||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
|
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.search.BooleanClause;
|
||||||
import org.apache.lucene.search.IndexSearcher;
|
import org.apache.lucene.search.BooleanQuery;
|
||||||
import org.apache.lucene.search.TermQuery;
|
|
||||||
import org.apache.lucene.search.TopDocs;
|
|
||||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
import org.apache.maven.index.ArtifactContext;
|
import org.apache.maven.index.ArtifactContext;
|
||||||
import org.apache.maven.index.ArtifactContextProducer;
|
import org.apache.maven.index.ArtifactContextProducer;
|
||||||
import org.apache.maven.index.ArtifactInfo;
|
|
||||||
import org.apache.maven.index.DefaultArtifactContextProducer;
|
import org.apache.maven.index.DefaultArtifactContextProducer;
|
||||||
import org.apache.maven.index.IndexerEngine;
|
import org.apache.maven.index.FlatSearchRequest;
|
||||||
|
import org.apache.maven.index.FlatSearchResponse;
|
||||||
|
import org.apache.maven.index.MAVEN;
|
||||||
import org.apache.maven.index.NexusIndexer;
|
import org.apache.maven.index.NexusIndexer;
|
||||||
import org.apache.maven.index.artifact.IllegalArtifactCoordinateException;
|
import org.apache.maven.index.artifact.IllegalArtifactCoordinateException;
|
||||||
import org.apache.maven.index.context.IndexingContext;
|
import org.apache.maven.index.context.IndexingContext;
|
||||||
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
|
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
|
||||||
|
import org.apache.maven.index.expr.SourcedSearchExpression;
|
||||||
import org.apache.maven.index.packer.IndexPacker;
|
import org.apache.maven.index.packer.IndexPacker;
|
||||||
import org.apache.maven.index.packer.IndexPackingRequest;
|
import org.apache.maven.index.packer.IndexPackingRequest;
|
||||||
import org.codehaus.plexus.taskqueue.Task;
|
import org.codehaus.plexus.taskqueue.Task;
|
||||||
|
@ -63,11 +63,6 @@ public class ArchivaIndexingTaskExecutor
|
||||||
{
|
{
|
||||||
private Logger log = LoggerFactory.getLogger( ArchivaIndexingTaskExecutor.class );
|
private Logger log = LoggerFactory.getLogger( ArchivaIndexingTaskExecutor.class );
|
||||||
|
|
||||||
/**
|
|
||||||
* plexus.requirement
|
|
||||||
*/
|
|
||||||
private IndexerEngine indexerEngine;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* plexus.requirement
|
* plexus.requirement
|
||||||
*/
|
*/
|
||||||
|
@ -88,15 +83,15 @@ public class ArchivaIndexingTaskExecutor
|
||||||
|
|
||||||
artifactContextProducer = new DefaultArtifactContextProducer();
|
artifactContextProducer = new DefaultArtifactContextProducer();
|
||||||
|
|
||||||
indexerEngine = plexusSisuBridge.lookup( IndexerEngine.class, "default" );
|
|
||||||
|
|
||||||
indexPacker = plexusSisuBridge.lookup( IndexPacker.class, "default" );
|
indexPacker = plexusSisuBridge.lookup( IndexPacker.class, "default" );
|
||||||
|
|
||||||
|
nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeTask( Task task )
|
public void executeTask( Task task )
|
||||||
throws TaskExecutionException
|
throws TaskExecutionException
|
||||||
{
|
{
|
||||||
synchronized ( indexerEngine )
|
synchronized ( nexusIndexer )
|
||||||
{
|
{
|
||||||
ArtifactIndexingTask indexingTask = (ArtifactIndexingTask) task;
|
ArtifactIndexingTask indexingTask = (ArtifactIndexingTask) task;
|
||||||
|
|
||||||
|
@ -116,8 +111,8 @@ public class ArchivaIndexingTaskExecutor
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
log.debug(
|
log.debug( "Creating indexing context on resource: {}",
|
||||||
"Creating indexing context on resource: {}", indexingTask.getResourceFile().getPath() );
|
indexingTask.getResourceFile().getPath() );
|
||||||
context = ArtifactIndexingTask.createContext( repository, nexusIndexer );
|
context = ArtifactIndexingTask.createContext( repository, nexusIndexer );
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
|
@ -146,35 +141,61 @@ public class ArchivaIndexingTaskExecutor
|
||||||
{
|
{
|
||||||
if ( indexingTask.getAction().equals( ArtifactIndexingTask.Action.ADD ) )
|
if ( indexingTask.getAction().equals( ArtifactIndexingTask.Action.ADD ) )
|
||||||
{
|
{
|
||||||
IndexSearcher s = context.getIndexSearcher();
|
//IndexSearcher s = context.getIndexSearcher();
|
||||||
String uinfo = ac.getArtifactInfo().getUinfo();
|
//String uinfo = ac.getArtifactInfo().getUinfo();
|
||||||
TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), 1 );
|
//TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), 1 );
|
||||||
if ( d.totalHits == 0 )
|
|
||||||
|
BooleanQuery q = new BooleanQuery();
|
||||||
|
q.add( nexusIndexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression(
|
||||||
|
ac.getArtifactInfo().groupId ) ), BooleanClause.Occur.MUST );
|
||||||
|
q.add( nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression(
|
||||||
|
ac.getArtifactInfo().artifactId ) ), BooleanClause.Occur.MUST );
|
||||||
|
q.add( nexusIndexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression(
|
||||||
|
ac.getArtifactInfo().version ) ), BooleanClause.Occur.MUST );
|
||||||
|
if (ac.getArtifactInfo().classifier != null)
|
||||||
|
{
|
||||||
|
q.add( nexusIndexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression(
|
||||||
|
ac.getArtifactInfo().classifier ) ), BooleanClause.Occur.MUST );
|
||||||
|
}
|
||||||
|
if (ac.getArtifactInfo().packaging != null)
|
||||||
|
{
|
||||||
|
q.add( nexusIndexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression(
|
||||||
|
ac.getArtifactInfo().packaging ) ), BooleanClause.Occur.MUST );
|
||||||
|
}
|
||||||
|
FlatSearchRequest flatSearchRequest = new FlatSearchRequest( q, context );
|
||||||
|
FlatSearchResponse flatSearchResponse = nexusIndexer.searchFlat( flatSearchRequest );
|
||||||
|
if ( flatSearchResponse.getResults().isEmpty() )
|
||||||
|
//if ( d.totalHits == 0 )
|
||||||
{
|
{
|
||||||
log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo() );
|
log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo() );
|
||||||
indexerEngine.index( context, ac );
|
//indexerEngine.index( context, ac );
|
||||||
context.getIndexWriter().commit();
|
//context.getIndexWriter().commit();
|
||||||
|
nexusIndexer.addArtifactToIndex( ac, context );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo() );
|
log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo() );
|
||||||
indexerEngine.update( context, ac );
|
// TODO check if update exists !!
|
||||||
context.getIndexWriter().commit();
|
nexusIndexer.deleteArtifactFromIndex( ac, context );
|
||||||
|
nexusIndexer.addArtifactToIndex( ac, context );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nexusIndexer.scan( context, true );
|
||||||
|
|
||||||
|
context.updateTimestamp();
|
||||||
|
|
||||||
// close the context if not a repo scan request
|
// close the context if not a repo scan request
|
||||||
if ( !indexingTask.isExecuteOnEntireRepo() )
|
if ( !indexingTask.isExecuteOnEntireRepo() )
|
||||||
{
|
{
|
||||||
log.debug( "Finishing indexing task on resource file : {}",
|
log.debug( "Finishing indexing task on resource file : {}",
|
||||||
indexingTask.getResourceFile().getPath() );
|
indexingTask.getResourceFile().getPath() );
|
||||||
finishIndexingTask( indexingTask, repository, context );
|
finishIndexingTask( indexingTask, repository, context );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo() );
|
log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo() );
|
||||||
indexerEngine.remove( context, ac );
|
nexusIndexer.deleteArtifactFromIndex( ac, context );
|
||||||
context.getIndexWriter().commit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,6 +238,8 @@ public class ArchivaIndexingTaskExecutor
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
olamy don't close it anymore as it nullify IndexSearcher
|
||||||
if ( context != null )
|
if ( context != null )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -229,16 +252,10 @@ public class ArchivaIndexingTaskExecutor
|
||||||
throw new TaskExecutionException( "Error occurred while closing context: " + e.getMessage() );
|
throw new TaskExecutionException( "Error occurred while closing context: " + e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setIndexerEngine( IndexerEngine indexerEngine )
|
|
||||||
{
|
|
||||||
this.indexerEngine = indexerEngine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIndexPacker( IndexPacker indexPacker )
|
public void setIndexPacker( IndexPacker indexPacker )
|
||||||
{
|
{
|
||||||
this.indexPacker = indexPacker;
|
this.indexPacker = indexPacker;
|
||||||
|
|
|
@ -184,9 +184,6 @@ public class ArtifactIndexingTask
|
||||||
managedRepository.toURI().toURL().toString(),
|
managedRepository.toURI().toURL().toString(),
|
||||||
indexDirectory.toURI().toURL().toString(), ArchivaNexusIndexerUtil.FULL_INDEX );
|
indexDirectory.toURI().toURL().toString(), ArchivaNexusIndexerUtil.FULL_INDEX );
|
||||||
|
|
||||||
//IndexingContext context =
|
|
||||||
// new DefaultIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
|
|
||||||
// null, null, ArchivaNexusIndexerUtil.FULL_INDEX, false );
|
|
||||||
context.setSearchable( repository.isScanned() );
|
context.setSearchable( repository.isScanned() );
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
<?xml version="1.0" ?>
|
|
||||||
<!--
|
|
||||||
~ Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
~ or more contributor license agreements. See the NOTICE file
|
|
||||||
~ distributed with this work for additional information
|
|
||||||
~ regarding copyright ownership. The ASF licenses this file
|
|
||||||
~ to you under the Apache License, Version 2.0 (the
|
|
||||||
~ "License"); you may not use this file except in compliance
|
|
||||||
~ with the License. You may obtain a copy of the License at
|
|
||||||
~
|
|
||||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
~
|
|
||||||
~ Unless required by applicable law or agreed to in writing,
|
|
||||||
~ software distributed under the License is distributed on an
|
|
||||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
~ KIND, either express or implied. See the License for the
|
|
||||||
~ specific language governing permissions and limitations
|
|
||||||
~ under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<component-set>
|
|
||||||
<components>
|
|
||||||
<!--
|
|
||||||
|
|
|
||||||
| Indexing Task Queue / Executor
|
|
||||||
|
|
|
||||||
-->
|
|
||||||
<component>
|
|
||||||
<role>org.codehaus.plexus.taskqueue.TaskQueue</role>
|
|
||||||
<role-hint>indexing</role-hint>
|
|
||||||
<implementation>org.codehaus.plexus.taskqueue.DefaultTaskQueue</implementation>
|
|
||||||
<lifecycle-handler>plexus-configurable</lifecycle-handler>
|
|
||||||
<configuration>
|
|
||||||
<task-entry-evaluators>
|
|
||||||
</task-entry-evaluators>
|
|
||||||
<task-exit-evaluators>
|
|
||||||
</task-exit-evaluators>
|
|
||||||
<task-viability-evaluators>
|
|
||||||
</task-viability-evaluators>
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
||||||
|
|
||||||
<component>
|
|
||||||
<role>org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor</role>
|
|
||||||
<role-hint>indexing</role-hint>
|
|
||||||
<implementation>org.codehaus.plexus.taskqueue.execution.ThreadedTaskQueueExecutor</implementation>
|
|
||||||
<instantiation-strategy>singleton</instantiation-strategy>
|
|
||||||
<requirements>
|
|
||||||
<requirement>
|
|
||||||
<role>org.codehaus.plexus.taskqueue.execution.TaskExecutor</role>
|
|
||||||
<role-hint>indexing</role-hint>
|
|
||||||
</requirement>
|
|
||||||
<requirement>
|
|
||||||
<role>org.codehaus.plexus.taskqueue.TaskQueue</role>
|
|
||||||
<role-hint>indexing</role-hint>
|
|
||||||
</requirement>
|
|
||||||
</requirements>
|
|
||||||
<configuration>
|
|
||||||
<name>indexing</name>
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
||||||
</components>
|
|
||||||
</component-set>
|
|
|
@ -32,12 +32,11 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
import org.apache.maven.index.ArtifactInfo;
|
import org.apache.maven.index.ArtifactInfo;
|
||||||
import org.apache.maven.index.FlatSearchRequest;
|
import org.apache.maven.index.FlatSearchRequest;
|
||||||
import org.apache.maven.index.FlatSearchResponse;
|
import org.apache.maven.index.FlatSearchResponse;
|
||||||
import org.apache.maven.index.IndexerEngine;
|
|
||||||
import org.apache.maven.index.MAVEN;
|
import org.apache.maven.index.MAVEN;
|
||||||
import org.apache.maven.index.NexusIndexer;
|
import org.apache.maven.index.NexusIndexer;
|
||||||
import org.apache.maven.index.context.IndexingContext;
|
import org.apache.maven.index.context.IndexingContext;
|
||||||
|
import org.apache.maven.index.expr.SourcedSearchExpression;
|
||||||
import org.apache.maven.index.expr.StringSearchExpression;
|
import org.apache.maven.index.expr.StringSearchExpression;
|
||||||
import org.apache.maven.index.packer.IndexPacker;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -68,18 +67,12 @@ public class ArchivaIndexingTaskExecutorTest
|
||||||
@Inject
|
@Inject
|
||||||
private ArchivaIndexingTaskExecutor indexingExecutor;
|
private ArchivaIndexingTaskExecutor indexingExecutor;
|
||||||
|
|
||||||
private IndexerEngine indexerEngine;
|
|
||||||
|
|
||||||
private IndexPacker indexPacker;
|
|
||||||
|
|
||||||
private ManagedRepositoryConfiguration repositoryConfig;
|
private ManagedRepositoryConfiguration repositoryConfig;
|
||||||
|
|
||||||
private Configuration configuration;
|
private Configuration configuration;
|
||||||
|
|
||||||
private NexusIndexer indexer;
|
private NexusIndexer indexer;
|
||||||
|
|
||||||
private IndexingContext context;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PlexusSisuBridge plexusSisuBridge;
|
PlexusSisuBridge plexusSisuBridge;
|
||||||
|
|
||||||
|
@ -89,10 +82,6 @@ public class ArchivaIndexingTaskExecutorTest
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
//indexingExecutor = new ArchivaIndexingTaskExecutor();
|
|
||||||
//indexingExecutor.setPlexusSisuBridge( plexusSisuBridge );
|
|
||||||
indexingExecutor.initialize();
|
|
||||||
|
|
||||||
repositoryConfig = new ManagedRepositoryConfiguration();
|
repositoryConfig = new ManagedRepositoryConfiguration();
|
||||||
repositoryConfig.setId( "test-repo" );
|
repositoryConfig.setId( "test-repo" );
|
||||||
repositoryConfig.setLocation( "target/test-classes/test-repo" );
|
repositoryConfig.setLocation( "target/test-classes/test-repo" );
|
||||||
|
@ -106,25 +95,16 @@ public class ArchivaIndexingTaskExecutorTest
|
||||||
configuration.addManagedRepository( repositoryConfig );
|
configuration.addManagedRepository( repositoryConfig );
|
||||||
|
|
||||||
indexer = plexusSisuBridge.lookup( NexusIndexer.class );
|
indexer = plexusSisuBridge.lookup( NexusIndexer.class );
|
||||||
indexerEngine = plexusSisuBridge.lookup( IndexerEngine.class );
|
|
||||||
indexPacker = plexusSisuBridge.lookup( IndexPacker.class );
|
|
||||||
|
|
||||||
indexingExecutor.setIndexerEngine( indexerEngine );
|
|
||||||
indexingExecutor.setIndexPacker( indexPacker );
|
|
||||||
|
|
||||||
context = ArtifactIndexingTask.createContext( repositoryConfig, indexer );
|
|
||||||
|
|
||||||
|
|
||||||
|
ArtifactIndexingTask.createContext( repositoryConfig, indexer );
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown()
|
public void tearDown()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
//context.close( true );
|
|
||||||
//indexer.removeIndexingContext( context, true );
|
|
||||||
|
|
||||||
for (IndexingContext indexingContext : indexer.getIndexingContexts().values())
|
for ( IndexingContext indexingContext : indexer.getIndexingContexts().values() )
|
||||||
{
|
{
|
||||||
indexer.removeIndexingContext( indexingContext, true );
|
indexer.removeIndexingContext( indexingContext, true );
|
||||||
}
|
}
|
||||||
|
@ -141,6 +121,11 @@ public class ArchivaIndexingTaskExecutorTest
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected IndexingContext getIndexingContext()
|
||||||
|
{
|
||||||
|
return indexer.getIndexingContexts().get( repositoryConfig.getId() );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddArtifactToIndex()
|
public void testAddArtifactToIndex()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -149,7 +134,8 @@ public class ArchivaIndexingTaskExecutorTest
|
||||||
"org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
|
"org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
|
||||||
|
|
||||||
ArtifactIndexingTask task =
|
ArtifactIndexingTask task =
|
||||||
new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD, context );
|
new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
|
||||||
|
getIndexingContext() );
|
||||||
|
|
||||||
indexingExecutor.executeTask( task );
|
indexingExecutor.executeTask( task );
|
||||||
|
|
||||||
|
@ -160,16 +146,16 @@ 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() ))
|
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(),
|
||||||
null, null, ArchivaNexusIndexerUtil.FULL_INDEX );
|
".indexer" ), 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 );
|
||||||
|
|
||||||
|
@ -194,7 +180,8 @@ public class ArchivaIndexingTaskExecutorTest
|
||||||
"org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
|
"org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
|
||||||
|
|
||||||
ArtifactIndexingTask task =
|
ArtifactIndexingTask task =
|
||||||
new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD, context );
|
new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
|
||||||
|
getIndexingContext() );
|
||||||
|
|
||||||
indexingExecutor.executeTask( task );
|
indexingExecutor.executeTask( task );
|
||||||
indexingExecutor.executeTask( task );
|
indexingExecutor.executeTask( task );
|
||||||
|
@ -226,60 +213,55 @@ public class ArchivaIndexingTaskExecutorTest
|
||||||
"org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
|
"org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
|
||||||
|
|
||||||
ArtifactIndexingTask task =
|
ArtifactIndexingTask task =
|
||||||
new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD, context );
|
new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
|
||||||
|
getIndexingContext() );
|
||||||
|
|
||||||
// remove artifact from index
|
// add artifact to index
|
||||||
indexingExecutor.executeTask( task );
|
indexingExecutor.executeTask( task );
|
||||||
|
|
||||||
BooleanQuery q = new BooleanQuery();
|
BooleanQuery q = new BooleanQuery();
|
||||||
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
|
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.archiva" ) ),
|
||||||
Occur.SHOULD );
|
Occur.SHOULD );
|
||||||
q.add(
|
//q.add(
|
||||||
indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
|
// indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( "archiva-index-methods-jar-test" ) ),
|
||||||
Occur.SHOULD );
|
// Occur.SHOULD );
|
||||||
|
|
||||||
IndexSearcher searcher = indexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher();
|
FlatSearchRequest flatSearchRequest =
|
||||||
|
new FlatSearchRequest( q, indexer.getIndexingContexts().get( repositoryConfig.getId() ) );
|
||||||
|
|
||||||
TopDocs topDocs = searcher.search( q, null, 10 );
|
FlatSearchResponse response = indexer.searchFlat( flatSearchRequest );
|
||||||
|
|
||||||
searcher.close();
|
|
||||||
|
|
||||||
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
|
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
|
||||||
assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
|
assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
|
||||||
|
|
||||||
// should return 1 hit
|
// should return 1 hit
|
||||||
assertEquals( 1, topDocs.totalHits );
|
assertEquals( 1, response.getTotalHitsCount() );
|
||||||
|
|
||||||
searcher.close();
|
|
||||||
|
|
||||||
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,
|
||||||
|
getIndexingContext() );
|
||||||
indexingExecutor.executeTask( task );
|
indexingExecutor.executeTask( task );
|
||||||
|
|
||||||
task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH, context );
|
task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH,
|
||||||
|
getIndexingContext() );
|
||||||
indexingExecutor.executeTask( task );
|
indexingExecutor.executeTask( task );
|
||||||
|
|
||||||
q = new BooleanQuery();
|
q = new BooleanQuery();
|
||||||
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
|
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.archiva" ) ),
|
||||||
|
Occur.SHOULD );
|
||||||
|
q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID,
|
||||||
|
new SourcedSearchExpression( "archiva-index-methods-jar-test" ) ),
|
||||||
Occur.SHOULD );
|
Occur.SHOULD );
|
||||||
q.add(
|
|
||||||
indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
|
|
||||||
Occur.SHOULD );
|
|
||||||
|
|
||||||
searcher = indexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher();
|
|
||||||
|
|
||||||
topDocs = searcher.search( q, null, 10 );
|
|
||||||
|
|
||||||
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
|
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
|
||||||
assertTrue( new File( repositoryConfig.getLocation(), ".index" ).exists() );
|
assertTrue( new File( repositoryConfig.getLocation(), ".index" ).exists() );
|
||||||
|
|
||||||
// artifact should have been removed from the index!
|
flatSearchRequest = new FlatSearchRequest( q, getIndexingContext() );
|
||||||
assertEquals( 0, topDocs.totalHits );
|
|
||||||
|
response = indexer.searchFlat( flatSearchRequest );
|
||||||
|
// artifact should have been removed from the index!
|
||||||
|
assertEquals( 0, response.getTotalHitsCount() );//.totalHits );
|
||||||
|
|
||||||
context.close( true );
|
|
||||||
searcher.close();
|
|
||||||
// TODO: test it was removed from the packaged index also
|
// TODO: test it was removed from the packaged index also
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,11 +273,13 @@ public class ArchivaIndexingTaskExecutorTest
|
||||||
"org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
|
"org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
|
||||||
|
|
||||||
ArtifactIndexingTask task =
|
ArtifactIndexingTask task =
|
||||||
new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD, context );
|
new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
|
||||||
|
getIndexingContext() );
|
||||||
|
|
||||||
indexingExecutor.executeTask( task );
|
indexingExecutor.executeTask( task );
|
||||||
|
|
||||||
task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH, context );
|
task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH,
|
||||||
|
getIndexingContext() );
|
||||||
|
|
||||||
indexingExecutor.executeTask( task );
|
indexingExecutor.executeTask( task );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue