Search in sources :

Example 21 with Dispatcher

use of okhttp3.Dispatcher in project dropbox-sdk-java by dropbox.

the class OkHttp3RequestorTest method testSameThreadDispatcher.

@Test(expectedExceptions = { IllegalArgumentException.class })
public void testSameThreadDispatcher() {
    OkHttpClient.Builder client = new OkHttpClient.Builder();
    // should fail for same-thread executors
    client.dispatcher(new Dispatcher(MoreExecutors.newDirectExecutorService()));
    new OkHttp3Requestor(client.build());
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Dispatcher(okhttp3.Dispatcher) Test(org.testng.annotations.Test)

Example 22 with Dispatcher

use of okhttp3.Dispatcher in project dropbox-sdk-java by dropbox.

the class OkHttp3RequestorTest method testCustomDispatcher.

@Test
public void testCustomDispatcher() {
    OkHttpClient.Builder client = new OkHttpClient.Builder();
    // should be fine with default Dispatcher
    new OkHttp3Requestor(client.build());
    // should also be fine with other common executors that run on separate threads
    client.dispatcher(new Dispatcher(Executors.newSingleThreadExecutor()));
    new OkHttp3Requestor(client.build());
    client.dispatcher(new Dispatcher(Executors.newCachedThreadPool()));
    new OkHttp3Requestor(client.build());
    client.dispatcher(new Dispatcher(Executors.newFixedThreadPool(3)));
    new OkHttp3Requestor(client.build());
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Dispatcher(okhttp3.Dispatcher) Test(org.testng.annotations.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)9 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)9 Dispatcher (okhttp3.Dispatcher)8 OkHttpClient (okhttp3.OkHttpClient)7 Test (org.junit.Test)7 IOException (java.io.IOException)6 ResponseBody (okhttp3.ResponseBody)6 Dispatcher (okhttp3.mockwebserver.Dispatcher)6 Request (okhttp3.Request)5 Gson (com.google.gson.Gson)4 Dispatcher (io.chelizi.amokhttp.Dispatcher)4 Response (okhttp3.Response)4 Type (java.lang.reflect.Type)3 Call (okhttp3.Call)2 Interceptor (okhttp3.Interceptor)2 Buffer (okio.Buffer)2 Test (org.testng.annotations.Test)2 Bundle (android.os.Bundle)1 Message (android.os.Message)1 BuckConfig (com.facebook.buck.cli.BuckConfig)1