mirror of https://github.com/apache/archiva.git
fix index optimize default index location
optimize io in search rest service unit test git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1171043 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7c1ab2042a
commit
92f181109d
|
@ -24,9 +24,9 @@ import org.apache.archiva.admin.model.managed.ManagedRepository;
|
||||||
import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
|
import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
|
||||||
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.commons.lang.StringUtils;
|
||||||
import org.apache.lucene.search.BooleanClause;
|
import org.apache.lucene.search.BooleanClause;
|
||||||
import org.apache.lucene.search.BooleanQuery;
|
import org.apache.lucene.search.BooleanQuery;
|
||||||
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.DefaultArtifactContextProducer;
|
import org.apache.maven.index.DefaultArtifactContextProducer;
|
||||||
|
@ -58,7 +58,6 @@ import java.util.List;
|
||||||
* ArchivaIndexingTaskExecutor Executes all indexing tasks. Adding, updating and removing artifacts from the index are
|
* ArchivaIndexingTaskExecutor Executes all indexing tasks. Adding, updating and removing artifacts from the index are
|
||||||
* all performed by this executor. Add and update artifact in index tasks are added in the indexing task queue by the
|
* all performed by this executor. Add and update artifact in index tasks are added in the indexing task queue by the
|
||||||
* NexusIndexerConsumer while remove artifact from index tasks are added by the LuceneCleanupRemoveIndexedConsumer.
|
* NexusIndexerConsumer while remove artifact from index tasks are added by the LuceneCleanupRemoveIndexedConsumer.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Service( "taskExecutor#indexing" )
|
@Service( "taskExecutor#indexing" )
|
||||||
public class ArchivaIndexingTaskExecutor
|
public class ArchivaIndexingTaskExecutor
|
||||||
|
@ -239,9 +238,11 @@ public class ArchivaIndexingTaskExecutor
|
||||||
|
|
||||||
context.optimize();
|
context.optimize();
|
||||||
|
|
||||||
|
|
||||||
File managedRepository = new File( repository.getLocation() );
|
File managedRepository = new File( repository.getLocation() );
|
||||||
final File indexLocation = new File( managedRepository, ".index" );
|
String indexDirectory = repository.getIndexDirectory();
|
||||||
|
final File indexLocation = StringUtils.isBlank( indexDirectory )
|
||||||
|
? new File( managedRepository, ".indexer" )
|
||||||
|
: new File( indexDirectory );
|
||||||
IndexPackingRequest request = new IndexPackingRequest( context, indexLocation );
|
IndexPackingRequest request = new IndexPackingRequest( context, indexLocation );
|
||||||
indexPacker.packIndex( request );
|
indexPacker.packIndex( request );
|
||||||
|
|
||||||
|
|
|
@ -253,7 +253,7 @@ public class ArchivaIndexingTaskExecutorTest
|
||||||
Occur.SHOULD );
|
Occur.SHOULD );
|
||||||
|
|
||||||
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
|
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
|
||||||
assertTrue( new File( repositoryConfig.getLocation(), ".index" ).exists() );
|
assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
|
||||||
|
|
||||||
flatSearchRequest = new FlatSearchRequest( q, getIndexingContext() );
|
flatSearchRequest = new FlatSearchRequest( q, getIndexingContext() );
|
||||||
|
|
||||||
|
@ -286,11 +286,10 @@ public class ArchivaIndexingTaskExecutorTest
|
||||||
indexingExecutor.executeTask( task );
|
indexingExecutor.executeTask( task );
|
||||||
|
|
||||||
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
|
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
|
||||||
assertTrue( new File( repositoryConfig.getLocation(), ".index" ).exists() );
|
|
||||||
|
|
||||||
// unpack .zip index
|
// unpack .zip index
|
||||||
File destDir = new File( repositoryConfig.getLocation(), ".index/tmp" );
|
File destDir = new File( repositoryConfig.getLocation(), ".indexer/tmp" );
|
||||||
unzipIndex( new File( repositoryConfig.getLocation(), ".index" ).getPath(), destDir.getPath() );
|
unzipIndex( new File( repositoryConfig.getLocation(), ".indexer" ).getPath(), destDir.getPath() );
|
||||||
|
|
||||||
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 StringSearchExpression( "org.apache.archiva" ) ),
|
||||||
|
|
|
@ -248,7 +248,6 @@
|
||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
<plexus.home>${project.build.outputDirectory}</plexus.home>
|
<plexus.home>${project.build.outputDirectory}</plexus.home>
|
||||||
<appserver.base>${basedir}/target/appserver-base</appserver.base>
|
<appserver.base>${basedir}/target/appserver-base</appserver.base>
|
||||||
<targetDir>${basedir}/target/</targetDir>
|
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -23,7 +23,6 @@ import org.apache.archiva.rest.api.model.ManagedRepository;
|
||||||
import org.apache.archiva.rest.api.model.SearchRequest;
|
import org.apache.archiva.rest.api.model.SearchRequest;
|
||||||
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
|
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
|
||||||
import org.apache.archiva.rest.api.services.SearchService;
|
import org.apache.archiva.rest.api.services.SearchService;
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -146,7 +145,6 @@ public class SearchServiceTest
|
||||||
assertTrue(
|
assertTrue(
|
||||||
" not 1 results for Bundle Symbolic Name org.apache.karaf.features.command but " + artifacts.size() + ":"
|
" not 1 results for Bundle Symbolic Name org.apache.karaf.features.command but " + artifacts.size() + ":"
|
||||||
+ artifacts, artifacts.size() == 1 );
|
+ artifacts, artifacts.size() == 1 );
|
||||||
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
|
|
||||||
|
|
||||||
deleteTestRepo( testRepoId, targetRepo );
|
deleteTestRepo( testRepoId, targetRepo );
|
||||||
}
|
}
|
||||||
|
@ -176,7 +174,34 @@ public class SearchServiceTest
|
||||||
assertTrue(
|
assertTrue(
|
||||||
" not 2 results for Bundle Symbolic Name org.apache.karaf.features.core but " + artifacts.size() + ":"
|
" not 2 results for Bundle Symbolic Name org.apache.karaf.features.core but " + artifacts.size() + ":"
|
||||||
+ artifacts, artifacts.size() == 2 );
|
+ artifacts, artifacts.size() == 2 );
|
||||||
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
|
|
||||||
|
deleteTestRepo( testRepoId, targetRepo );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void searchWithSearchRequestExportPackageOneVersion()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
String testRepoId = "test-repo";
|
||||||
|
// force guest user creation if not exists
|
||||||
|
if ( getUserService( authorizationHeader ).getGuestUser() == null )
|
||||||
|
{
|
||||||
|
assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
|
||||||
|
}
|
||||||
|
|
||||||
|
File targetRepo = createAndIndexRepo( testRepoId );
|
||||||
|
|
||||||
|
SearchService searchService = getSearchService( authorizationHeader );
|
||||||
|
|
||||||
|
SearchRequest searchRequest = new SearchRequest();
|
||||||
|
searchRequest.setBundleExportPackage( "org.apache.karaf.features.command.completers" );
|
||||||
|
|
||||||
|
List<Artifact> artifacts = searchService.searchArtifacts( searchRequest );
|
||||||
|
|
||||||
|
assertNotNull( artifacts );
|
||||||
|
assertTrue( " not 1 results for Bundle ExportPackage org.apache.karaf.features.command.completers but "
|
||||||
|
+ artifacts.size() + ":" + artifacts, artifacts.size() == 1 );
|
||||||
|
|
||||||
deleteTestRepo( testRepoId, targetRepo );
|
deleteTestRepo( testRepoId, targetRepo );
|
||||||
}
|
}
|
||||||
|
@ -188,19 +213,14 @@ public class SearchServiceTest
|
||||||
{
|
{
|
||||||
getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, true );
|
getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, true );
|
||||||
}
|
}
|
||||||
File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" );
|
File targetRepo = new File( "src/test/repo-with-osgi" );
|
||||||
cleanupFiles( targetRepo );
|
|
||||||
|
|
||||||
File sourceRepo = new File( "src/test/repo-with-osgi" );
|
|
||||||
|
|
||||||
FileUtils.copyDirectory( sourceRepo, targetRepo );
|
|
||||||
|
|
||||||
ManagedRepository managedRepository = new ManagedRepository();
|
ManagedRepository managedRepository = new ManagedRepository();
|
||||||
managedRepository.setId( testRepoId );
|
managedRepository.setId( testRepoId );
|
||||||
managedRepository.setName( "test repo" );
|
managedRepository.setName( "test repo" );
|
||||||
|
|
||||||
managedRepository.setLocation( targetRepo.getPath() );
|
managedRepository.setLocation( targetRepo.getPath() );
|
||||||
managedRepository.setIndexDirectory( targetRepo.getPath() + "/index-" + Long.toString( new Date().getTime() ) );
|
managedRepository.setIndexDirectory( "target/.index-" + Long.toString( new Date().getTime() ) );
|
||||||
|
|
||||||
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
|
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
|
||||||
service.addManagedRepository( managedRepository );
|
service.addManagedRepository( managedRepository );
|
||||||
|
@ -215,38 +235,11 @@ public class SearchServiceTest
|
||||||
{
|
{
|
||||||
if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( id ) != null )
|
if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( id ) != null )
|
||||||
{
|
{
|
||||||
getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( id, true );
|
getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( id, false );
|
||||||
}
|
}
|
||||||
cleanupFiles( targetRepo );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanupFiles( File targetRepo )
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
File indexerDir = new File( targetRepo, ".indexer" );
|
|
||||||
|
|
||||||
if ( targetRepo.exists() )
|
|
||||||
{
|
|
||||||
FileUtils.deleteDirectory( targetRepo );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( indexerDir.exists() )
|
|
||||||
{
|
|
||||||
FileUtils.deleteDirectory( indexerDir );
|
|
||||||
}
|
|
||||||
|
|
||||||
File lockFile = new File( indexerDir, "write.lock" );
|
|
||||||
if ( lockFile.exists() )
|
|
||||||
{
|
|
||||||
FileUtils.forceDelete( lockFile );
|
|
||||||
}
|
|
||||||
|
|
||||||
assertFalse( targetRepo.exists() );
|
|
||||||
assertFalse( indexerDir.exists() );
|
|
||||||
assertFalse( lockFile.exists() );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue