Search in sources :

Example 31 with Dispatcher

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

the class NormalizedCacheTestCase method setUp.

@Before
public void setUp() {
    OkHttpClient okHttpClient = new OkHttpClient.Builder().writeTimeout(2, TimeUnit.SECONDS).readTimeout(2, TimeUnit.SECONDS).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();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) LruNormalizedCacheFactory(com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory) Dispatcher(okhttp3.Dispatcher) Before(org.junit.Before)

Example 32 with Dispatcher

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

the class Rx2ApolloTest method setup.

@Before
public void setup() {
    OkHttpClient okHttpClient = new OkHttpClient.Builder().dispatcher(new Dispatcher(immediateExecutorService())).build();
    apolloClient = ApolloClient.builder().serverUrl(server.url("/")).dispatcher(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) Dispatcher(okhttp3.Dispatcher) Before(org.junit.Before)

Example 33 with Dispatcher

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

the class BaseFetcherTest method setUp.

@Before
public void setUp() {
    server = new MockWebServer();
    OkHttpClient okHttpClient = new OkHttpClient.Builder().writeTimeout(2, TimeUnit.SECONDS).readTimeout(2, TimeUnit.SECONDS).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();
}
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 34 with Dispatcher

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

the class ApolloServerInterceptor method interceptAsync.

@Override
public void interceptAsync(@Nonnull final InterceptorRequest request, @Nonnull final ApolloInterceptorChain chain, @Nonnull Executor dispatcher, @Nonnull final CallBack callBack) {
    if (disposed)
        return;
    dispatcher.execute(new Runnable() {

        @Override
        public void run() {
            callBack.onFetch(FetchSourceType.NETWORK);
            try {
                httpCall = httpCall(request.operation);
            } catch (IOException e) {
                logger.e(e, "Failed to prepare http call for operation %s", request.operation.name().name());
                callBack.onFailure(new ApolloNetworkException("Failed to prepare http call", e));
                return;
            }
            httpCall.enqueue(new Callback() {

                @Override
                public void onFailure(@Nonnull Call call, @Nonnull IOException e) {
                    if (disposed)
                        return;
                    logger.e(e, "Failed to execute http call for operation %s", request.operation.name().name());
                    callBack.onFailure(new ApolloNetworkException("Failed to execute http call", e));
                }

                @Override
                public void onResponse(@Nonnull Call call, @Nonnull Response response) throws IOException {
                    if (disposed)
                        return;
                    callBack.onResponse(new ApolloInterceptor.InterceptorResponse(response));
                    callBack.onCompleted();
                }
            });
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Nonnull(javax.annotation.Nonnull) ApolloInterceptor(com.apollographql.apollo.interceptor.ApolloInterceptor) IOException(java.io.IOException) ApolloNetworkException(com.apollographql.apollo.exception.ApolloNetworkException)

Example 35 with Dispatcher

use of okhttp3.Dispatcher in project okhttp by square.

the class InterceptorTest method applicationInterceptorReturnsNull.

@Test
public void applicationInterceptorReturnsNull() throws Exception {
    server.enqueue(new MockResponse());
    Interceptor interceptor = chain -> {
        chain.proceed(chain.request());
        return null;
    };
    client = client.newBuilder().addInterceptor(interceptor).build();
    ExceptionCatchingExecutor executor = new ExceptionCatchingExecutor();
    client = client.newBuilder().dispatcher(new Dispatcher(executor)).build();
    Request request = new Request.Builder().url(server.url("/")).build();
    try {
        client.newCall(request).execute();
        fail();
    } catch (NullPointerException expected) {
        assertThat(expected.getMessage()).isEqualTo(("interceptor " + interceptor + " returned null"));
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Okio(okio.Okio) BeforeEach(org.junit.jupiter.api.BeforeEach) Socket(java.net.Socket) Source(okio.Source) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicReference(java.util.concurrent.atomic.AtomicReference) Sink(okio.Sink) MockWebServer(mockwebserver3.MockWebServer) InetAddress(java.net.InetAddress) ServerSocket(java.net.ServerSocket) SocketPolicy(mockwebserver3.SocketPolicy) BufferedSink(okio.BufferedSink) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Locale(java.util.Locale) SocketTimeoutException(java.net.SocketTimeoutException) Duration(java.time.Duration) ForwardingSource(okio.ForwardingSource) Tag(org.junit.jupiter.api.Tag) Buffer(okio.Buffer) SynchronousQueue(java.util.concurrent.SynchronousQueue) IOException(java.io.IOException) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Unit(kotlin.Unit) GzipSink(okio.GzipSink) ForwardingSink(okio.ForwardingSink) MockResponse(mockwebserver3.MockResponse) TestUtil.assertSuppressed(okhttp3.TestUtil.assertSuppressed) RecordedRequest(mockwebserver3.RecordedRequest) MockResponse(mockwebserver3.MockResponse) RecordedRequest(mockwebserver3.RecordedRequest) Test(org.junit.jupiter.api.Test)

Aggregations

Dispatcher (okhttp3.Dispatcher)42 OkHttpClient (okhttp3.OkHttpClient)34 MockResponse (okhttp3.mockwebserver.MockResponse)28 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)26 Dispatcher (okhttp3.mockwebserver.Dispatcher)25 IOException (java.io.IOException)19 Before (org.junit.Before)18 MockWebServer (okhttp3.mockwebserver.MockWebServer)16 Test (org.junit.Test)15 Call (okhttp3.Call)11 LruNormalizedCacheFactory (com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory)10 ArrayList (java.util.ArrayList)8 Request (okhttp3.Request)8 Response (okhttp3.Response)8 Interceptor (okhttp3.Interceptor)7 ResponseBody (okhttp3.ResponseBody)7 Gson (com.google.gson.Gson)5 CloudantClient (com.cloudant.client.api.CloudantClient)4 RefineTest (com.google.refine.RefineTest)4 DataExtensionConfig (com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig)4