30
30
import org .apache .hc .client5 .http .classic .methods .HttpUriRequest ;
31
31
import org .apache .hc .client5 .http .impl .io .PoolingHttpClientConnectionManager ;
32
32
import org .apache .hc .client5 .http .io .HttpClientConnectionManager ;
33
- import org .apache .hc .core5 .http .ClassicHttpResponse ;
34
- import org .apache .hc .core5 .http .HttpVersion ;
35
- import org .apache .hc .core5 .http .io .HttpClientResponseHandler ;
36
33
import org .apache .hc .core5 .http .message .BasicClassicHttpResponse ;
37
- import org .apache .hc .core5 .http .message .BasicHttpResponse ;
38
34
import org .apache .hc .core5 .http .protocol .HttpContext ;
39
35
import org .apache .hc .core5 .pool .PoolStats ;
40
36
import org .junit .Before ;
43
39
import org .mockito .Mock ;
44
40
import org .mockito .junit .MockitoJUnitRunner ;
45
41
import software .amazon .awssdk .http .HttpExecuteRequest ;
46
- import software .amazon .awssdk .http .HttpExecuteResponse ;
47
42
import software .amazon .awssdk .http .SdkHttpFullRequest ;
48
43
import software .amazon .awssdk .http .SdkHttpMethod ;
49
44
import software .amazon .awssdk .http .apache5 .internal .Apache5HttpRequestConfig ;
@@ -63,16 +58,20 @@ public class MetricReportingTest {
63
58
64
59
@ Before
65
60
public void methodSetup () throws IOException {
61
+ // Create a response that can be reused
62
+ BasicClassicHttpResponse response = new BasicClassicHttpResponse (200 , "OK" );
66
63
67
- when (mockHttpClient .execute (any (HttpUriRequest .class ), any (HttpContext .class )))
68
- .thenReturn (new BasicClassicHttpResponse (200 , "OK" ));
64
+ // Mock executeOpen which is now being used
65
+ when (mockHttpClient .executeOpen (any (), any (HttpUriRequest .class ), any (HttpContext .class )))
66
+ .thenReturn (response );
69
67
70
68
when (mockHttpClient .getHttpClientConnectionManager ()).thenReturn (cm );
71
69
72
70
PoolStats stats = new PoolStats (1 , 2 , 3 , 4 );
73
71
when (cm .getTotalStats ()).thenReturn (stats );
74
72
}
75
73
74
+
76
75
@ Test
77
76
public void prepareRequest_callableCalled_metricsReported () throws IOException {
78
77
Apache5HttpClient client = newClient ();
@@ -117,11 +116,11 @@ private Apache5HttpClient newClient() {
117
116
}
118
117
119
118
private HttpExecuteRequest newRequest (MetricCollector collector ) {
120
- final SdkHttpFullRequest sdkRequest = SdkHttpFullRequest .builder ()
121
- .method (SdkHttpMethod .HEAD )
122
- .host ("amazonaws.com" )
123
- .protocol ("https" )
124
- .build ();
119
+ SdkHttpFullRequest sdkRequest = SdkHttpFullRequest .builder ()
120
+ .method (SdkHttpMethod .HEAD )
121
+ .host ("amazonaws.com" )
122
+ .protocol ("https" )
123
+ .build ();
125
124
return HttpExecuteRequest .builder ()
126
125
.request (sdkRequest )
127
126
.metricCollector (collector )
0 commit comments