diff options
author | Brett Porter <brett@apache.org> | 2009-12-07 23:27:58 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2009-12-07 23:27:58 +0000 |
commit | 1dad23aaf3d3a6fa10876a2363169b76b52608b9 (patch) | |
tree | 8da4c014f06efa774e23c1404f8e3b0dde65a2a5 /archiva-modules/plugins/repository-statistics | |
parent | 7c7fffc71c4c2546c8e5aacb933bea9fd1c8ffa7 (diff) | |
download | archiva-1dad23aaf3d3a6fa10876a2363169b76b52608b9.tar.gz archiva-1dad23aaf3d3a6fa10876a2363169b76b52608b9.zip |
[MRM-1293] adjust the EditManagedRepositoryAction to delete statistics when the repository location changes.
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@888185 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/plugins/repository-statistics')
3 files changed, 84 insertions, 11 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 5289b6438..65b9c2f1b 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 @@ -73,6 +73,11 @@ public class DefaultRepositoryStatisticsManager repositoryStatistics ); } + public void deleteStatistics( String repositoryId ) + { + metadataRepository.removeMetadataFacets( repositoryId, RepositoryStatistics.FACET_ID ); + } + public void setMetadataRepository( MetadataRepository metadataRepository ) { this.metadataRepository = metadataRepository; 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 15ba27802..24b9135ed 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 @@ -24,4 +24,6 @@ public interface RepositoryStatisticsManager RepositoryStatistics getLastStatistics( String repositoryId ); void addStatisticsAfterScan( String repositoryId, RepositoryStatistics repositoryStatistics ); + + void deleteStatistics( String repositoryId ); } 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 0dbda2eb5..8cff40848 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 @@ -113,24 +113,17 @@ public class RepositoryStatisticsManagerTest Date current = new Date(); Date startTime = new Date( current.getTime() - 12345 ); - RepositoryStatistics stats = new RepositoryStatistics(); - stats.setScanStartTime( startTime ); - stats.setScanEndTime( current ); - stats.setTotalArtifactFileSize( 1400032000L ); - stats.setNewFileCount( 45 ); - stats.setTotalArtifactCount( 10412 ); - stats.setTotalProjectCount( 2036 ); - stats.setTotalGroupCount( 531 ); - stats.setTotalFileCount( 56345 ); + RepositoryStatistics stats1 = createTestStats( startTime, current ); String startTimeAsString = DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( startTime ); - metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString, stats ); + metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString, stats1 ); metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), Arrays.asList( startTimeAsString ) ); metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString ), - stats ); + stats1 ); + RepositoryStatistics stats = stats1; metadataRepositoryControl.replay(); @@ -149,4 +142,77 @@ public class RepositoryStatisticsManagerTest metadataRepositoryControl.verify(); } + + public void testDeleteStats() + { + Date current = new Date(); + + Date startTime1 = new Date( current.getTime() - 12345 ); + RepositoryStatistics stats1 = createTestStats( startTime1, new Date( current.getTime() - 6000 ) ); + String startTimeAsString1 = DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( startTime1 ); + metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString1, stats1 ); + + Date startTime2 = new Date( current.getTime() - 3000 ); + RepositoryStatistics stats2 = createTestStats( startTime2, current ); + String startTimeAsString2 = DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( startTime2 ); + metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString2, stats2 ); + + metadataRepositoryControl.expectAndReturn( + metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), + Arrays.asList( startTimeAsString1, startTimeAsString2 ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString2 ), + stats2 ); + + metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ); + + metadataRepositoryControl.expectAndReturn( + metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), + Collections.emptyList() ); + + metadataRepositoryControl.replay(); + + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats1 ); + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats2 ); + + assertNotNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) ); + + repositoryStatisticsManager.deleteStatistics( TEST_REPO_ID ); + + assertNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) ); + + metadataRepositoryControl.verify(); + } + + public void testDeleteStatsWhenEmpty() + { + metadataRepositoryControl.expectAndReturn( + metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), + Collections.emptyList(), 2 ); + metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ); + + metadataRepositoryControl.replay(); + + assertNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) ); + + repositoryStatisticsManager.deleteStatistics( TEST_REPO_ID ); + + assertNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) ); + + metadataRepositoryControl.verify(); + } + + private RepositoryStatistics createTestStats( Date startTime, Date endTime ) + { + RepositoryStatistics stats = new RepositoryStatistics(); + stats.setScanStartTime( startTime ); + stats.setScanEndTime( endTime ); + stats.setTotalArtifactFileSize( 1400032000L ); + stats.setNewFileCount( 45 ); + stats.setTotalArtifactCount( 10412 ); + stats.setTotalProjectCount( 2036 ); + stats.setTotalGroupCount( 531 ); + stats.setTotalFileCount( 56345 ); + return stats; + } } |