Search in sources :

Example 61 with Response

use of okhttp3.Response in project okhttputils by hongyangAndroid.

the class LoggerInterceptor method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    logForRequest(request);
    Response response = chain.proceed(request);
    return logForResponse(response);
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request)

Example 62 with Response

use of okhttp3.Response in project zipkin by openzipkin.

the class ZipkinRuleTest method storeSpans_readbackHttp.

@Test
public void storeSpans_readbackHttp() throws IOException {
    // write the span to zipkin directly
    zipkin.storeSpans(TRACE);
    // read trace id using the the http api
    Response getResponse = client.newCall(new Request.Builder().url(format("%s/api/v1/trace/%016x", zipkin.httpUrl(), traceId)).build()).execute();
    assertThat(getResponse.code()).isEqualTo(200);
}
Also used : Response(okhttp3.Response) Test(org.junit.Test)

Example 63 with Response

use of okhttp3.Response in project zipkin by openzipkin.

the class ZipkinRuleTest method healthIsOK.

@Test
public void healthIsOK() throws IOException {
    Response getResponse = client.newCall(new Request.Builder().url(zipkin.httpUrl() + "/health").build()).execute();
    assertThat(getResponse.code()).isEqualTo(200);
    assertThat(getResponse.body().string()).isEqualTo("OK\n");
}
Also used : Response(okhttp3.Response) Test(org.junit.Test)

Example 64 with Response

use of okhttp3.Response in project zipkin by openzipkin.

the class ZipkinRuleTest method storeSpans_readbackRaw.

/** The raw query can show affects like redundant rows in the data store. */
@Test
public void storeSpans_readbackRaw() throws IOException {
    // write the span to zipkin directly
    zipkin.storeSpans(TRACE);
    zipkin.storeSpans(TRACE);
    // Default will merge by span id
    Response defaultResponse = client.newCall(new Request.Builder().url(format("%s/api/v1/trace/%016x", zipkin.httpUrl(), traceId)).build()).execute();
    assertThat(Codec.JSON.readSpans(defaultResponse.body().bytes())).hasSize(TRACE.size());
    // In the in-memory (or cassandra) stores, a raw read will show duplicate span rows.
    Response rawResponse = client.newCall(new Request.Builder().url(format("%s/api/v1/trace/%016x?raw", zipkin.httpUrl(), traceId)).build()).execute();
    assertThat(Codec.JSON.readSpans(rawResponse.body().bytes())).hasSize(TRACE.size() * 2);
}
Also used : Response(okhttp3.Response) Test(org.junit.Test)

Example 65 with Response

use of okhttp3.Response in project zipkin by openzipkin.

the class ZipkinRuleTest method readSpans_gzippedResponse.

@Test
public void readSpans_gzippedResponse() throws Exception {
    char[] annotation2K = new char[2048];
    Arrays.fill(annotation2K, 'a');
    List<Span> trace = asList(TRACE.get(0).toBuilder().addAnnotation(Annotation.create(System.currentTimeMillis(), new String(annotation2K), null)).build());
    zipkin.storeSpans(trace);
    Response response = client.newCall(new Request.Builder().url(format("%s/api/v1/trace/%016x", zipkin.httpUrl(), traceId)).addHeader("Accept-Encoding", "gzip").build()).execute();
    assertThat(response.code()).isEqualTo(200);
    assertThat(response.body().contentLength()).isLessThan(annotation2K.length);
    Buffer result = new Buffer();
    GzipSource source = new GzipSource(response.body().source());
    while (source.read(result, Integer.MAX_VALUE) != -1) ;
    byte[] unzipped = result.readByteArray();
    assertThat(Codec.JSON.readSpans(unzipped)).isEqualTo(trace);
}
Also used : Response(okhttp3.Response) Buffer(okio.Buffer) GzipSource(okio.GzipSource) Request(okhttp3.Request) ByteString(okio.ByteString) Span(zipkin.Span) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)471 Response (okhttp3.Response)444 MockResponse (okhttp3.mockwebserver.MockResponse)380 Request (okhttp3.Request)377 ResponseBody (okhttp3.ResponseBody)351 IOException (java.io.IOException)220 DateTime (org.joda.time.DateTime)194 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)192 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)178 Response (retrofit2.Response)150 ServiceCall (com.microsoft.rest.ServiceCall)140 ServiceResponse (com.microsoft.rest.ServiceResponse)114 Observable (rx.Observable)104 Call (okhttp3.Call)103 List (java.util.List)95 RequestBody (okhttp3.RequestBody)85 PagedList (com.microsoft.azure.PagedList)80 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)78 OkHttpClient (okhttp3.OkHttpClient)78 HttpURLConnection (java.net.HttpURLConnection)47