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();
}
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();
}
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();
}
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();
}
});
}
});
}
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"));
}
}
Aggregations