]> source.dussan.org Git - archiva.git/commitdiff
[MRM-138] add more proxy tests, and fix a bug where a cached failure would not trigge...
authorBrett Porter <brett@apache.org>
Sun, 13 Aug 2006 02:51:39 +0000 (02:51 +0000)
committerBrett Porter <brett@apache.org>
Sun, 13 Aug 2006 02:51:39 +0000 (02:51 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@431137 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyRequestHandler.java
maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.java

index 5b000e413d9023847e22b6f2e5fd50407e4ace97..298a586a35849efd38da6bf97a8855c9e3f835bc 100644 (file)
@@ -110,7 +110,7 @@ public class DefaultProxyRequestHandler
 
             if ( repository.isCachedFailure( path ) )
             {
-                getLogger().debug( "Skipping repository " + repository.getName() + " for a cached path failure." );
+                processRepositoryFailure( repository, "Cached failure found" );
             }
             else
             {
@@ -249,8 +249,8 @@ public class DefaultProxyRequestHandler
 
                     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
@@ -265,13 +265,11 @@ public class DefaultProxyRequestHandler
         }
         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 )
         {
@@ -483,26 +481,33 @@ public class DefaultProxyRequestHandler
         }
     }
 
-    /**
-     * 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 );
         }
     }
 
index c722686d0534293a9749328817e52370f37707b3..b7aef88759ba1d9f146213a4d1ff788b19392a35 100644 (file)
@@ -36,8 +36,6 @@ import java.util.List;
 /**
  * @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
@@ -58,6 +56,7 @@ import java.util.List;
  * @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
@@ -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.
      *