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);
}
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);
}
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");
}
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);
}
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);
}
Aggregations