[MRM-127] add a blackout on discovery to ensure indexer will work correctly in all sensible cases

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@425963 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2006-07-27 04:58:38 +00:00
parent 8da406db53
commit 071eb2dced
2 changed files with 55 additions and 3 deletions

View File

@ -61,6 +61,11 @@ public abstract class AbstractDiscoverer
private List excludedPaths = new ArrayList();
/**
* @plexus.configuration default-value="60000"
*/
private int blackoutPeriod;
protected static final String DATE_FMT = "yyyyMMddHHmmss";
/**
@ -122,9 +127,13 @@ public abstract class AbstractDiscoverer
{
String path = files.next().toString();
if ( comparisonTimestamp == 0 || new File( repositoryBase, path ).lastModified() > comparisonTimestamp )
long modTime = new File( repositoryBase, path ).lastModified();
if ( modTime < System.currentTimeMillis() - blackoutPeriod )
{
includedPaths.add( path );
if ( modTime > comparisonTimestamp )
{
includedPaths.add( path );
}
}
}

View File

@ -79,7 +79,10 @@ public abstract class AbstractArtifactDiscovererTest
protected Artifact createArtifact( String groupId, String artifactId, String version )
{
return factory.createArtifact( groupId, artifactId, version, null, "jar" );
Artifact artifact = factory.createArtifact( groupId, artifactId, version, null, "jar" );
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
artifact.setRepository( repository );
return artifact;
}
protected Artifact createArtifact( String groupId, String artifactId, String version, String type )
@ -146,6 +149,46 @@ public abstract class AbstractArtifactDiscovererTest
artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) );
}
public void testUpdatedInRepositoryBlackout()
throws ComponentLookupException, DiscovererException, IOException
{
discoverer.resetLastCheckedTime( repository, "update" );
Artifact artifact = createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" );
artifact.getFile().setLastModified( System.currentTimeMillis() );
List artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
assertNotNull( "Check artifacts not null", artifacts );
assertFalse( "Check not included", artifacts.contains( artifact ) );
// try again with the updated timestamp
artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
assertNotNull( "Check artifacts not null", artifacts );
assertFalse( "Check not included", artifacts.contains( artifact ) );
}
public void testUpdatedInRepositoryNotBlackout()
throws ComponentLookupException, DiscovererException, IOException
{
discoverer.resetLastCheckedTime( repository, "update" );
Artifact artifact = createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" );
artifact.getFile().setLastModified( System.currentTimeMillis() - 61000 );
List artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check included", artifacts.contains( artifact ) );
// try again with the updated timestamp
artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
assertNotNull( "Check artifacts not null", artifacts );
assertFalse( "Check not included", artifacts.contains( artifact ) );
}
public void testNotUpdatedInRepositoryForcedDiscoveryMetadataAlreadyExists()
throws ComponentLookupException, DiscovererException, IOException
{