use of okhttp3.Dispatcher in project OpenRefine by OpenRefine.
the class ExtendDataOperationTests method testFetchStrings.
@Test
public void testFetchStrings() throws Exception {
DataExtensionConfig extension = DataExtensionConfig.reconstruct("{\"properties\":[{\"id\":\"P297\",\"name\":\"ISO 3166-1 alpha-2 code\"}]}");
try (MockWebServer server = new MockWebServer()) {
server.start();
server.setDispatcher(dispatcher);
mockHttpCall("{\"ids\":[\"Q863\",\"Q794\",\"Q17\",\"Q30\"],\"properties\":[{\"id\":\"P297\"}]}", "{" + "\"rows\": {" + " \"Q794\": {\"P297\": [{\"str\": \"IR\"}]}," + " \"Q863\": {\"P297\": []}," + " \"Q30\": {\"P297\": [{\"str\": \"US\"}]}," + " \"Q17\": {\"P297\": [{\"str\": \"JP\"}]}" + "}," + "\"meta\": [" + " {\"name\": \"ISO 3166-1 alpha-2 code\", \"id\": \"P297\"}" + "]}");
EngineDependentOperation op = new ExtendDataOperation(engine_config, "country", server.url("/reconcile").url().toString(), RECON_IDENTIFIER_SPACE, RECON_SCHEMA_SPACE, extension, 1);
LongRunningProcessStub process = new LongRunningProcessStub(op.createProcess(project, options));
process.run();
// Inspect rows
Assert.assertTrue("IR".equals(project.rows.get(0).getCellValue(1)), "Bad country code for Iran.");
Assert.assertTrue("JP".equals(project.rows.get(1).getCellValue(1)), "Bad country code for Japan.");
Assert.assertNull(project.rows.get(2).getCell(1), "Expected a null country code.");
Assert.assertTrue("US".equals(project.rows.get(3).getCellValue(1)), "Bad country code for United States.");
// Make sure we did not create any recon stats for that column (no reconciled value)
Assert.assertTrue(project.columnModel.getColumnByName("ISO 3166-1 alpha-2 code").getReconStats() == null);
}
}
use of okhttp3.Dispatcher in project ExoPlayer by google.
the class HttpDataSourceTestEnv method before.
@Override
protected void before() throws Throwable {
originServer.start();
originServer.setDispatcher(WebServerDispatcher.forResources(ImmutableList.of(RANGE_SUPPORTED, RANGE_SUPPORTED_LENGTH_UNKNOWN, RANGE_NOT_SUPPORTED, RANGE_NOT_SUPPORTED_LENGTH_UNKNOWN, GZIP_ENABLED, GZIP_FORCED)));
redirectionServer.start();
redirectionServer.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) {
if (getRequestPath(request).equals(REDIRECTS_TO_RANGE_SUPPORTED.getPath())) {
return new MockResponse().setResponseCode(302).setHeader("Location", originServer.url(RANGE_SUPPORTED.getPath()).toString());
} else {
return new MockResponse().setResponseCode(404);
}
}
});
}
use of okhttp3.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());
}
use of okhttp3.Dispatcher in project dropbox-sdk-java by dropbox.
the class OkHttp3RequestorTest method testCustomDispatcher.
@Test
public void testCustomDispatcher() {
OkHttpClient.Builder client = new OkHttpClient.Builder();
// should be fine with default Dispatcher
new OkHttp3Requestor(client.build());
// should also be fine with other common executors that run on separate threads
client.dispatcher(new Dispatcher(Executors.newSingleThreadExecutor()));
new OkHttp3Requestor(client.build());
client.dispatcher(new Dispatcher(Executors.newCachedThreadPool()));
new OkHttp3Requestor(client.build());
client.dispatcher(new Dispatcher(Executors.newFixedThreadPool(3)));
new OkHttp3Requestor(client.build());
}
use of okhttp3.Dispatcher in project dubbo by alibaba.
the class EmbeddedApolloJunit5 method beforeAll.
@Override
public void beforeAll(ExtensionContext extensionContext) throws Exception {
clear();
server = new MockWebServer();
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().startsWith("/notifications/v2")) {
String notifications = request.getRequestUrl().queryParameter("notifications");
return new MockResponse().setResponseCode(200).setBody(mockLongPollBody(notifications));
}
if (request.getPath().startsWith("/configs")) {
List<String> pathSegments = request.getRequestUrl().pathSegments();
// appId and cluster might be used in the future
String appId = pathSegments.get(1);
String cluster = pathSegments.get(2);
String namespace = pathSegments.get(3);
return new MockResponse().setResponseCode(200).setBody(loadConfigFor(namespace));
}
return new MockResponse().setResponseCode(404);
}
};
server.setDispatcher(dispatcher);
server.start();
mockConfigServiceUrl("http://localhost:" + server.getPort());
}
Aggregations