fix unit test, ArtifactIndexingTask has now a new field onlyUpdate to prevent full scan after only adding a file

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1159077 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-08-18 08:17:26 +00:00
parent 3652f4c6e4
commit 0ea6774509
3 changed files with 46 additions and 13 deletions

View File

@ -112,11 +112,9 @@ public class ArchivaIndexingTaskExecutor
if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction() ) if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction() )
&& indexingTask.isExecuteOnEntireRepo() ) && indexingTask.isExecuteOnEntireRepo() )
{ {
// TODO update or not !!
// olamy currently do the full scan
try try
{ {
nexusIndexer.scan( context, null, false ); nexusIndexer.scan( context, null, indexingTask.isOnlyUpdate() );
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -51,6 +51,11 @@ public class ArtifactIndexingTask
private boolean executeOnEntireRepo = true; private boolean executeOnEntireRepo = true;
/**
* @since 1.4
*/
private boolean onlyUpdate = false;
public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File resourceFile, Action action, public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File resourceFile, Action action,
IndexingContext context ) IndexingContext context )
{ {
@ -67,6 +72,13 @@ public class ArtifactIndexingTask
this.executeOnEntireRepo = executeOnEntireRepo; this.executeOnEntireRepo = executeOnEntireRepo;
} }
public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File resourceFile, Action action,
IndexingContext context, boolean executeOnEntireRepo, boolean onlyUpdate )
{
this( repository, resourceFile, action, context, executeOnEntireRepo );
this.onlyUpdate = onlyUpdate;
}
public boolean isExecuteOnEntireRepo() public boolean isExecuteOnEntireRepo()
{ {
return executeOnEntireRepo; return executeOnEntireRepo;
@ -92,13 +104,6 @@ public class ArtifactIndexingTask
return action; return action;
} }
@Override
public String toString()
{
return "ArtifactIndexingTask [action=" + action + ", repositoryId=" + repository.getId() + ", resourceFile="
+ resourceFile + "]";
}
public ManagedRepositoryConfiguration getRepository() public ManagedRepositoryConfiguration getRepository()
{ {
return repository; return repository;
@ -109,6 +114,16 @@ public class ArtifactIndexingTask
return context; return context;
} }
public boolean isOnlyUpdate()
{
return onlyUpdate;
}
public void setOnlyUpdate( boolean onlyUpdate )
{
this.onlyUpdate = onlyUpdate;
}
@Override @Override
public int hashCode() public int hashCode()
{ {
@ -158,6 +173,23 @@ public class ArtifactIndexingTask
return true; return true;
} }
@Override
public String toString()
{
return "ArtifactIndexingTask [action=" + action + ", repositoryId=" + repository.getId() + ", resourceFile="
+ resourceFile + "]";
}
/**
* FIXME remove this static somewhere else !
* @param repository
* @param indexer
* @param indexCreators
* @return
* @throws IOException
* @throws UnsupportedExistingLuceneIndexException
*/
public static IndexingContext createContext( ManagedRepositoryConfiguration repository, NexusIndexer indexer, public static IndexingContext createContext( ManagedRepositoryConfiguration repository, NexusIndexer indexer,
List<? extends IndexCreator> indexCreators ) List<? extends IndexCreator> indexCreators )
throws IOException, UnsupportedExistingLuceneIndexException throws IOException, UnsupportedExistingLuceneIndexException

View File

@ -278,12 +278,15 @@ public class ArchivaIndexingTaskExecutorTest
ArtifactIndexingTask task = ArtifactIndexingTask task =
new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD, new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
getIndexingContext() ); getIndexingContext() );
task.setExecuteOnEntireRepo( false );
indexingExecutor.executeTask( task ); indexingExecutor.executeTask( task );
task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH, task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH,
getIndexingContext() ); getIndexingContext() );
task.setExecuteOnEntireRepo( false );
indexingExecutor.executeTask( task ); indexingExecutor.executeTask( task );
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() ); assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
@ -303,14 +306,14 @@ public class ArchivaIndexingTaskExecutorTest
FlatSearchRequest request = new FlatSearchRequest( q, getIndexingContext() ); FlatSearchRequest request = new FlatSearchRequest( q, getIndexingContext() );
FlatSearchResponse response = indexer.searchFlat( request ); FlatSearchResponse response = indexer.searchFlat( request );
assertEquals( 1, response.getTotalHits() );
Set<ArtifactInfo> results = response.getResults(); Set<ArtifactInfo> results = response.getResults();
ArtifactInfo artifactInfo = (ArtifactInfo) results.iterator().next(); ArtifactInfo artifactInfo = results.iterator().next();
assertEquals( "org.apache.archiva", artifactInfo.groupId ); assertEquals( "org.apache.archiva", artifactInfo.groupId );
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 );
assertEquals( 1, response.getTotalHits() );
} }
private void unzipIndex( String indexDir, String destDir ) private void unzipIndex( String indexDir, String destDir )