Search in sources :

Example 1 with Dispatcher

use of com.squareup.okhttp.Dispatcher in project dropbox-sdk-java by dropbox.

the class OkHttpRequestorTest method testSameThreadDispatcher.

@Test(expectedExceptions = { IllegalArgumentException.class })
public void testSameThreadDispatcher() {
    OkHttpClient client = new OkHttpClient();
    // should fail for same-thread executors
    client.setDispatcher(new Dispatcher(MoreExecutors.newDirectExecutorService()));
    new OkHttpRequestor(client);
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient) Dispatcher(com.squareup.okhttp.Dispatcher) Test(org.testng.annotations.Test)

Example 2 with Dispatcher

use of com.squareup.okhttp.Dispatcher in project dropbox-sdk-java by dropbox.

the class OkHttpRequestorTest method testCustomDispatcher.

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

Aggregations

Dispatcher (com.squareup.okhttp.Dispatcher)2 OkHttpClient (com.squareup.okhttp.OkHttpClient)2 Test (org.testng.annotations.Test)2