Search in sources :

Example 66 with Dispatcher

use of okhttp3.Dispatcher in project apollo-android by apollographql.

the class ResponseNormalizationTest method setUp.

@Before
public void setUp() {
    OkHttpClient okHttpClient = new OkHttpClient.Builder().dispatcher(new Dispatcher(Utils.immediateExecutorService())).build();
    apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).normalizedCache(new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION), new IdFieldCacheKeyResolver()).dispatcher(Utils.immediateExecutor()).build();
    normalizedCache = apolloClient.apolloStore().normalizedCache();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) LruNormalizedCacheFactory(com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory) Dispatcher(okhttp3.Dispatcher) Before(org.junit.Before)

Example 67 with Dispatcher

use of okhttp3.Dispatcher in project apollo-android by apollographql.

the class SendOperationIdentifiersTest method operationIdHttpRequestHeader.

@Test
public void operationIdHttpRequestHeader() throws Exception {
    final HeroAndFriendsNamesQuery heroAndFriendsNamesQuery = new HeroAndFriendsNamesQuery(Input.fromNullable(EMPIRE));
    final AtomicBoolean applicationInterceptorHeader = new AtomicBoolean();
    final AtomicBoolean networkInterceptorHeader = new AtomicBoolean();
    OkHttpClient okHttpClient = new OkHttpClient.Builder().dispatcher(new Dispatcher(Utils.immediateExecutorService())).addInterceptor(new Interceptor() {

        @Override
        public okhttp3.Response intercept(Chain chain) throws IOException {
            Request request = chain.request();
            if (request.header("X-APOLLO-OPERATION-ID").equals(heroAndFriendsNamesQuery.operationId())) {
                applicationInterceptorHeader.set(true);
            }
            return chain.proceed(chain.request());
        }
    }).addNetworkInterceptor(new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            Request request = chain.request();
            if (request.header("X-APOLLO-OPERATION-ID").equals(heroAndFriendsNamesQuery.operationId())) {
                networkInterceptorHeader.set(true);
            }
            return chain.proceed(chain.request());
        }
    }).build();
    ApolloClient apolloClient = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).dispatcher(Utils.immediateExecutor()).build();
    enqueueAndAssertResponse(server, "HeroAndFriendsNameResponse.json", apolloClient.query(heroAndFriendsNamesQuery), new Predicate<com.apollographql.apollo.api.Response<HeroAndFriendsNamesQuery.Data>>() {

        @Override
        public boolean test(com.apollographql.apollo.api.Response<HeroAndFriendsNamesQuery.Data> response) throws Exception {
            return !response.hasErrors();
        }
    });
    assertThat(applicationInterceptorHeader.get()).isTrue();
    assertThat(networkInterceptorHeader.get()).isTrue();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) IOException(java.io.IOException) Dispatcher(okhttp3.Dispatcher) IOException(java.io.IOException) Utils.enqueueAndAssertResponse(com.apollographql.apollo.Utils.enqueueAndAssertResponse) Response(okhttp3.Response) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HeroAndFriendsNamesQuery(com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesQuery) Interceptor(okhttp3.Interceptor) Test(org.junit.Test)

Example 68 with Dispatcher

use of okhttp3.Dispatcher in project apollo-android by apollographql.

the class QueryRefetchTest method setUp.

@Before
public void setUp() throws IOException {
    server = new MockWebServer();
    server.start();
    OkHttpClient okHttpClient = new OkHttpClient.Builder().dispatcher(new Dispatcher(Utils.immediateExecutorService())).build();
    apolloClient = ApolloClient.builder().serverUrl(server.url("/")).dispatcher(Utils.immediateExecutor()).okHttpClient(okHttpClient).normalizedCache(new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION), new IdFieldCacheKeyResolver()).build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) LruNormalizedCacheFactory(com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory) MockWebServer(okhttp3.mockwebserver.MockWebServer) Dispatcher(okhttp3.Dispatcher) IdFieldCacheKeyResolver(com.apollographql.apollo.IdFieldCacheKeyResolver) Before(org.junit.Before)

Example 69 with Dispatcher

use of okhttp3.Dispatcher in project lzc_app_lib by httplzc.

the class HttpUtil method cancelAllHttpRequest.

public static void cancelAllHttpRequest(Object tag) {
    if (tag == null)
        return;
    for (Call call : OkHttpInstance.getClient().dispatcher().queuedCalls()) {
        if (call.request().tag() == tag) {
            call.cancel();
            Log.i("lzc", "call_cancel_queuedCalls " + call.request().tag());
        }
    }
    for (Call call : OkHttpInstance.getClient().dispatcher().runningCalls()) {
        if (call.request().tag() == tag) {
            call.cancel();
            Log.i("lzc", "call_cancel_runningCalls " + call.request().tag());
        }
    }
}
Also used : Call(okhttp3.Call)

Example 70 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