Search in sources :

Example 86 with Dispatcher

use of okhttp3.Dispatcher in project java-cloudant by cloudant.

the class LoggingTest method setupMockWebServer.

@BeforeEach
public void setupMockWebServer() throws Exception {
    mockWebServer = mockWebServerExt.get();
    // Set a dispatcher that always returns 200 OK
    mockWebServer.setDispatcher(new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            return new MockResponse();
        }
    });
    client = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer).build();
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Dispatcher(okhttp3.mockwebserver.Dispatcher) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 87 with Dispatcher

use of okhttp3.Dispatcher in project td-client-java by treasure-data.

the class TestServerFailures method unknownResponseCode.

@Test
public void unknownResponseCode() throws Exception {
    server.setDispatcher(new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            if (request.getPath().endsWith("server_status")) {
                // return an invalid response code
                return new MockResponse().setResponseCode(600);
            } else {
                // return an invalid resonce code
                return new MockResponse().setResponseCode(HttpStatus.NOT_ACCEPTABLE_406);
            }
        }
    });
    server.start(port);
    TDClient client = TDClient.newBuilder().setEndpoint("localhost").setUseSSL(false).setPort(port).build();
    try {
        client.serverStatus();
        fail("cannot reach here");
    } catch (TDClientHttpException e) {
        assertEquals(600, e.getStatusCode());
    }
    // 406 error
    try {
        client.listDatabaseNames();
        fail("cannot reach heer");
    } catch (TDClientHttpException e) {
        assertEquals(406, e.getStatusCode());
    }
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Dispatcher(okhttp3.mockwebserver.Dispatcher) Test(org.junit.Test)

Example 88 with Dispatcher

use of okhttp3.Dispatcher in project MVP by yuchengren.

the class OkHttpUtil method getQueuedAndRunningCallList.

public List<Call> getQueuedAndRunningCallList() {
    Dispatcher dispatcher = mOkHttpClient.dispatcher();
    List<Call> callList = new ArrayList<>();
    callList.addAll(dispatcher.queuedCalls());
    callList.addAll(dispatcher.runningCalls());
    return callList;
}
Also used : Call(okhttp3.Call) ArrayList(java.util.ArrayList) Dispatcher(okhttp3.Dispatcher)

Aggregations

Dispatcher (okhttp3.Dispatcher)40 OkHttpClient (okhttp3.OkHttpClient)34 MockResponse (okhttp3.mockwebserver.MockResponse)27 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)25 Dispatcher (okhttp3.mockwebserver.Dispatcher)24 IOException (java.io.IOException)17 Before (org.junit.Before)14 Test (org.junit.Test)13 Call (okhttp3.Call)11 MockWebServer (okhttp3.mockwebserver.MockWebServer)11 LruNormalizedCacheFactory (com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory)10 ArrayList (java.util.ArrayList)8 Request (okhttp3.Request)8 Response (okhttp3.Response)8 ResponseBody (okhttp3.ResponseBody)7 Gson (com.google.gson.Gson)5 Interceptor (okhttp3.Interceptor)5 CloudantClient (com.cloudant.client.api.CloudantClient)4 RefineTest (com.google.refine.RefineTest)4 DataExtensionConfig (com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig)4