APISonar


com.linecorp.armeria.client.ClientRequestContext.log

> com > linecorp > armeria > client > ClientRequestContext > log
com APIs linecorp APIs armeria APIs client APIs ClientRequestContext APIs log APIs

Example 1
public CompletionStage<Boolean> shouldReportAsSuccess(ClientRequestContext ctx, @Nullable Throwable cause) {
        if (cause instanceof UnprocessedRequestException) {
            return CompletableFuture.completedFuture(null); // Neither success nor failure.
        }
        final HttpStatus status;
        if (ctx.log().isAvailable(RequestLogAvailability.RESPONSE_HEADERS)) {
            status = ctx.log().responseHeaders().status();
        } else {
            status = null;
        }
        return CompletableFuture.completedFuture(function.apply(status, cause));
    }
Example 2
private Function<? super HttpClient, ? extends HttpClient> loggingDecorator() {
        return delegate -> new SimpleDecoratingHttpClient(delegate) {
            @Override
            public HttpResponse execute(ClientRequestContext ctx, HttpRequest req) throws Exception {
                ctx.log().addListener(listener, RequestLogAvailability.REQUEST_END);
                ctx.log().addListener(listener, RequestLogAvailability.COMPLETE);
                return delegate().execute(ctx, req);
            }
        };
    }
Example 3
public void testId_Assign() {
        final RequestHeaders reqHeaders =
                RequestHeaders.of(HttpMethod.POST, "/armeria/id",
                                  HttpHeaderNames.CONTENT_LENGTH, VERY_LONG_STRING.length());
        final HttpRequest req = AggregatedHttpRequest.of(reqHeaders, HttpData.ofUtf8(VERY_LONG_STRING))
                                                     .toHttpRequest();
        final ClientRequestContext cctx = ClientRequestContext.builder(req).build();
        assertThat(cctx.log().id()).isNotNull();
        assertThat(cctx.log().id()).isEqualTo(cctx.id());

        final ServiceRequestContext sctx = ServiceRequestContext.of(req);
        assertThat(sctx.log().id()).isNotNull();
        assertThat(sctx.log().id()).isEqualTo(sctx.id());
    }
Example 4
private ClientRequestContext ctx;

    void statusCode_notAvailable() {
        when(ctx.log()).thenReturn(requestLog);
        when(requestLog.isAvailable(RequestLogAvailability.RESPONSE_HEADERS)).thenReturn(false);
        assertThat(response.statusCode()).isEqualTo(0);
    }
Example 5
void hasSameNameAndTagAsDefaultMeterIdPrefixFunction() {
        final MeterRegistry registry = NoopMeterRegistry.get();
        final MeterIdPrefixFunction f1 = RetrofitMeterIdPrefixFunction.of("foo");
        final MeterIdPrefixFunction f2 = MeterIdPrefixFunction.ofDefault("foo");

        final ClientRequestContext ctx = newContext();
        assertThat(f1.apply(registry, ctx.log())).isEqualTo(f2.apply(registry, ctx.log()));
    }
Example 6
private ClientRequestContext ctx;

    void requestHeader() {
        when(ctx.log()).thenReturn(requestLog);
        when(requestLog.isAvailable(RequestLogAvailability.REQUEST_HEADERS)).thenReturn(true);
        final RequestHeaders requestHeaders = mock(RequestHeaders.class);
        when(requestLog.requestHeaders()).thenReturn(requestHeaders);
        when(requestHeaders.get("foo")).thenReturn("bar");
        assertThat(request.header("foo")).isEqualTo("bar");
    }