if ( repository.isCachedFailure( path ) )
{
- getLogger().debug( "Skipping repository " + repository.getName() + " for a cached path failure." );
+ processRepositoryFailure( repository, "Cached failure found" );
}
else
{
if ( tries > 1 && !success )
{
- //noinspection ThrowCaughtLocally
- throw new TransferFailedException( "Checksum failures occurred while downloading " + path );
+ processRepositoryFailure( repository, "Checksum failures occurred while downloading " + path );
+ return;
}
// temp won't exist if we called getIfNewer and it was older, but its still a successful return
}
catch ( TransferFailedException e )
{
- String message = "Skipping repository " + repository.getName() + ": " + e.getMessage();
- processRepositoryFailure( repository, message, e );
+ processRepositoryFailure( repository, e );
}
catch ( AuthorizationException e )
{
- String message = "Skipping repository " + repository.getName() + ": " + e.getMessage();
- processRepositoryFailure( repository, message, e );
+ processRepositoryFailure( repository, e );
}
catch ( ResourceDoesNotExistException e )
{
}
}
- /**
- * Queries the configuration on how to handle a repository download failure
- *
- * @param repository the repository object where the failure occurred
- * @param message the message/reason for the failure
- * @param t the cause for the exception
- * @throws ProxyException if hard failure is enabled on the repository causing the failure
- */
- private void processRepositoryFailure( ProxiedArtifactRepository repository, String message, Throwable t )
+ private void processRepositoryFailure( ProxiedArtifactRepository repository, Throwable t )
+ throws ProxyException
+ {
+ if ( repository.isHardFail() )
+ {
+ throw new ProxyException(
+ "An error occurred in hardfailing repository " + repository.getName() + "...\n " + t.getMessage(),
+ t );
+ }
+ else
+ {
+ getLogger().warn( "Skipping repository " + repository.getName() + ": " + t.getMessage() );
+ getLogger().debug( "Cause", t );
+ }
+ }
+
+ private void processRepositoryFailure( ProxiedArtifactRepository repository, String message )
throws ProxyException
{
if ( repository.isHardFail() )
{
throw new ProxyException(
- "An error occurred in hardfailing repository " + repository.getName() + "...\n " + message, t );
+ "An error occurred in hardfailing repository " + repository.getName() + "...\n " + message );
}
else
{
- getLogger().warn( message );
- getLogger().debug( message, t );
+ getLogger().warn( "Skipping repository " + repository.getName() + ": " + message );
}
}
/**
* @author Brett Porter
* @todo! tests to do vvv
- * @todo test when failure is cached
- * @todo test when failure is cached and repo is hard fail
* @todo test when failure should be cached but caching is disabled
* @todo test snapshots - general
* @todo test snapshots - newer version on repo2 is pulled down
* @todo test remote checksum present and correct
* @todo test remote checksum present and incorrect
* @todo test remote checksum transfer failed
+ * @todo test when failure is cached but cache period is over (and check failure is cleared)
*/
public class ProxyRequestHandlerTest
extends PlexusTestCase
}
}
+ public void testGetInSecondProxiedRepoFirstFailsFromCache()
+ throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException,
+ AuthorizationException
+ {
+ // fail from the cache, even though it is in the first repo now
+
+ String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar";
+ File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
+
+ assertFalse( expectedFile.exists() );
+
+ proxiedRepositories.clear();
+ ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 );
+ proxiedArtifactRepository.addFailure( path );
+ proxiedRepositories.add( proxiedArtifactRepository );
+ proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) );
+ File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
+
+ assertEquals( "Check file matches", expectedFile, file );
+ assertTrue( "Check file created", file.exists() );
+
+ File proxiedFile = new File( proxiedRepository2.getBasedir(), path );
+ String expectedContents = FileUtils.fileRead( proxiedFile );
+ assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) );
+
+ proxiedFile = new File( proxiedRepository1.getBasedir(), path );
+ String unexpectedContents = FileUtils.fileRead( proxiedFile );
+ assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) );
+ }
+
+ public void testGetInSecondProxiedRepoFirstHardFailsFromCache()
+ throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException,
+ AuthorizationException
+ {
+ // fail from the cache, even though it is in the first repo now
+
+ String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar";
+ File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
+
+ assertFalse( expectedFile.exists() );
+
+ proxiedRepositories.clear();
+ ProxiedArtifactRepository proxiedArtifactRepository = createHardFailProxiedRepository( proxiedRepository1 );
+ proxiedArtifactRepository.addFailure( path );
+ proxiedRepositories.add( proxiedArtifactRepository );
+ proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) );
+ try
+ {
+ File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
+ fail( "Found file: " + file + "; but was expecting a failure" );
+ }
+ catch ( ProxyException e )
+ {
+ // expect a failure
+ assertTrue( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) );
+ }
+ }
+
/**
* A faster recursive copy that omits .svn directories.
*