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
This commit is contained in:
Olivier Lamy 2011-11-03 15:19:21 +00:00
parent d3fe5410c7
commit 44885020d8
2 changed files with 34 additions and 32 deletions

View File

@ -87,8 +87,9 @@ public class NexusIndexerConsumer
@Inject @Inject
public NexusIndexerConsumer( public NexusIndexerConsumer(
@Named( value = "archivaTaskScheduler#indexing" ) ArchivaTaskScheduler<ArtifactIndexingTask> scheduler, @Named( value = "archivaTaskScheduler#indexing" ) ArchivaTaskScheduler<ArtifactIndexingTask> scheduler,
@Named(value = "archivaConfiguration") ArchivaConfiguration configuration, FileTypes filetypes, PlexusSisuBridge plexusSisuBridge, @Named( value = "archivaConfiguration" ) ArchivaConfiguration configuration, FileTypes filetypes,
MavenIndexerUtils mavenIndexerUtils, ManagedRepositoryAdmin managedRepositoryAdmin ) PlexusSisuBridge plexusSisuBridge, MavenIndexerUtils mavenIndexerUtils,
ManagedRepositoryAdmin managedRepositoryAdmin )
throws PlexusSisuBridgeException throws PlexusSisuBridgeException
{ {
this.configuration = configuration; this.configuration = configuration;

View File

@ -53,7 +53,7 @@ public class SearchServiceTest
assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
} }
File targetRepo = createAndIndexRepo( testRepoId ); createAndIndexRepo( testRepoId );
SearchService searchService = getSearchService( authorizationHeader ); SearchService searchService = getSearchService( authorizationHeader );
@ -68,7 +68,7 @@ public class SearchServiceTest
artifacts.size() == 6 ); artifacts.size() == 6 );
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts ); log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
deleteTestRepo( testRepoId, targetRepo ); deleteTestRepo( testRepoId );
} }
@Test @Test
@ -83,7 +83,7 @@ public class SearchServiceTest
assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
} }
File targetRepo = createAndIndexRepo( testRepoId ); createAndIndexRepo( testRepoId );
// START SNIPPET: searchservice-artifact-versions // START SNIPPET: searchservice-artifact-versions
SearchService searchService = getSearchService( authorizationHeader ); SearchService searchService = getSearchService( authorizationHeader );
@ -97,7 +97,7 @@ public class SearchServiceTest
artifacts.size() == 13 ); artifacts.size() == 13 );
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts ); log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
deleteTestRepo( testRepoId, targetRepo ); deleteTestRepo( testRepoId );
} }
@Test @Test
@ -112,7 +112,7 @@ public class SearchServiceTest
assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
} }
File targetRepo = createAndIndexRepo( testRepoId ); createAndIndexRepo( testRepoId );
SearchService searchService = getSearchService( authorizationHeader ); SearchService searchService = getSearchService( authorizationHeader );
@ -130,7 +130,7 @@ public class SearchServiceTest
artifacts.size() == 2 ); artifacts.size() == 2 );
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts ); log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
deleteTestRepo( testRepoId, targetRepo ); deleteTestRepo( testRepoId );
} }
@Test @Test
@ -145,7 +145,7 @@ public class SearchServiceTest
assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
} }
File targetRepo = createAndIndexRepo( testRepoId ); createAndIndexRepo( testRepoId );
SearchService searchService = getSearchService( authorizationHeader ); 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() + ":" " not 1 results for Bundle Symbolic Name org.apache.karaf.features.command but " + artifacts.size() + ":"
+ artifacts, artifacts.size() == 1 ); + artifacts, artifacts.size() == 1 );
deleteTestRepo( testRepoId, targetRepo ); deleteTestRepo( testRepoId );
} }
@Test @Test
@ -176,7 +176,7 @@ public class SearchServiceTest
assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
} }
File targetRepo = createAndIndexRepo( testRepoId ); createAndIndexRepo( testRepoId );
SearchService searchService = getSearchService( authorizationHeader ); 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() + ":" " not 2 results for Bundle Symbolic Name org.apache.karaf.features.core but " + artifacts.size() + ":"
+ artifacts, artifacts.size() == 2 ); + artifacts, artifacts.size() == 2 );
deleteTestRepo( testRepoId, targetRepo ); deleteTestRepo( testRepoId );
} }
@Test @Test
@ -205,7 +205,7 @@ public class SearchServiceTest
assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
} }
File targetRepo = createAndIndexRepo( testRepoId ); createAndIndexRepo( testRepoId );
SearchService searchService = getSearchService( authorizationHeader ); 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 " assertTrue( " not 1 results for Bundle ExportPackage org.apache.karaf.features.command.completers but "
+ artifacts.size() + ":" + artifacts, artifacts.size() == 1 ); + artifacts.size() + ":" + artifacts, artifacts.size() == 1 );
log.info( "artifcat url " + artifacts.get( 0 ).getUrl() ); log.info( "artifact url " + artifacts.get( 0 ).getUrl() );
deleteTestRepo( testRepoId, targetRepo ); deleteTestRepo( testRepoId );
} }
@Test @Test
@ -234,51 +234,52 @@ public class SearchServiceTest
assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
} }
File targetRepo = createAndIndexRepo( testRepoId ); createAndIndexRepo( testRepoId );
SearchService searchService = getSearchService( authorizationHeader ); SearchService searchService = getSearchService( authorizationHeader );
Collection<String> groupIds = searchService.getAllGroupIds( Arrays.asList( testRepoId ) ).getGroupIds(); Collection<String> groupIds = searchService.getAllGroupIds( Arrays.asList( testRepoId ) ).getGroupIds();
log.info( "groupIds " + groupIds ); log.info( "groupIds " + groupIds );
assertFalse( groupIds.isEmpty() ); assertFalse( groupIds.isEmpty() );
assertTrue( groupIds.contains( "commons-cli") ); assertTrue( groupIds.contains( "commons-cli" ) );
assertTrue( groupIds.contains( "org.apache.felix" ) ); assertTrue( groupIds.contains( "org.apache.felix" ) );
deleteTestRepo( testRepoId, targetRepo ); deleteTestRepo( testRepoId );
} }
private File createAndIndexRepo( String testRepoId ) private void createAndIndexRepo( String testRepoId )
throws Exception throws Exception
{ {
if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( testRepoId ) != null ) if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( testRepoId ) != null )
{ {
getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, true ); getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, false );
} }
File targetRepo = new File( "target/test-origin-repo" ); //File targetRepo = new File( "target/test-origin-repo" );
if ( targetRepo.exists() ) //if ( targetRepo.exists() )
{ //{
FileUtils.deleteDirectory( targetRepo ); // FileUtils.deleteDirectory( targetRepo );
} //}
assertFalse( targetRepo.exists() ); //assertFalse( targetRepo.exists() );
FileUtils.copyDirectory( new File( "src/test/repo-with-osgi" ), targetRepo ); //FileUtils.copyDirectory( new File( "src/test/repo-with-osgi" ), 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( new File( "src/test/repo-with-osgi" ).getPath() );
managedRepository.setIndexDirectory( "target/.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 );
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 throws Exception
{ {
if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( id ) != null ) if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( id ) != null )