[MRM-1079]

o updated and activated tests for index cleanup consumer
o cleaned up index cleanup consumer


git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@746169 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2009-02-20 06:52:41 +00:00
parent 57ebe9526a
commit 48e96d554f
3 changed files with 77 additions and 67 deletions

View File

@ -41,7 +41,6 @@ import org.sonatype.nexus.index.NexusIndexer;
import org.sonatype.nexus.index.context.IndexingContext; import org.sonatype.nexus.index.context.IndexingContext;
import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException; import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException;
import org.sonatype.nexus.index.creator.AbstractIndexCreator; import org.sonatype.nexus.index.creator.AbstractIndexCreator;
import org.sonatype.nexus.index.creator.IndexerEngine;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -64,22 +63,17 @@ public class LuceneCleanupRemoveIndexedConsumer
private ArtifactContextProducer artifactContextProducer; private ArtifactContextProducer artifactContextProducer;
private IndexerEngine indexerEngine;
private IndexingContext context; private IndexingContext context;
public LuceneCleanupRemoveIndexedConsumer( RepositoryContentFactory repoFactory, NexusIndexer indexer, public LuceneCleanupRemoveIndexedConsumer( RepositoryContentFactory repoFactory, NexusIndexer indexer )
IndexerEngine indexerEngine )
{ {
this.repoFactory = repoFactory; this.repoFactory = repoFactory;
this.indexer = indexer; this.indexer = indexer;
this.indexerEngine = indexerEngine;
this.artifactContextProducer = new DefaultArtifactContextProducer(); this.artifactContextProducer = new DefaultArtifactContextProducer();
} }
public void beginScan() public void beginScan()
{ {
// TODO Auto-generated method stub
} }
@ -136,7 +130,6 @@ public class LuceneCleanupRemoveIndexedConsumer
context.setSearchable( repository.isScanned() ); context.setSearchable( repository.isScanned() );
File artifactFile = new File( repoContent.getRepoRoot(), repoContent.toPath( artifact ) ); File artifactFile = new File( repoContent.getRepoRoot(), repoContent.toPath( artifact ) );
System.out.println( "artifactFile :: " + artifactFile.getAbsolutePath() );
if ( !artifactFile.exists() ) if ( !artifactFile.exists() )
{ {
@ -147,7 +140,7 @@ public class LuceneCleanupRemoveIndexedConsumer
{ {
//indexerEngine.remove( context, artifactContext ); //indexerEngine.remove( context, artifactContext );
// hack for deleting documents - indexer engine's isn't working for me // hack for deleting documents - indexer engine's remove(...) isn't working for me
removeDocuments( artifactContext ); removeDocuments( artifactContext );
} }
} }
@ -167,7 +160,7 @@ public class LuceneCleanupRemoveIndexedConsumer
throw new ConsumerException( "Can't run index cleanup consumer: " + e.getMessage() ); throw new ConsumerException( "Can't run index cleanup consumer: " + e.getMessage() );
} }
} }
private void removeDocuments( ArtifactContext ac ) private void removeDocuments( ArtifactContext ac )
throws IOException throws IOException
{ {
@ -209,4 +202,9 @@ public class LuceneCleanupRemoveIndexedConsumer
{ {
this.repoFactory = repoFactory; this.repoFactory = repoFactory;
} }
public void setArtifactContextProducer( ArtifactContextProducer artifactContextProducer )
{
this.artifactContextProducer = artifactContextProducer;
}
} }

View File

@ -12,6 +12,5 @@
<bean id="indexCleanupConsumer" class="org.apache.archiva.consumers.lucene.LuceneCleanupRemoveIndexedConsumer"> <bean id="indexCleanupConsumer" class="org.apache.archiva.consumers.lucene.LuceneCleanupRemoveIndexedConsumer">
<constructor-arg ref="repositoryContentFactory"/> <constructor-arg ref="repositoryContentFactory"/>
<constructor-arg ref="nexusIndexer#archiva"/> <constructor-arg ref="nexusIndexer#archiva"/>
<constructor-arg ref="indexerEngine"/>
</bean> </bean>
</beans> </beans>

View File

@ -32,47 +32,48 @@ import org.easymock.MockControl;
import org.easymock.classextension.MockClassControl; import org.easymock.classextension.MockClassControl;
import org.sonatype.nexus.index.ArtifactContext; import org.sonatype.nexus.index.ArtifactContext;
import org.sonatype.nexus.index.ArtifactContextProducer; import org.sonatype.nexus.index.ArtifactContextProducer;
import org.sonatype.nexus.index.DefaultArtifactContextProducer; import org.sonatype.nexus.index.ArtifactInfo;
import org.sonatype.nexus.index.NexusIndexer; import org.sonatype.nexus.index.NexusIndexer;
import org.sonatype.nexus.index.context.DefaultIndexingContext; import org.sonatype.nexus.index.context.DefaultIndexingContext;
import org.sonatype.nexus.index.context.IndexingContext; import org.sonatype.nexus.index.context.IndexingContext;
import org.sonatype.nexus.index.creator.IndexerEngine;
public class LuceneCleanupRemoveIndexedConsumerTest public class LuceneCleanupRemoveIndexedConsumerTest
extends PlexusInSpringTestCase extends PlexusInSpringTestCase
{ {
private LuceneCleanupRemoveIndexedConsumer consumer; private LuceneCleanupRemoveIndexedConsumer consumer;
private MockControl indexerControl; private MockControl indexerControl;
private NexusIndexer indexer; private NexusIndexer indexer;
private RepositoryContentFactory repoFactory; private RepositoryContentFactory repoFactory;
private MockControl repoFactoryControl; private MockControl repoFactoryControl;
private ManagedRepositoryConfiguration repositoryConfig; private ManagedRepositoryConfiguration repositoryConfig;
private MockControl contextProducerControl;
private ArtifactContextProducer artifactContextProducer; private ArtifactContextProducer artifactContextProducer;
private IndexerEngine indexerEngine; private MockControl acControl;
private ArtifactContext ac;
public void setUp() public void setUp()
throws Exception throws Exception
{ {
super.setUp(); super.setUp();
indexerControl = MockControl.createControl( NexusIndexer.class ); indexerControl = MockControl.createControl( NexusIndexer.class );
indexerControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); indexerControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
indexer = ( NexusIndexer ) indexerControl.getMock(); indexer = (NexusIndexer) indexerControl.getMock();
repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class ); repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
repoFactory = ( RepositoryContentFactory ) repoFactoryControl.getMock(); repoFactory = (RepositoryContentFactory) repoFactoryControl.getMock();
indexerEngine = ( IndexerEngine ) lookup( IndexerEngine.class ); consumer = new LuceneCleanupRemoveIndexedConsumer( repoFactory, indexer );
consumer = new LuceneCleanupRemoveIndexedConsumer( repoFactory, indexer, indexerEngine );
repositoryConfig = new ManagedRepositoryConfiguration(); repositoryConfig = new ManagedRepositoryConfiguration();
repositoryConfig.setId( "test-repo" ); repositoryConfig.setId( "test-repo" );
repositoryConfig.setLocation( getBasedir() + "/target/test-classes/test-repo" ); repositoryConfig.setLocation( getBasedir() + "/target/test-classes/test-repo" );
@ -80,28 +81,34 @@ public class LuceneCleanupRemoveIndexedConsumerTest
repositoryConfig.setName( "Test Repository" ); repositoryConfig.setName( "Test Repository" );
repositoryConfig.setScanned( true ); repositoryConfig.setScanned( true );
repositoryConfig.setSnapshots( false ); repositoryConfig.setSnapshots( false );
repositoryConfig.setReleases( true ); repositoryConfig.setReleases( true );
repositoryConfig.setIndexDir( getBasedir() + "/target/test-classes/test-repo/.cleanup-index" ); repositoryConfig.setIndexDir( getBasedir() + "/target/test-classes/test-repo/.cleanup-index" );
artifactContextProducer = new DefaultArtifactContextProducer(); contextProducerControl = MockControl.createControl( ArtifactContextProducer.class );
artifactContextProducer = (ArtifactContextProducer) contextProducerControl.getMock();
consumer.setArtifactContextProducer( artifactContextProducer );
acControl = MockClassControl.createControl( ArtifactContext.class );
ac = (ArtifactContext) acControl.getMock();
} }
public void tearDown() public void tearDown()
throws Exception throws Exception
{ {
FileUtils.deleteDirectory( new File( repositoryConfig.getIndexDir() ) ); FileUtils.deleteDirectory( new File( repositoryConfig.getIndexDir() ) );
super.tearDown(); super.tearDown();
} }
public void testProcessArtifactArtifactDoesNotExist() public void testProcessArtifactArtifactDoesNotExist()
throws Exception throws Exception
{ {
/*ArchivaArtifact artifact = ArchivaArtifact artifact =
new ArchivaArtifact( "org.apache.archiva", "archiva-lucene-consumers", "1.2", null, "jar", "test-repo" ); new ArchivaArtifact( "org.apache.archiva", "archiva-lucene-consumers", "1.2", null, "jar", "test-repo" );
ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent(); ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
repoContent.setRepository( repositoryConfig ); repoContent.setRepository( repositoryConfig );
IndexingContext context = IndexingContext context =
new DefaultIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), new DefaultIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
new File( repositoryConfig.getLocation() ), new File( repositoryConfig.getLocation() ),
@ -111,51 +118,57 @@ public class LuceneCleanupRemoveIndexedConsumerTest
File artifactFile = File artifactFile =
new File( repositoryConfig.getLocation(), new File( repositoryConfig.getLocation(),
"org/apache/archiva/archiva-lucene-consumers/1.2/archiva-lucene-consumers-1.2.jar" ); "org/apache/archiva/archiva-lucene-consumers/1.2/archiva-lucene-consumers-1.2.jar" );
ArtifactContext artifactContext = artifactContextProducer.getArtifactContext( context, artifactFile ); ArtifactInfo ai = new ArtifactInfo( "test-repo", "org.apache.archiva", "archiva-lucene-consumers", "1.2", null );
repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( repositoryConfig.getId() ), repoContent ); repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( repositoryConfig.getId() ),
repoContent );
indexerControl.expectAndReturn( indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), indexerControl.expectAndReturn( indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
new File( repositoryConfig.getLocation() ), new File( repositoryConfig.getLocation() ),
new File( repositoryConfig.getIndexDir() ), null, null, new File( repositoryConfig.getIndexDir() ), null,
NexusIndexer.FULL_INDEX ), context ); null, NexusIndexer.FULL_INDEX ), context );
indexer.deleteArtifactFromIndex( artifactContext, context ); contextProducerControl.expectAndReturn( artifactContextProducer.getArtifactContext( context, artifactFile ), ac );
indexerControl.setVoidCallable(); acControl.expectAndReturn( ac.getArtifactInfo(), ai );
repoFactoryControl.replay(); repoFactoryControl.replay();
indexerControl.replay(); indexerControl.replay();
contextProducerControl.replay();
acControl.replay();
consumer.processArchivaArtifact( artifact ); consumer.processArchivaArtifact( artifact );
repoFactoryControl.verify(); repoFactoryControl.verify();
indexerControl.verify(); */ indexerControl.verify();
} contextProducerControl.verify();
acControl.verify();
}
public void testProcessArtifactArtifactExists() public void testProcessArtifactArtifactExists()
throws Exception throws Exception
{ {
/*ArchivaArtifact artifact = ArchivaArtifact artifact =
new ArchivaArtifact( "org.apache.maven.archiva", "archiva-lucene-cleanup", "1.0", null, "jar", "test-repo" ); new ArchivaArtifact( "org.apache.maven.archiva", "archiva-lucene-cleanup", "1.0", null, "jar", "test-repo" );
ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent(); ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
repoContent.setRepository( repositoryConfig ); repoContent.setRepository( repositoryConfig );
IndexingContext context = IndexingContext context =
new DefaultIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), new DefaultIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
new File( repositoryConfig.getLocation() ), new File( repositoryConfig.getLocation() ),
new File( repositoryConfig.getIndexDir() ), null, null, new File( repositoryConfig.getIndexDir() ), null, null,
NexusIndexer.FULL_INDEX, false ); NexusIndexer.FULL_INDEX, false );
repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( repositoryConfig.getId() ), repoContent ); repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( repositoryConfig.getId() ),
repoContent );
indexerControl.expectAndReturn( indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), indexerControl.expectAndReturn( indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
new File( repositoryConfig.getLocation() ), new File( repositoryConfig.getLocation() ),
new File( repositoryConfig.getIndexDir() ), null, null, new File( repositoryConfig.getIndexDir() ), null,
NexusIndexer.FULL_INDEX ), context ); null, NexusIndexer.FULL_INDEX ), context );
repoFactoryControl.replay(); repoFactoryControl.replay();
indexerControl.replay(); indexerControl.replay();
consumer.processArchivaArtifact( artifact ); consumer.processArchivaArtifact( artifact );
repoFactoryControl.verify(); repoFactoryControl.verify();
indexerControl.verify(); */ indexerControl.verify();
} }
} }