diff options
author | Olivier Lamy <olamy@apache.org> | 2012-12-19 15:19:53 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-12-19 15:19:53 +0000 |
commit | 58afcb111487f09821d20ce25015352ee5140b65 (patch) | |
tree | f0cfeabeff964ca1b7cc6cdac092288c749e57c4 /archiva-modules/metadata | |
parent | 31438032029fe54269ae1b349d40f49d8c73c5d3 (diff) | |
download | archiva-58afcb111487f09821d20ce25015352ee5140b65.tar.gz archiva-58afcb111487f09821d20ce25015352ee5140b65.zip |
[MRM-1729] add MetadataRepository#hasMetadataFacet to prevent slow startup time.
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1423878 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/metadata')
2 files changed, 108 insertions, 2 deletions
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index 50e6e6300..4089300c7 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -54,6 +54,17 @@ public interface MetadataRepository List<String> getMetadataFacets( String repositoryId, String facetId ) throws MetadataRepositoryException; + /** + * + * @param repositoryId + * @param facetId + * @return true if the repository datas for this facetId + * @since 1.4-M4 + * @throws MetadataRepositoryException + */ + boolean hasMetadataFacet( String repositoryId, String facetId ) + throws MetadataRepositoryException; + MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name ) throws MetadataRepositoryException; diff --git a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java index d7152b864..285548d4e 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java +++ b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java @@ -40,8 +40,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.test.context.ContextConfiguration; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -49,9 +51,10 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TimeZone; -@RunWith (ArchivaSpringJUnit4ClassRunner.class) -@ContextConfiguration (locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" }) +@RunWith( ArchivaSpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } ) public abstract class AbstractMetadataRepositoryTest extends TestCase { @@ -704,6 +707,52 @@ public abstract class AbstractMetadataRepositoryTest } @Test + public void hasMetadataFacetStart() + throws Exception + { + assertFalse( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) ); + + } + + @Test + public void hasMetadataFacet() + throws Exception + { + + assertFalse( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) ); + + Calendar cal = Calendar.getInstance(); + + repository.addMetadataFacet( TEST_REPO_ID, new KindOfRepositoryStatistics( "first", cal.getTime() ) ); + + assertTrue( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) ); + + cal.add( Calendar.MINUTE, 2 ); + + repository.addMetadataFacet( TEST_REPO_ID, new KindOfRepositoryStatistics( "second", cal.getTime() ) ); + + cal.add( Calendar.MINUTE, 2 ); + + repository.addMetadataFacet( TEST_REPO_ID, new KindOfRepositoryStatistics( "third", cal.getTime() ) ); + + List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ); + + Assertions.assertThat( facets ).isNotNull().isNotEmpty().hasSize( 3 ); + + assertTrue( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) ); + + repository.removeMetadataFacets( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ); + + assertFalse( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) ); + + facets = repository.getMetadataFacets( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ); + + Assertions.assertThat( facets ).isNotNull().isEmpty(); + + } + + + @Test public void testGetArtifacts() throws Exception { @@ -1231,6 +1280,7 @@ public abstract class AbstractMetadataRepositoryTest Assertions.assertThat( artifactMetadatas ).isNotNull().isEmpty(); } + private static ProjectMetadata createProject() { return createProject( TEST_NAMESPACE ); @@ -1274,6 +1324,51 @@ public abstract class AbstractMetadataRepositoryTest } } + private static class KindOfRepositoryStatistics + implements MetadataFacet + { + private String value; + + private Date date; + + static final String SCAN_TIMESTAMP_FORMAT = "yyyy/MM/dd/HHmmss.SSS"; + + private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" ); + + private KindOfRepositoryStatistics( String value, Date date ) + { + this.value = value; + this.date = date; + } + + public String getName() + { + return createNameFormat().format( date ); + } + + private static SimpleDateFormat createNameFormat() + { + SimpleDateFormat fmt = new SimpleDateFormat( SCAN_TIMESTAMP_FORMAT ); + fmt.setTimeZone( UTC_TIME_ZONE ); + return fmt; + } + + public String getFacetId() + { + return KindOfRepositoryStatistics.class.getName(); + } + + public Map<String, String> toProperties() + { + return Collections.emptyMap(); + } + + public void fromProperties( Map<String, String> properties ) + { + // no op + } + } + private static class TestMetadataFacet implements MetadataFacet { |