Search in sources :

Example 36 with Dispatcher

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

the class ApolloCancelCallTest method setup.

@Before
public void setup() {
    cacheStore = new MockHttpCacheStore();
    OkHttpClient okHttpClient = new OkHttpClient.Builder().dispatcher(new Dispatcher(Utils.immediateExecutorService())).build();
    apolloClient = ApolloClient.builder().serverUrl(server.url("/")).dispatcher(Utils.immediateExecutor()).okHttpClient(okHttpClient).httpCache(new ApolloHttpCache(cacheStore, null)).build();
}
Also used : ApolloHttpCache(com.apollographql.apollo.cache.http.ApolloHttpCache) OkHttpClient(okhttp3.OkHttpClient) Dispatcher(okhttp3.Dispatcher) Before(org.junit.Before)

Example 37 with Dispatcher

use of mockwebserver3.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 38 with Dispatcher

use of mockwebserver3.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 39 with Dispatcher

use of mockwebserver3.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 40 with Dispatcher

use of mockwebserver3.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)

Aggregations

Dispatcher (okhttp3.Dispatcher)43 OkHttpClient (okhttp3.OkHttpClient)28 Before (org.junit.Before)14 LruNormalizedCacheFactory (com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory)10 IOException (java.io.IOException)9 Interceptor (okhttp3.Interceptor)7 Test (org.junit.Test)7 Call (okhttp3.Call)6 RecordedRequest (mockwebserver3.RecordedRequest)5 ApolloHttpCache (com.apollographql.apollo.cache.http.ApolloHttpCache)3 CustomTypeValue (com.apollographql.apollo.response.CustomTypeValue)3 ParseException (java.text.ParseException)3 MockResponse (mockwebserver3.MockResponse)3 ConnectionPool (okhttp3.ConnectionPool)3 Request (okhttp3.Request)3 Response (okhttp3.Response)3 Buffer (okio.Buffer)3 NonNull (android.support.annotation.NonNull)2 IdFieldCacheKeyResolver (com.apollographql.apollo.IdFieldCacheKeyResolver)2 Response (com.apollographql.apollo.api.Response)2