@ -22,6 +22,7 @@ import org.apache.http.HttpResponse;
@@ -22,6 +22,7 @@ import org.apache.http.HttpResponse;
import org.apache.http.StatusLine ;
import org.apache.http.client.HttpClient ;
import org.apache.http.client.config.RequestConfig ;
import org.apache.http.client.methods.CloseableHttpResponse ;
import org.apache.http.client.methods.HttpUriRequest ;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager ;
import org.junit.After ;
@ -285,7 +286,7 @@ public class RibbonLoadBalancingHttpClientTests {
@@ -285,7 +286,7 @@ public class RibbonLoadBalancingHttpClientTests {
HttpMethod method = HttpMethod . POST ;
URI uri = new URI ( "http://" + host + ":" + port ) ;
HttpClient delegate = mock ( HttpClient . class ) ;
final HttpResponse response = mock ( HttpResponse . class ) ;
final Closeable HttpResponse response = mock ( Closeable HttpResponse. class ) ;
StatusLine statusLine = mock ( StatusLine . class ) ;
doReturn ( 200 ) . when ( statusLine ) . getStatusCode ( ) ;
doReturn ( statusLine ) . when ( response ) . getStatusLine ( ) ;
@ -301,6 +302,7 @@ public class RibbonLoadBalancingHttpClientTests {
@@ -301,6 +302,7 @@ public class RibbonLoadBalancingHttpClientTests {
HttpUriRequest uriRequest = mock ( HttpUriRequest . class ) ;
doReturn ( uriRequest ) . when ( request ) . toRequest ( any ( RequestConfig . class ) ) ;
RibbonApacheHttpResponse returnedResponse = client . execute ( request , null ) ;
verify ( response , times ( 0 ) ) . close ( ) ;
verify ( delegate , times ( 3 ) ) . execute ( any ( HttpUriRequest . class ) ) ;
verify ( lb , times ( 1 ) ) . chooseServer ( eq ( serviceName ) ) ;
}
@ -317,7 +319,7 @@ public class RibbonLoadBalancingHttpClientTests {
@@ -317,7 +319,7 @@ public class RibbonLoadBalancingHttpClientTests {
HttpMethod method = HttpMethod . POST ;
URI uri = new URI ( "http://" + host + ":" + port ) ;
HttpClient delegate = mock ( HttpClient . class ) ;
final HttpResponse response = mock ( HttpResponse . class ) ;
final Closeable HttpResponse response = mock ( Closeable HttpResponse. class ) ;
doThrow ( new IOException ( "boom" ) ) . doThrow ( new IOException ( "boom again" ) ) . doReturn ( response ) .
when ( delegate ) . execute ( any ( HttpUriRequest . class ) ) ;
ILoadBalancer lb = mock ( ILoadBalancer . class ) ;
@ -334,6 +336,7 @@ public class RibbonLoadBalancingHttpClientTests {
@@ -334,6 +336,7 @@ public class RibbonLoadBalancingHttpClientTests {
client . execute ( request , null ) ;
fail ( "Expected IOException" ) ;
} catch ( IOException e ) { } finally {
verify ( response , times ( 0 ) ) . close ( ) ;
verify ( delegate , times ( 1 ) ) . execute ( any ( HttpUriRequest . class ) ) ;
verify ( lb , times ( 0 ) ) . chooseServer ( eq ( serviceName ) ) ;
}
@ -355,7 +358,7 @@ public class RibbonLoadBalancingHttpClientTests {
@@ -355,7 +358,7 @@ public class RibbonLoadBalancingHttpClientTests {
StatusLine statusLine = mock ( StatusLine . class ) ;
doReturn ( 200 ) . when ( statusLine ) . getStatusCode ( ) ;
doReturn ( statusLine ) . when ( response ) . getStatusLine ( ) ;
final HttpResponse fourOFourResponse = mock ( HttpResponse . class ) ;
final Closeable HttpResponse fourOFourResponse = mock ( Closeable HttpResponse. class ) ;
StatusLine fourOFourStatusLine = mock ( StatusLine . class ) ;
doReturn ( 404 ) . when ( fourOFourStatusLine ) . getStatusCode ( ) ;
doReturn ( fourOFourStatusLine ) . when ( fourOFourResponse ) . getStatusLine ( ) ;
@ -371,6 +374,7 @@ public class RibbonLoadBalancingHttpClientTests {
@@ -371,6 +374,7 @@ public class RibbonLoadBalancingHttpClientTests {
doReturn ( uri ) . when ( uriRequest ) . getURI ( ) ;
doReturn ( uriRequest ) . when ( request ) . toRequest ( any ( RequestConfig . class ) ) ;
RibbonApacheHttpResponse returnedResponse = client . execute ( request , null ) ;
verify ( fourOFourResponse , times ( 1 ) ) . close ( ) ;
verify ( delegate , times ( 2 ) ) . execute ( any ( HttpUriRequest . class ) ) ;
verify ( lb , times ( 0 ) ) . chooseServer ( eq ( serviceName ) ) ;
}