From 44885020d874da2d4eb7b8d96780825d5c0bd521 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 3 Nov 2011 15:19:21 +0000 Subject: [PATCH] optimize io consume by not deleting/copying artifacts for all tests git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1197181 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/NexusIndexerConsumer.java | 5 +- .../rest/services/SearchServiceTest.java | 61 ++++++++++--------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java index 06d4cfd04..4b6f8ca37 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java @@ -87,8 +87,9 @@ public class NexusIndexerConsumer @Inject public NexusIndexerConsumer( @Named( value = "archivaTaskScheduler#indexing" ) ArchivaTaskScheduler scheduler, - @Named(value = "archivaConfiguration") ArchivaConfiguration configuration, FileTypes filetypes, PlexusSisuBridge plexusSisuBridge, - MavenIndexerUtils mavenIndexerUtils, ManagedRepositoryAdmin managedRepositoryAdmin ) + @Named( value = "archivaConfiguration" ) ArchivaConfiguration configuration, FileTypes filetypes, + PlexusSisuBridge plexusSisuBridge, MavenIndexerUtils mavenIndexerUtils, + ManagedRepositoryAdmin managedRepositoryAdmin ) throws PlexusSisuBridgeException { this.configuration = configuration; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java index c1e0fa464..91a1cc029 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java @@ -53,7 +53,7 @@ public class SearchServiceTest assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); } - File targetRepo = createAndIndexRepo( testRepoId ); + createAndIndexRepo( testRepoId ); SearchService searchService = getSearchService( authorizationHeader ); @@ -68,7 +68,7 @@ public class SearchServiceTest artifacts.size() == 6 ); log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts ); - deleteTestRepo( testRepoId, targetRepo ); + deleteTestRepo( testRepoId ); } @Test @@ -83,7 +83,7 @@ public class SearchServiceTest assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); } - File targetRepo = createAndIndexRepo( testRepoId ); + createAndIndexRepo( testRepoId ); // START SNIPPET: searchservice-artifact-versions SearchService searchService = getSearchService( authorizationHeader ); @@ -97,7 +97,7 @@ public class SearchServiceTest artifacts.size() == 13 ); log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts ); - deleteTestRepo( testRepoId, targetRepo ); + deleteTestRepo( testRepoId ); } @Test @@ -112,7 +112,7 @@ public class SearchServiceTest assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); } - File targetRepo = createAndIndexRepo( testRepoId ); + createAndIndexRepo( testRepoId ); SearchService searchService = getSearchService( authorizationHeader ); @@ -130,7 +130,7 @@ public class SearchServiceTest artifacts.size() == 2 ); log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts ); - deleteTestRepo( testRepoId, targetRepo ); + deleteTestRepo( testRepoId ); } @Test @@ -145,7 +145,7 @@ public class SearchServiceTest assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); } - File targetRepo = createAndIndexRepo( testRepoId ); + createAndIndexRepo( testRepoId ); SearchService searchService = getSearchService( authorizationHeader ); @@ -161,7 +161,7 @@ public class SearchServiceTest " not 1 results for Bundle Symbolic Name org.apache.karaf.features.command but " + artifacts.size() + ":" + artifacts, artifacts.size() == 1 ); - deleteTestRepo( testRepoId, targetRepo ); + deleteTestRepo( testRepoId ); } @Test @@ -176,7 +176,7 @@ public class SearchServiceTest assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); } - File targetRepo = createAndIndexRepo( testRepoId ); + createAndIndexRepo( testRepoId ); SearchService searchService = getSearchService( authorizationHeader ); @@ -190,7 +190,7 @@ public class SearchServiceTest " not 2 results for Bundle Symbolic Name org.apache.karaf.features.core but " + artifacts.size() + ":" + artifacts, artifacts.size() == 2 ); - deleteTestRepo( testRepoId, targetRepo ); + deleteTestRepo( testRepoId ); } @Test @@ -205,7 +205,7 @@ public class SearchServiceTest assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); } - File targetRepo = createAndIndexRepo( testRepoId ); + createAndIndexRepo( testRepoId ); SearchService searchService = getSearchService( authorizationHeader ); @@ -218,8 +218,8 @@ public class SearchServiceTest assertTrue( " not 1 results for Bundle ExportPackage org.apache.karaf.features.command.completers but " + artifacts.size() + ":" + artifacts, artifacts.size() == 1 ); - log.info( "artifcat url " + artifacts.get( 0 ).getUrl() ); - deleteTestRepo( testRepoId, targetRepo ); + log.info( "artifact url " + artifacts.get( 0 ).getUrl() ); + deleteTestRepo( testRepoId ); } @Test @@ -234,51 +234,52 @@ public class SearchServiceTest assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); } - File targetRepo = createAndIndexRepo( testRepoId ); + createAndIndexRepo( testRepoId ); SearchService searchService = getSearchService( authorizationHeader ); Collection groupIds = searchService.getAllGroupIds( Arrays.asList( testRepoId ) ).getGroupIds(); log.info( "groupIds " + groupIds ); assertFalse( groupIds.isEmpty() ); - assertTrue( groupIds.contains( "commons-cli") ); + assertTrue( groupIds.contains( "commons-cli" ) ); assertTrue( groupIds.contains( "org.apache.felix" ) ); - deleteTestRepo( testRepoId, targetRepo ); + deleteTestRepo( testRepoId ); } - private File createAndIndexRepo( String testRepoId ) + private void createAndIndexRepo( String testRepoId ) throws Exception { if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( testRepoId ) != null ) { - getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, true ); + getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, false ); } - File targetRepo = new File( "target/test-origin-repo" ); - if ( targetRepo.exists() ) - { - FileUtils.deleteDirectory( targetRepo ); - } - assertFalse( targetRepo.exists() ); - FileUtils.copyDirectory( new File( "src/test/repo-with-osgi" ), targetRepo ); + //File targetRepo = new File( "target/test-origin-repo" ); + //if ( targetRepo.exists() ) + //{ + // FileUtils.deleteDirectory( targetRepo ); + //} + //assertFalse( targetRepo.exists() ); + //FileUtils.copyDirectory( new File( "src/test/repo-with-osgi" ), targetRepo ); ManagedRepository managedRepository = new ManagedRepository(); managedRepository.setId( testRepoId ); managedRepository.setName( "test repo" ); - managedRepository.setLocation( targetRepo.getPath() ); + managedRepository.setLocation( new File( "src/test/repo-with-osgi" ).getPath() ); managedRepository.setIndexDirectory( "target/.index-" + Long.toString( new Date().getTime() ) ); ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader ); service.addManagedRepository( managedRepository ); - getRoleManagementService( authorizationHeader ).assignTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, testRepoId, "admin" ); + getRoleManagementService( authorizationHeader ).assignTemplatedRole( + ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, testRepoId, "admin" ); - getRepositoriesService(authorizationHeader).scanRepositoryNow( testRepoId, true ); + getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true ); - return targetRepo; + //return targetRepo; } - private void deleteTestRepo( String id, File targetRepo ) + private void deleteTestRepo( String id ) throws Exception { if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( id ) != null ) -- 2.39.5