]> source.dussan.org Git - archiva.git/commitdiff
fix index optimize default index location
authorOlivier Lamy <olamy@apache.org>
Thu, 15 Sep 2011 10:44:52 +0000 (10:44 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 15 Sep 2011 10:44:52 +0000 (10:44 +0000)
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

archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java

index e3654714210f473e5afd946f92057bd97b238ac7..267796f08dacc4c06b243be6040ddbdabfeccbe4 100644 (file)
@@ -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.PlexusSisuBridge;
 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
+import org.apache.commons.lang.StringUtils;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
-import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.index.ArtifactContext;
 import org.apache.maven.index.ArtifactContextProducer;
 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
  * 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.
- *
  */
 @Service( "taskExecutor#indexing" )
 public class ArchivaIndexingTaskExecutor
@@ -239,9 +238,11 @@ public class ArchivaIndexingTaskExecutor
 
             context.optimize();
 
-
             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 );
             indexPacker.packIndex( request );
 
index 86e164ab9dc8694ed47038f81b38191622971857..e3e34749142c3b56d5a9a91f54e7538806aea473 100644 (file)
@@ -253,7 +253,7 @@ public class ArchivaIndexingTaskExecutorTest
                Occur.SHOULD );
 
         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() );
 
@@ -286,11 +286,10 @@ public class ArchivaIndexingTaskExecutorTest
         indexingExecutor.executeTask( task );
 
         assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
-        assertTrue( new File( repositoryConfig.getLocation(), ".index" ).exists() );
 
         // unpack .zip index
-        File destDir = new File( repositoryConfig.getLocation(), ".index/tmp" );
-        unzipIndex( new File( repositoryConfig.getLocation(), ".index" ).getPath(), destDir.getPath() );
+        File destDir = new File( repositoryConfig.getLocation(), ".indexer/tmp" );
+        unzipIndex( new File( repositoryConfig.getLocation(), ".indexer" ).getPath(), destDir.getPath() );
 
         BooleanQuery q = new BooleanQuery();
         q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
index bc7122715156075390f4ec4d02b87a772072dda8..908e8b66ef556a4128cb6aa56756e6b9896b2ebc 100644 (file)
           <systemPropertyVariables>
             <plexus.home>${project.build.outputDirectory}</plexus.home>
             <appserver.base>${basedir}/target/appserver-base</appserver.base>
-            <targetDir>${basedir}/target/</targetDir>
           </systemPropertyVariables>
         </configuration>
       </plugin>
index f04cd335ebbbdd564d0f276370b023a03e92b30e..0e9f5aaa2bc7ad3b75763c0d72e937dd76c293e7 100644 (file)
@@ -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.services.ManagedRepositoriesService;
 import org.apache.archiva.rest.api.services.SearchService;
-import org.apache.commons.io.FileUtils;
 import org.junit.Test;
 
 import java.io.File;
@@ -146,7 +145,6 @@ public class SearchServiceTest
         assertTrue(
             " not 1 results for Bundle Symbolic Name org.apache.karaf.features.command but " + artifacts.size() + ":"
                 + artifacts, artifacts.size() == 1 );
-        log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
 
         deleteTestRepo( testRepoId, targetRepo );
     }
@@ -176,7 +174,34 @@ public class SearchServiceTest
         assertTrue(
             " not 2 results for Bundle Symbolic Name org.apache.karaf.features.core but " + artifacts.size() + ":"
                 + 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 );
     }
@@ -188,19 +213,14 @@ public class SearchServiceTest
         {
             getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, true );
         }
-        File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" );
-        cleanupFiles( targetRepo );
-
-        File sourceRepo = new File( "src/test/repo-with-osgi" );
-
-        FileUtils.copyDirectory( sourceRepo, targetRepo );
+        File targetRepo = new File( "src/test/repo-with-osgi" );
 
         ManagedRepository managedRepository = new ManagedRepository();
         managedRepository.setId( testRepoId );
         managedRepository.setName( "test repo" );
 
         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 );
         service.addManagedRepository( managedRepository );
@@ -215,38 +235,11 @@ public class SearchServiceTest
     {
         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() );
-    }
 
 }