Search in sources :

Example 81 with Dispatcher

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);
    }
}
Also used : LongRunningProcessStub(com.google.refine.process.LongRunningProcessStub) EngineDependentOperation(com.google.refine.operations.EngineDependentOperation) MockWebServer(okhttp3.mockwebserver.MockWebServer) DataExtensionConfig(com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 82 with Dispatcher

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);
            }
        }
    });
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Dispatcher(okhttp3.mockwebserver.Dispatcher)

Example 83 with Dispatcher

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());
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Dispatcher(okhttp3.Dispatcher) Test(org.testng.annotations.Test)

Example 84 with Dispatcher

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());
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Dispatcher(okhttp3.Dispatcher) Test(org.testng.annotations.Test)

Example 85 with Dispatcher

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());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) MockWebServer(okhttp3.mockwebserver.MockWebServer) Dispatcher(okhttp3.mockwebserver.Dispatcher)

Aggregations

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