Search in sources :

Example 1 with ClientAdapter

use of brave.http.HttpResponseParserAdapters.ClientAdapter in project brave by openzipkin.

the class HttpResponseParserAdaptersTest method parse_HttpClientResponse.

@Test
public void parse_HttpClientResponse() {
    ClientAdapter parserAdapter = new ClientAdapter(currentTraceContext, parser);
    HttpClientResponse response = mock(HttpClientResponse.class);
    Object res = new Object();
    when(response.unwrap()).thenReturn(res);
    parserAdapter.parse(response, context, span);
    HttpClientAdapters.ToResponseAdapter a = new HttpClientAdapters.ToResponseAdapter(response, res);
    verify(parser).response(refEq(a), eq(res), eq(null), eq(span));
}
Also used : ClientAdapter(brave.http.HttpResponseParserAdapters.ClientAdapter) Test(org.junit.Test)

Example 2 with ClientAdapter

use of brave.http.HttpResponseParserAdapters.ClientAdapter in project brave by openzipkin.

the class HttpResponseParserAdaptersTest method parse_parsesInScope.

/**
 * The old http handler always parsed in scope because the parser had no argument for a trace
 * context.
 */
@Test
public void parse_parsesInScope() {
    AtomicBoolean parsed = new AtomicBoolean();
    ClientAdapter parserAdapter = new ClientAdapter(currentTraceContext, new HttpParser() {

        @Override
        public <Res> void response(HttpAdapter<?, Res> adapter, Res res, Throwable error, SpanCustomizer customizer) {
            parsed.set(true);
            assertThat(currentTraceContext.get()).isSameAs(context);
        }
    });
    parserAdapter.parse(mock(HttpClientResponse.class), context, span);
    assertThat(parsed).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientAdapter(brave.http.HttpResponseParserAdapters.ClientAdapter) SpanCustomizer(brave.SpanCustomizer) Test(org.junit.Test)

Example 3 with ClientAdapter

use of brave.http.HttpResponseParserAdapters.ClientAdapter in project brave by openzipkin.

the class HttpResponseParserAdaptersTest method parse_HttpClientParse_unwrapNull.

@Test
public void parse_HttpClientParse_unwrapNull() {
    ClientAdapter parserAdapter = new ClientAdapter(currentTraceContext, parser);
    HttpClientResponse response = mock(HttpClientResponse.class);
    // to avoid old parsers seeing null
    Object res = NULL_SENTINEL;
    parserAdapter.parse(response, context, span);
    HttpClientAdapters.ToResponseAdapter a = new HttpClientAdapters.ToResponseAdapter(response, res);
    verify(parser).response(refEq(a), eq(res), eq(null), eq(span));
}
Also used : ClientAdapter(brave.http.HttpResponseParserAdapters.ClientAdapter) Test(org.junit.Test)

Example 4 with ClientAdapter

use of brave.http.HttpResponseParserAdapters.ClientAdapter in project brave by openzipkin.

the class HttpResponseParserAdaptersTest method parse_HttpClientResponseAdapter.

@Test
public void parse_HttpClientResponseAdapter() {
    ClientAdapter parserAdapter = new ClientAdapter(currentTraceContext, parser);
    HttpClientAdapter adapter = mock(HttpClientAdapter.class);
    Object res = new Object();
    parserAdapter.parse(new HttpClientAdapters.FromResponseAdapter(adapter, res, null), context, span);
    verify(parser).response(adapter, res, null, span);
}
Also used : ClientAdapter(brave.http.HttpResponseParserAdapters.ClientAdapter) Test(org.junit.Test)

Example 5 with ClientAdapter

use of brave.http.HttpResponseParserAdapters.ClientAdapter in project brave by openzipkin.

the class HttpResponseParserAdaptersTest method parse_HttpClientParse_error.

@Test
public void parse_HttpClientParse_error() {
    ClientAdapter parserAdapter = new ClientAdapter(currentTraceContext, parser);
    HttpClientResponse response = mock(HttpClientResponse.class);
    Object res = new Object();
    Throwable error = new Throwable();
    when(response.unwrap()).thenReturn(res);
    when(response.error()).thenReturn(error);
    parserAdapter.parse(response, context, span);
    HttpClientAdapters.ToResponseAdapter a = new HttpClientAdapters.ToResponseAdapter(response, res);
    verify(parser).response(refEq(a), eq(res), eq(error), eq(span));
}
Also used : ClientAdapter(brave.http.HttpResponseParserAdapters.ClientAdapter) Test(org.junit.Test)

Aggregations

ClientAdapter (brave.http.HttpResponseParserAdapters.ClientAdapter)5 Test (org.junit.Test)5 SpanCustomizer (brave.SpanCustomizer)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1