Search in sources :

Example 46 with OkHttpClient

use of com.squareup.okhttp.OkHttpClient 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 47 with OkHttpClient

use of com.squareup.okhttp.OkHttpClient 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

OkHttpClient (com.squareup.okhttp.OkHttpClient)47 Request (com.squareup.okhttp.Request)22 Response (com.squareup.okhttp.Response)18 IOException (java.io.IOException)15 RequestBody (com.squareup.okhttp.RequestBody)8 Provides (dagger.Provides)6 Gson (com.google.gson.Gson)5 Cache (com.squareup.okhttp.Cache)5 Singleton (javax.inject.Singleton)5 SpringAndroidSpiceRequest (com.octo.android.robospice.request.springandroid.SpringAndroidSpiceRequest)4 File (java.io.File)4 RestAdapter (retrofit.RestAdapter)4 OkClient (retrofit.client.OkClient)4 SSLContext (javax.net.ssl.SSLContext)3 X509TrustManager (javax.net.ssl.X509TrustManager)3 HttpResponse (org.apache.http.HttpResponse)3 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Call (com.squareup.okhttp.Call)2 Dispatcher (com.squareup.okhttp.Dispatcher)2