Search in sources :

Example 6 with MockResponse

use of okhttp3.mockwebserver.MockResponse in project zipkin by openzipkin.

the class AWSSignatureVersion4Test method unwrapsJsonError.

@Test
public void unwrapsJsonError() throws InterruptedException, IOException {
    // makes sure this isn't wrapped.
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("The request signature we calculated does not match the signature you provided.");
    es.enqueue(new MockResponse().setResponseCode(403).setBody("{\"message\":\"The request signature we calculated does not match the signature you provided.\"}"));
    client.newCall(new Request.Builder().url(es.url("/_template/zipkin_template")).build()).execute();
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 7 with MockResponse

use of okhttp3.mockwebserver.MockResponse in project zipkin by openzipkin.

the class HttpCallTest method propagatesOnDispatcherThreadWhenFatal.

@Test
public void propagatesOnDispatcherThreadWhenFatal() throws Exception {
    mws.enqueue(new MockResponse());
    http.newCall(request, b -> {
        throw new LinkageError();
    }).submit(callback);
    SimpleTimeLimiter timeLimiter = new SimpleTimeLimiter();
    try {
        timeLimiter.callWithTimeout(callback::get, 100, TimeUnit.MILLISECONDS, true);
        failBecauseExceptionWasNotThrown(UncheckedTimeoutException.class);
    } catch (UncheckedTimeoutException expected) {
    }
}
Also used : Request(okhttp3.Request) SimpleTimeLimiter(com.google.common.util.concurrent.SimpleTimeLimiter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) OkHttpClient(okhttp3.OkHttpClient) Rule(org.junit.Rule) After(org.junit.After) MockWebServer(okhttp3.mockwebserver.MockWebServer) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) MockResponse(okhttp3.mockwebserver.MockResponse) CallbackCaptor(zipkin.internal.CallbackCaptor) Assertions.failBecauseExceptionWasNotThrown(org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown) MockResponse(okhttp3.mockwebserver.MockResponse) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) SimpleTimeLimiter(com.google.common.util.concurrent.SimpleTimeLimiter) Test(org.junit.Test)

Example 8 with MockResponse

use of okhttp3.mockwebserver.MockResponse in project zipkin by openzipkin.

the class HttpCallTest method executionException_conversionException.

@Test
public void executionException_conversionException() throws Exception {
    mws.enqueue(new MockResponse());
    http.newCall(request, b -> {
        throw new IllegalArgumentException("eeek");
    }).submit(callback);
    try {
        callback.get();
        failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (IllegalArgumentException expected) {
        assertThat(expected).isInstanceOf(IllegalArgumentException.class);
    }
}
Also used : Request(okhttp3.Request) SimpleTimeLimiter(com.google.common.util.concurrent.SimpleTimeLimiter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) OkHttpClient(okhttp3.OkHttpClient) Rule(org.junit.Rule) After(org.junit.After) MockWebServer(okhttp3.mockwebserver.MockWebServer) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) MockResponse(okhttp3.mockwebserver.MockResponse) CallbackCaptor(zipkin.internal.CallbackCaptor) Assertions.failBecauseExceptionWasNotThrown(org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 9 with MockResponse

use of okhttp3.mockwebserver.MockResponse in project zipkin by openzipkin.

the class ElasticsearchHttpStorageTest method memoizesIndexTemplate.

@Test
public void memoizesIndexTemplate() throws Exception {
    es.enqueue(new MockResponse().setBody("{\"version\":{\"number\":\"2.4.0\"}}"));
    // get template
    es.enqueue(new MockResponse());
    // dependencies request
    es.enqueue(new MockResponse());
    // dependencies request
    es.enqueue(new MockResponse());
    long endTs = storage.indexNameFormatter().parseDate("2016-10-02");
    storage.spanStore().getDependencies(endTs, TimeUnit.DAYS.toMillis(1));
    storage.spanStore().getDependencies(endTs, TimeUnit.DAYS.toMillis(1));
    // get version
    es.takeRequest();
    // get template
    es.takeRequest();
    assertThat(es.takeRequest().getPath()).startsWith("/zipkin-2016-10-01,zipkin-2016-10-02/dependencylink/_search");
    assertThat(es.takeRequest().getPath()).startsWith("/zipkin-2016-10-01,zipkin-2016-10-02/dependencylink/_search");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 10 with MockResponse

use of okhttp3.mockwebserver.MockResponse in project zipkin by openzipkin.

the class HttpBulkSpanIndexerTest method doesntWriteSpanId.

@Test
public void doesntWriteSpanId() throws Exception {
    es.enqueue(new MockResponse());
    indexer.add("test_zipkin_http-2016-10-01", TestObjects.LOTS_OF_SPANS[0], (Long) null);
    indexer.execute(callback);
    callback.get();
    RecordedRequest request = es.takeRequest();
    assertThat(request.getBody().readByteString().utf8()).doesNotContain("\"_id\"");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)1754 Test (org.junit.Test)1284 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)483 AtomicReference (java.util.concurrent.atomic.AtomicReference)258 Test (org.junit.jupiter.api.Test)216 MockWebServer (okhttp3.mockwebserver.MockWebServer)201 CountDownLatch (java.util.concurrent.CountDownLatch)196 IOException (java.io.IOException)158 HttpURLConnection (java.net.HttpURLConnection)157 ANError (com.androidnetworking.error.ANError)148 Response (okhttp3.Response)147 MockResponse (mockwebserver3.MockResponse)115 Buffer (okio.Buffer)104 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)89 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)84 List (java.util.List)84 URL (java.net.URL)78 URLConnection (java.net.URLConnection)76 Request (okhttp3.Request)70 ANResponse (com.androidnetworking.common.ANResponse)61