Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
bclozel committed Jun 28, 2023
1 parent 80e8682 commit 447c482
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
* .addExecInterceptorLast("micrometer", new ObservationExecChainHandler(observationRegistry))
* .build();
* </pre>
* <p>Note that the {@link ObservationExecChainHandler} must always be inserted after the
* <p>
* Note that the {@link ObservationExecChainHandler} must always be inserted after the
* {@link ChainElement#RETRY retry interceptor}, preferably last.
*
* @author Brian Clozel
Expand All @@ -65,7 +66,6 @@ public class ObservationExecChainHandler implements ExecChainHandler, AsyncExecC
@Nullable
private final ApacheHttpClientObservationConvention observationConvention;


public ObservationExecChainHandler(ObservationRegistry observationRegistry,
@Nullable ApacheHttpClientObservationConvention observationConvention) {
this.observationRegistry = observationRegistry;
Expand All @@ -76,21 +76,20 @@ public ObservationExecChainHandler(ObservationRegistry observationRegistry) {
this(observationRegistry, null);
}


@Override
public void execute(HttpRequest request, AsyncEntityProducer entityProducer, AsyncExecChain.Scope scope,
AsyncExecChain chain, AsyncExecCallback asyncExecCallback) throws HttpException, IOException {
ApacheHttpClientContext observationContext = new ApacheHttpClientContext(request, scope.clientContext);
Observation observation = ApacheHttpClientObservationDocumentation.DEFAULT
.observation(observationConvention, DefaultApacheHttpClientObservationConvention.INSTANCE,
() -> observationContext, observationRegistry)
() -> observationContext, observationRegistry)
.start();
ObervableCancellableDependency cancellable = new ObervableCancellableDependency(observation);
chain.proceed(request, entityProducer, cancellable.wrapScope(scope), new AsyncExecCallback() {

@Override
public AsyncDataConsumer handleResponse(HttpResponse response, EntityDetails entityDetails)
throws HttpException, IOException {
throws HttpException, IOException {
observationContext.setResponse(response);
observation.stop();
return asyncExecCallback.handleResponse(response, entityDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void recordProtocolErrorsAsIoErrors(@WiremockResolver.Wiremock WireMockServer se

@Test
void recordSocketTimeoutAsIoErrors(@WiremockResolver.Wiremock WireMockServer server) throws Exception {
server.stubFor(get(urlEqualTo("/delayed")).willReturn(aResponse().withStatus(200).withFixedDelay(2100)));
server.stubFor(get(urlEqualTo("/delayed")).willReturn(aResponse().withStatus(200).withFixedDelay(2000)));
try (CloseableHttpClient client = classicClient()) {
assertThatThrownBy(() -> executeClassic(client, new HttpGet(server.baseUrl() + "/delayed")))
.isInstanceOf(SocketTimeoutException.class);
Expand Down Expand Up @@ -409,8 +409,8 @@ private CloseableHttpAsyncClient asyncClient() {
TimeValue.ofMilliseconds(500L));

ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setSocketTimeout(2000, TimeUnit.MILLISECONDS)
.setConnectTimeout(2000L, TimeUnit.MILLISECONDS)
.setSocketTimeout(1000, TimeUnit.MILLISECONDS)
.setConnectTimeout(1000, TimeUnit.MILLISECONDS)
.build();

HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom()
Expand Down

0 comments on commit 447c482

Please sign in to comment.