use of okhttp3.Dispatcher in project java-cloudant by cloudant.
the class LoggingTest method setupMockWebServer.
@BeforeEach
public void setupMockWebServer() throws Exception {
mockWebServer = mockWebServerExt.get();
// Set a dispatcher that always returns 200 OK
mockWebServer.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
return new MockResponse();
}
});
client = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer).build();
}
use of okhttp3.Dispatcher in project td-client-java by treasure-data.
the class TestServerFailures method unknownResponseCode.
@Test
public void unknownResponseCode() throws Exception {
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().endsWith("server_status")) {
// return an invalid response code
return new MockResponse().setResponseCode(600);
} else {
// return an invalid resonce code
return new MockResponse().setResponseCode(HttpStatus.NOT_ACCEPTABLE_406);
}
}
});
server.start(port);
TDClient client = TDClient.newBuilder().setEndpoint("localhost").setUseSSL(false).setPort(port).build();
try {
client.serverStatus();
fail("cannot reach here");
} catch (TDClientHttpException e) {
assertEquals(600, e.getStatusCode());
}
// 406 error
try {
client.listDatabaseNames();
fail("cannot reach heer");
} catch (TDClientHttpException e) {
assertEquals(406, e.getStatusCode());
}
}
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;
}
Aggregations