mirror of https://github.com/apache/archiva.git
[MRM-138] add more proxy tests, and fix a bug where a cached failure would not trigger a hard failure on a repository configured to
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@431137 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
58463f598f
commit
ba2bef3cd3
|
@ -110,7 +110,7 @@ public class DefaultProxyRequestHandler
|
||||||
|
|
||||||
if ( repository.isCachedFailure( path ) )
|
if ( repository.isCachedFailure( path ) )
|
||||||
{
|
{
|
||||||
getLogger().debug( "Skipping repository " + repository.getName() + " for a cached path failure." );
|
processRepositoryFailure( repository, "Cached failure found" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -249,8 +249,8 @@ public class DefaultProxyRequestHandler
|
||||||
|
|
||||||
if ( tries > 1 && !success )
|
if ( tries > 1 && !success )
|
||||||
{
|
{
|
||||||
//noinspection ThrowCaughtLocally
|
processRepositoryFailure( repository, "Checksum failures occurred while downloading " + path );
|
||||||
throw new TransferFailedException( "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
|
// temp won't exist if we called getIfNewer and it was older, but its still a successful return
|
||||||
|
@ -265,13 +265,11 @@ public class DefaultProxyRequestHandler
|
||||||
}
|
}
|
||||||
catch ( TransferFailedException e )
|
catch ( TransferFailedException e )
|
||||||
{
|
{
|
||||||
String message = "Skipping repository " + repository.getName() + ": " + e.getMessage();
|
processRepositoryFailure( repository, e );
|
||||||
processRepositoryFailure( repository, message, e );
|
|
||||||
}
|
}
|
||||||
catch ( AuthorizationException e )
|
catch ( AuthorizationException e )
|
||||||
{
|
{
|
||||||
String message = "Skipping repository " + repository.getName() + ": " + e.getMessage();
|
processRepositoryFailure( repository, e );
|
||||||
processRepositoryFailure( repository, message, e );
|
|
||||||
}
|
}
|
||||||
catch ( ResourceDoesNotExistException e )
|
catch ( ResourceDoesNotExistException e )
|
||||||
{
|
{
|
||||||
|
@ -483,26 +481,33 @@ public class DefaultProxyRequestHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void processRepositoryFailure( ProxiedArtifactRepository repository, Throwable t )
|
||||||
* 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 )
|
|
||||||
throws ProxyException
|
throws ProxyException
|
||||||
{
|
{
|
||||||
if ( repository.isHardFail() )
|
if ( repository.isHardFail() )
|
||||||
{
|
{
|
||||||
throw new ProxyException(
|
throw new ProxyException(
|
||||||
"An error occurred in hardfailing repository " + repository.getName() + "...\n " + message, t );
|
"An error occurred in hardfailing repository " + repository.getName() + "...\n " + t.getMessage(),
|
||||||
|
t );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
getLogger().warn( message );
|
getLogger().warn( "Skipping repository " + repository.getName() + ": " + t.getMessage() );
|
||||||
getLogger().debug( message, t );
|
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 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
getLogger().warn( "Skipping repository " + repository.getName() + ": " + message );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,6 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* @author Brett Porter
|
* @author Brett Porter
|
||||||
* @todo! tests to do vvv
|
* @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 when failure should be cached but caching is disabled
|
||||||
* @todo test snapshots - general
|
* @todo test snapshots - general
|
||||||
* @todo test snapshots - newer version on repo2 is pulled down
|
* @todo test snapshots - newer version on repo2 is pulled down
|
||||||
|
@ -58,6 +56,7 @@ import java.util.List;
|
||||||
* @todo test remote checksum present and correct
|
* @todo test remote checksum present and correct
|
||||||
* @todo test remote checksum present and incorrect
|
* @todo test remote checksum present and incorrect
|
||||||
* @todo test remote checksum transfer failed
|
* @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
|
public class ProxyRequestHandlerTest
|
||||||
extends PlexusTestCase
|
extends PlexusTestCase
|
||||||
|
@ -324,6 +323,64 @@ public class ProxyRequestHandlerTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
* A faster recursive copy that omits .svn directories.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue