use of mockwebserver3.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 mockwebserver3.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"));
}
}
use of mockwebserver3.Dispatcher in project okhttp by square.
the class WebSocketHttpTest method readTimeoutAppliesWithinFrames.
/**
* There's no read timeout when reading the first byte of a new frame. But as soon as we start
* reading a frame we enable the read timeout. In this test we have the server returning the first
* byte of a frame but no more frames.
*/
@Test
public void readTimeoutAppliesWithinFrames() {
webServer.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) {
return upgradeResponse(request).setBody(// Truncated frame.
new Buffer().write(ByteString.decodeHex("81"))).removeHeader("Content-Length").setSocketPolicy(SocketPolicy.KEEP_OPEN);
}
});
WebSocket webSocket = newWebSocket();
clientListener.assertOpen();
clientListener.assertFailure(SocketTimeoutException.class, "timeout", "Read timed out");
assertThat(webSocket.close(1000, null)).isFalse();
}
use of mockwebserver3.Dispatcher in project MVPArms by JessYanCoding.
the class ClientModule method provideClient.
/**
* 提供 {@link OkHttpClient}
*
* @param application {@link Application}
* @param configuration {@link OkhttpConfiguration}
* @param builder {@link OkHttpClient.Builder}
* @param intercept {@link Interceptor}
* @param interceptors {@link List<Interceptor>}
* @param handler {@link GlobalHttpHandler}
* @param executorService {@link ExecutorService}
* @return {@link OkHttpClient}
*/
@Singleton
@Provides
static OkHttpClient provideClient(Application application, @Nullable OkhttpConfiguration configuration, OkHttpClient.Builder builder, Interceptor intercept, @Nullable List<Interceptor> interceptors, @Nullable GlobalHttpHandler handler, ExecutorService executorService) {
builder.connectTimeout(TIME_OUT, TimeUnit.SECONDS).readTimeout(TIME_OUT, TimeUnit.SECONDS).addNetworkInterceptor(intercept);
if (handler != null) {
builder.addInterceptor(chain -> chain.proceed(handler.onHttpRequestBefore(chain, chain.request())));
}
// 如果外部提供了 Interceptor 的集合则遍历添加
if (interceptors != null) {
for (Interceptor interceptor : interceptors) {
builder.addInterceptor(interceptor);
}
}
// 为 OkHttp 设置默认的线程池
builder.dispatcher(new Dispatcher(executorService));
if (configuration != null) {
configuration.configOkhttp(application, builder);
}
return builder.build();
}
use of mockwebserver3.Dispatcher in project alluxio by Alluxio.
the class KodoUnderFileSystem method initializeKodoClientConfig.
private static Builder initializeKodoClientConfig(UnderFileSystemConfiguration conf) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequests(conf.getInt(PropertyKey.UNDERFS_KODO_REQUESTS_MAX));
builder.connectTimeout(conf.getMs(PropertyKey.UNDERFS_KODO_CONNECT_TIMEOUT), TimeUnit.SECONDS);
return builder;
}
Aggregations