maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WAGON-526) making the retry handle of http client configurable
Date Mon, 20 Aug 2018 19:51:02 GMT

    [ https://issues.apache.org/jira/browse/WAGON-526?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16586440#comment-16586440
] 

ASF GitHub Bot commented on WAGON-526:
--------------------------------------

michael-o commented on a change in pull request #37: [WAGON-526] making the retry handle of
http client configurable
URL: https://github.com/apache/maven-wagon/pull/37#discussion_r211385725
 
 

 ##########
 File path: wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagonTest.java
 ##########
 @@ -51,4 +79,197 @@ public void test()
 
         wagon.disconnect();
     }
+
+    @Test
+    public void retryableConfigurationDefaultTest() throws Exception
+    {
+        doTestHttpClient(new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                final HttpRequestRetryHandler handler = getCurrentHandler();
+                assertNotNull( handler );
+                assertThat( handler, instanceOf( DefaultHttpRequestRetryHandler.class ) );
+                final DefaultHttpRequestRetryHandler impl = DefaultHttpRequestRetryHandler.class.cast(handler);
+                assertEquals( 3, impl.getRetryCount() );
+                assertFalse( impl.isRequestSentRetryEnabled() );
+            }
+        });
+    }
+
+    @Test
+    public void retryableConfigurationCountTest() throws Exception
+    {
+        doTestHttpClient(new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                System.setProperty( "maven.wagon.http.retryhandler.class", "default" );
+                System.setProperty( "maven.wagon.http.retryhandler.count", "5" );
+
+                final HttpRequestRetryHandler handler = getCurrentHandler();
+                assertNotNull( handler );
+                assertThat( handler, instanceOf( DefaultHttpRequestRetryHandler.class ) );
+                final DefaultHttpRequestRetryHandler impl = DefaultHttpRequestRetryHandler.class.cast(handler);
+                assertEquals( 5, impl.getRetryCount() );
+                assertFalse( impl.isRequestSentRetryEnabled() );
+            }
+        });
+    }
+
+    @Test
+    public void retryableConfigurationSentTest() throws Exception
+    {
+        doTestHttpClient(new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                System.setProperty( "maven.wagon.http.retryhandler.class", "default" );
+                System.setProperty( "maven.wagon.http.retryhandler.requestSentEnabled", "true"
);
+
+                final HttpRequestRetryHandler handler = getCurrentHandler();
+                assertNotNull( handler );
+                assertThat( handler, instanceOf( DefaultHttpRequestRetryHandler.class ) );
+                final DefaultHttpRequestRetryHandler impl = DefaultHttpRequestRetryHandler.class.cast(handler);
+                assertEquals( 3, impl.getRetryCount() );
+                assertTrue( impl.isRequestSentRetryEnabled() );
+            }
+        });
+    }
+
+    @Test
+    public void retryableConfigurationExceptionsTest() throws Exception
+    {
+        doTestHttpClient(new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                System.setProperty( "maven.wagon.http.retryhandler.class", "default" );
+                System.setProperty( "maven.wagon.http.retryhandler.nonRetryableClasses",
IOException.class.getName() );
+
+                final HttpRequestRetryHandler handler = getCurrentHandler();
+                assertNotNull( handler );
+                assertThat( handler, instanceOf( DefaultHttpRequestRetryHandler.class ) );
+                final DefaultHttpRequestRetryHandler impl = DefaultHttpRequestRetryHandler.class.cast(handler);
+                assertEquals( 3, impl.getRetryCount() );
+                assertFalse( impl.isRequestSentRetryEnabled() );
+
+                try
+                {
+                    final Field nonRetriableClasses = handler.getClass().getSuperclass()
+                            .getDeclaredField( "nonRetriableClasses" );
+                    if (!nonRetriableClasses.isAccessible())
+                    {
+                        nonRetriableClasses.setAccessible(true);
+                    }
+                    final Set<?> exceptions = Set.class.cast( nonRetriableClasses.get(handler)
);
+                    assertEquals( 1, exceptions.size() );
+                    assertTrue( exceptions.contains( IOException.class ) );
+                }
+                catch ( final Exception e )
+                {
+                    fail( e.getMessage() );
+                }
+            }
+        });
+    }
+
+    private HttpRequestRetryHandler getCurrentHandler()
+    {
+        try
+        {
+            final Class<?> impl = Thread.currentThread().getContextClassLoader().loadClass(
+                        "org.apache.maven.wagon.shared.http.AbstractHttpClientWagon" );
+
+            final CloseableHttpClient httpClient = CloseableHttpClient.class.cast(
+                    impl.getMethod("getHttpClient").invoke(null) );
+
+            final Field redirectExec = httpClient.getClass().getDeclaredField("execChain");
+            if (!redirectExec.isAccessible())
+            {
+                redirectExec.setAccessible( true );
+            }
+            final RedirectExec redirectExecInstance = RedirectExec.class.cast(
+                    redirectExec.get( httpClient ) );
+
+            final Field requestExecutor = redirectExecInstance.getClass().getDeclaredField("requestExecutor");
+            if (!requestExecutor.isAccessible())
+            {
+                requestExecutor.setAccessible( true );
+            }
+            final RetryExec requestExecutorInstance = RetryExec.class.cast(
+                    requestExecutor.get( redirectExecInstance ) );
+
+            final Field retryHandler = requestExecutorInstance.getClass().getDeclaredField(
"retryHandler" );
+            if (!retryHandler.isAccessible())
+            {
+                retryHandler.setAccessible( true );
+            }
+            return HttpRequestRetryHandler.class.cast( retryHandler.get( requestExecutorInstance
) );
+        }
+        catch (final Exception e)
+        {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private void doTestHttpClient(final Runnable test) throws Exception
+    {
+        final String classpath = System.getProperty( "java.class.path" );
+        final String[] paths = classpath.split( File.pathSeparator );
+        final Collection<URL> urls = new ArrayList<>( paths.length );
+        for ( final String path : paths )
+        {
+            try
+            {
+                urls.add( new File(path).toURI().toURL() );
+            }
+            catch ( final MalformedURLException e )
+            {
+                fail( e.getMessage() );
+            }
+        }
+        final URLClassLoader loader = new URLClassLoader( urls.toArray( new URL[paths.length
] ) , new ClassLoader()
 
 Review comment:
   trailing space

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> making the retry handle of http client configurable
> ---------------------------------------------------
>
>                 Key: WAGON-526
>                 URL: https://issues.apache.org/jira/browse/WAGON-526
>             Project: Maven Wagon
>          Issue Type: New Feature
>            Reporter: Romain Manni-Bucau
>            Priority: Major
>
> Provide a way to customize a lot (until a custom impl) the way wagon retries downloads.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message