diff options
author | Brett Porter <brett@apache.org> | 2010-12-22 01:53:10 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2010-12-22 01:53:10 +0000 |
commit | badcc9e925b9351d2e1d2b198d082245960ee40a (patch) | |
tree | 5ef3f8a7ad494d5560b25fe1ad8ce9bb0dcfd410 /archiva-modules/plugins/repository-statistics | |
parent | 1ff88d24fe6665e01b57eff1e9db76216e942354 (diff) | |
download | archiva-badcc9e925b9351d2e1d2b198d082245960ee40a.tar.gz archiva-badcc9e925b9351d2e1d2b198d082245960ee40a.zip |
[MRM-1327] add exception handling to the metadata repository implementation
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1051732 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/plugins/repository-statistics')
3 files changed, 243 insertions, 162 deletions
diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java index 7f2466470..876ff19bc 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java @@ -21,6 +21,8 @@ package org.apache.archiva.metadata.repository.stats; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; +import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,6 +52,7 @@ public class DefaultRepositoryStatisticsManager private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" ); public RepositoryStatistics getLastStatistics( String repositoryId ) + throws MetadataRepositoryException { // TODO: consider a more efficient implementation that directly gets the last one from the content repository List<String> scans = metadataRepository.getMetadataFacets( repositoryId, RepositoryStatistics.FACET_ID ); @@ -67,6 +70,7 @@ public class DefaultRepositoryStatisticsManager } private void walkRepository( RepositoryStatistics stats, String repositoryId, String ns ) + throws MetadataResolutionException { for ( String namespace : metadataRepository.getNamespaces( repositoryId, ns ) ) { @@ -89,7 +93,8 @@ public class DefaultRepositoryStatisticsManager stats.setTotalArtifactCount( stats.getTotalArtifactCount() + 1 ); stats.setTotalArtifactFileSize( stats.getTotalArtifactFileSize() + artifact.getSize() ); - MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet( MavenArtifactFacet.FACET_ID ); + MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet( + MavenArtifactFacet.FACET_ID ); if ( facet != null ) { String type = facet.getType(); @@ -104,6 +109,7 @@ public class DefaultRepositoryStatisticsManager public void addStatisticsAfterScan( String repositoryId, Date startTime, Date endTime, long totalFiles, long newFiles ) + throws MetadataRepositoryException { RepositoryStatistics repositoryStatistics = new RepositoryStatistics(); repositoryStatistics.setScanStartTime( startTime ); @@ -121,9 +127,16 @@ public class DefaultRepositoryStatisticsManager // TODO: we can probably get a more efficient implementation directly from the metadata repository, but for now // we just walk it. Alternatively, we could build an index, or store the aggregate information and update // it on the fly - for ( String ns : metadataRepository.getRootNamespaces( repositoryId ) ) + try { - walkRepository( repositoryStatistics, repositoryId, ns ); + for ( String ns : metadataRepository.getRootNamespaces( repositoryId ) ) + { + walkRepository( repositoryStatistics, repositoryId, ns ); + } + } + catch ( MetadataResolutionException e ) + { + throw new MetadataRepositoryException( e.getMessage(), e ); } log.info( "Repository walk for statistics executed in " + ( System.currentTimeMillis() - startWalk ) + "ms" ); @@ -131,11 +144,13 @@ public class DefaultRepositoryStatisticsManager } public void deleteStatistics( String repositoryId ) + throws MetadataRepositoryException { metadataRepository.removeMetadataFacets( repositoryId, RepositoryStatistics.FACET_ID ); } public List<RepositoryStatistics> getStatisticsInRange( String repositoryId, Date startTime, Date endTime ) + throws MetadataRepositoryException { List<RepositoryStatistics> results = new ArrayList<RepositoryStatistics>(); List<String> list = metadataRepository.getMetadataFacets( repositoryId, RepositoryStatistics.FACET_ID ); @@ -145,13 +160,11 @@ public class DefaultRepositoryStatisticsManager try { Date date = createNameFormat().parse( name ); - if ( ( startTime == null || !date.before( startTime ) ) && - ( endTime == null || !date.after( endTime ) ) ) + if ( ( startTime == null || !date.before( startTime ) ) && ( endTime == null || !date.after( + endTime ) ) ) { - RepositoryStatistics stats = - (RepositoryStatistics) metadataRepository.getMetadataFacet( repositoryId, - RepositoryStatistics.FACET_ID, - name ); + RepositoryStatistics stats = (RepositoryStatistics) metadataRepository.getMetadataFacet( + repositoryId, RepositoryStatistics.FACET_ID, name ); results.add( stats ); } } diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java index 6abc44348..69fed9f65 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java @@ -19,16 +19,22 @@ package org.apache.archiva.metadata.repository.stats; * under the License. */ +import org.apache.archiva.metadata.repository.MetadataRepositoryException; + import java.util.Date; import java.util.List; public interface RepositoryStatisticsManager { - RepositoryStatistics getLastStatistics( String repositoryId ); + RepositoryStatistics getLastStatistics( String repositoryId ) + throws MetadataRepositoryException; - void addStatisticsAfterScan( String repositoryId, Date startTime, Date endTime, long totalFiles, long newFiles ); + void addStatisticsAfterScan( String repositoryId, Date startTime, Date endTime, long totalFiles, long newFiles ) + throws MetadataRepositoryException; - void deleteStatistics( String repositoryId ); + void deleteStatistics( String repositoryId ) + throws MetadataRepositoryException; - List<RepositoryStatistics> getStatisticsInRange( String repositoryId, Date startTime, Date endTime ); + List<RepositoryStatistics> getStatisticsInRange( String repositoryId, Date startTime, Date endTime ) + throws MetadataRepositoryException; } diff --git a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java index 5603c5d38..9757ca910 100644 --- a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java +++ b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java @@ -25,7 +25,6 @@ import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.easymock.MockControl; -import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -76,7 +75,7 @@ public class RepositoryStatisticsManagerTest } public void testGetLatestStats() - throws ParseException + throws Exception { Date startTime = TIMESTAMP_FORMAT.parse( SECOND_TEST_SCAN ); Date endTime = new Date( startTime.getTime() + 60000 ); @@ -91,12 +90,12 @@ public class RepositoryStatisticsManagerTest stats.setTotalGroupCount( 529 ); stats.setTotalFileCount( 56229 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), - Arrays.asList( FIRST_TEST_SCAN, SECOND_TEST_SCAN ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, SECOND_TEST_SCAN ), - stats ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + Arrays.asList( FIRST_TEST_SCAN, SECOND_TEST_SCAN ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + SECOND_TEST_SCAN ), stats ); metadataRepositoryControl.replay(); stats = repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ); @@ -115,10 +114,11 @@ public class RepositoryStatisticsManagerTest } public void testGetLatestStatsWhenEmpty() + throws Exception { - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), - Collections.emptyList() ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + Collections.emptyList() ); metadataRepositoryControl.replay(); RepositoryStatistics stats = repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ); @@ -128,6 +128,8 @@ public class RepositoryStatisticsManagerTest } public void testAddNewStats() + throws Exception + { Date current = new Date(); Date startTime = new Date( current.getTime() - 12345 ); @@ -137,12 +139,12 @@ public class RepositoryStatisticsManagerTest walkRepository( 1 ); metadataRepository.addMetadataFacet( TEST_REPO_ID, stats ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), - Arrays.asList( stats.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats.getName() ), - stats ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + Arrays.asList( stats.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + stats.getName() ), stats ); metadataRepositoryControl.replay(); @@ -163,6 +165,8 @@ public class RepositoryStatisticsManagerTest } public void testDeleteStats() + throws Exception + { walkRepository( 2 ); @@ -176,18 +180,18 @@ public class RepositoryStatisticsManagerTest RepositoryStatistics stats2 = createTestStats( startTime2, current ); metadataRepository.addMetadataFacet( TEST_REPO_ID, stats2 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), - Arrays.asList( stats1.getName(), stats2.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats2.getName() ), - stats2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + Arrays.asList( stats1.getName(), stats2.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + stats2.getName() ), stats2 ); metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), - Collections.emptyList() ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + Collections.emptyList() ); metadataRepositoryControl.replay(); @@ -206,10 +210,12 @@ public class RepositoryStatisticsManagerTest } public void testDeleteStatsWhenEmpty() + throws Exception + { - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), - Collections.emptyList(), 2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + Collections.emptyList(), 2 ); metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ); metadataRepositoryControl.replay(); @@ -224,6 +230,8 @@ public class RepositoryStatisticsManagerTest } public void testGetStatsRangeInside() + throws Exception + { walkRepository( 3 ); @@ -234,14 +242,16 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + keys ); // only match the middle one String key = keys.get( 1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); metadataRepositoryControl.replay(); @@ -251,9 +261,8 @@ public class RepositoryStatisticsManagerTest stats.getScanEndTime(), 56345, 45 ); } - List<RepositoryStatistics> list = - repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 4000 ), - new Date( current.getTime() - 2000 ) ); + List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( + current.getTime() - 4000 ), new Date( current.getTime() - 2000 ) ); assertEquals( 1, list.size() ); assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() ); @@ -262,6 +271,8 @@ public class RepositoryStatisticsManagerTest } public void testGetStatsRangeUpperOutside() + throws Exception + { walkRepository( 3 ); @@ -272,17 +283,20 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + keys ); String key = keys.get( 1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); key = keys.get( 2 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); metadataRepositoryControl.replay(); @@ -292,9 +306,8 @@ public class RepositoryStatisticsManagerTest stats.getScanEndTime(), 56345, 45 ); } - List<RepositoryStatistics> list = - repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 4000 ), - current ); + List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( + current.getTime() - 4000 ), current ); assertEquals( 2, list.size() ); assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() ); @@ -304,6 +317,8 @@ public class RepositoryStatisticsManagerTest } public void testGetStatsRangeLowerOutside() + throws Exception + { walkRepository( 3 ); @@ -314,17 +329,20 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + keys ); String key = keys.get( 0 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); key = keys.get( 1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); metadataRepositoryControl.replay(); @@ -334,9 +352,8 @@ public class RepositoryStatisticsManagerTest stats.getScanEndTime(), 56345, 45 ); } - List<RepositoryStatistics> list = - repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 20000 ), - new Date( current.getTime() - 2000 ) ); + List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( + current.getTime() - 20000 ), new Date( current.getTime() - 2000 ) ); assertEquals( 2, list.size() ); assertEquals( new Date( current.getTime() - 12345 ), list.get( 1 ).getScanStartTime() ); @@ -346,6 +363,8 @@ public class RepositoryStatisticsManagerTest } public void testGetStatsRangeLowerAndUpperOutside() + throws Exception + { walkRepository( 3 ); @@ -356,21 +375,25 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + keys ); String key = keys.get( 0 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); key = keys.get( 1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); key = keys.get( 2 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); metadataRepositoryControl.replay(); @@ -380,9 +403,8 @@ public class RepositoryStatisticsManagerTest stats.getScanEndTime(), 56345, 45 ); } - List<RepositoryStatistics> list = - repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 20000 ), - current ); + List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( + current.getTime() - 20000 ), current ); assertEquals( 3, list.size() ); assertEquals( new Date( current.getTime() - 12345 ), list.get( 2 ).getScanStartTime() ); @@ -393,6 +415,8 @@ public class RepositoryStatisticsManagerTest } public void testGetStatsRangeNotInside() + throws Exception + { walkRepository( 3 ); @@ -403,8 +427,9 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + keys ); metadataRepositoryControl.replay(); @@ -414,9 +439,8 @@ public class RepositoryStatisticsManagerTest stats.getScanEndTime(), 56345, 45 ); } - List<RepositoryStatistics> list = - repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 20000 ), - new Date( current.getTime() - 16000 ) ); + List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( + current.getTime() - 20000 ), new Date( current.getTime() - 16000 ) ); assertEquals( 0, list.size() ); @@ -424,6 +448,8 @@ public class RepositoryStatisticsManagerTest } private void addStats( Date startTime, Date endTime ) + throws Exception + { RepositoryStatistics stats = createTestStats( startTime, endTime ); metadataRepository.addMetadataFacet( TEST_REPO_ID, stats ); @@ -465,6 +491,7 @@ public class RepositoryStatisticsManagerTest } private void walkRepository( int count ) + throws Exception { for ( int i = 0; i < count; i++ ) { @@ -478,89 +505,124 @@ public class RepositoryStatisticsManagerTest Arrays.asList() ); metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "com.example" ), Arrays.asList( "example-project" ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getProjectVersions( TEST_REPO_ID, "com.example", "example-project" ), - Arrays.asList( "1.0", "1.1" ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", "example-project", "1.0" ), - Arrays.asList( createArtifact( "com.example", "example-project", "1.0", "jar" ), - createArtifact( "com.example", "example-project", "1.0", "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", "example-project", "1.1" ), - Arrays.asList( createArtifact( "com.example", "example-project", "1.1", "jar" ), - createArtifact( "com.example", "example-project", "1.1", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO_ID, + "com.example", + "example-project" ), + Arrays.asList( "1.0", "1.1" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", + "example-project", "1.0" ), + Arrays.asList( createArtifact( "com.example", "example-project", + "1.0", "jar" ), createArtifact( + "com.example", "example-project", "1.0", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", + "example-project", "1.1" ), + Arrays.asList( createArtifact( "com.example", "example-project", + "1.1", "jar" ), createArtifact( + "com.example", "example-project", "1.1", "pom" ) ) ); metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org" ), Arrays.asList( "apache", "codehaus" ) ); metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache" ), Arrays.asList( "archiva", "maven" ) ); metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org.apache" ), Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache.archiva" ), Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getProjects( TEST_REPO_ID, "org.apache.archiva" ), - Arrays.asList( "metadata-repository-api", "metadata-model" ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api" ), - Arrays.asList( "1.3-SNAPSHOT", "1.3" ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", - "1.3-SNAPSHOT" ), - Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "jar" ), - createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", - "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3" ), - Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ), - createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "metadata-model" ), - Arrays.asList( "1.3-SNAPSHOT", "1.3" ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT" ), - Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "jar" ), - createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3" ), - Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3", "jar" ), - createArtifact( "org.apache.archiva", "metadata-model", "1.3", "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache.maven" ), Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getProjects( TEST_REPO_ID, "org.apache.maven" ), Arrays.asList( "maven-model" ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.maven", "maven-model" ), - Arrays.asList( "2.2.1" ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.maven", "maven-model", "2.2.1" ), - Arrays.asList( createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "jar" ), - createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, + "org.apache.archiva" ), + Arrays.asList() ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, + "org.apache.archiva" ), + Arrays.asList( "metadata-repository-api", "metadata-model" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO_ID, + "org.apache.archiva", + "metadata-repository-api" ), + Arrays.asList( "1.3-SNAPSHOT", "1.3" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, + "org.apache.archiva", + "metadata-repository-api", + "1.3-SNAPSHOT" ), Arrays.asList( + createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "jar" ), + createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, + "org.apache.archiva", + "metadata-repository-api", + "1.3" ), Arrays.asList( + createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ), createArtifact( + "org.apache.archiva", "metadata-repository-api", "1.3", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO_ID, + "org.apache.archiva", + "metadata-model" ), + Arrays.asList( "1.3-SNAPSHOT", "1.3" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, + "org.apache.archiva", + "metadata-model", + "1.3-SNAPSHOT" ), Arrays.asList( + createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "jar" ), createArtifact( + "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, + "org.apache.archiva", + "metadata-model", "1.3" ), + Arrays.asList( createArtifact( "org.apache.archiva", + "metadata-model", "1.3", "jar" ), + createArtifact( "org.apache.archiva", + "metadata-model", "1.3", + "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, + "org.apache.maven" ), + Arrays.asList() ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, + "org.apache.maven" ), + Arrays.asList( "maven-model" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO_ID, + "org.apache.maven", + "maven-model" ), + Arrays.asList( "2.2.1" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, + "org.apache.maven", + "maven-model", "2.2.1" ), + Arrays.asList( createArtifact( "org.apache.archiva", + "maven-model", "2.2.1", "jar" ), + createArtifact( "org.apache.archiva", + "maven-model", "2.2.1", + "pom" ) ) ); metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus" ), Arrays.asList( "plexus" ) ); metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org" ), Arrays.asList() ); metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus" ), Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus.plexus" ), Arrays.asList() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus.plexus" ), - Arrays.asList( "plexus-spring" ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getProjectVersions( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring" ), - Arrays.asList( "1.0", "1.1", "1.2" ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.0" ), - Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "jar" ), - createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.1" ), - Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "jar" ), - createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "pom" ) ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2" ), - Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "jar" ), - createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, + "org.codehaus.plexus" ), + Arrays.asList() ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, + "org.codehaus.plexus" ), + Arrays.asList( "plexus-spring" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjectVersions( TEST_REPO_ID, + "org.codehaus.plexus", + "plexus-spring" ), + Arrays.asList( "1.0", "1.1", "1.2" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, + "org.codehaus.plexus", + "plexus-spring", "1.0" ), + Arrays.asList( createArtifact( "org.codehaus.plexus", + "plexus-spring", "1.0", "jar" ), + createArtifact( "org.codehaus.plexus", + "plexus-spring", "1.0", + "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, + "org.codehaus.plexus", + "plexus-spring", "1.1" ), + Arrays.asList( createArtifact( "org.codehaus.plexus", + "plexus-spring", "1.1", "jar" ), + createArtifact( "org.codehaus.plexus", + "plexus-spring", "1.1", + "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( TEST_REPO_ID, + "org.codehaus.plexus", + "plexus-spring", "1.2" ), + Arrays.asList( createArtifact( "org.codehaus.plexus", + "plexus-spring", "1.2", "jar" ), + createArtifact( "org.codehaus.plexus", + "plexus-spring", "1.2", + "pom" ) ) ); } } } |