Search in sources :

Example 26 with OkHttpClient

use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project che-server by eclipse-che.

the class OpenShiftClientFactory method clientForConfig.

private OkHttpClient clientForConfig(Config config) {
    OkHttpClient clientHttpClient = getHttpClient().newBuilder().authenticator(Authenticator.NONE).build();
    OkHttpClient.Builder builder = clientHttpClient.newBuilder();
    builder.interceptors().clear();
    return builder.addInterceptor(new OpenShiftOAuthInterceptor(clientHttpClient, OpenShiftConfig.wrap(config))).addInterceptor(new ImpersonatorInterceptor(config)).build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) ImpersonatorInterceptor(io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor) OpenShiftOAuthInterceptor(io.fabric8.openshift.client.internal.OpenShiftOAuthInterceptor)

Example 27 with OkHttpClient

use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project hetu-core by openlookeng.

the class TestDataCenterHTTPClientV1 method assertQuery.

private void assertQuery(String sql) {
    OkHttpClient httpClient = new OkHttpClient();
    try {
        DataCenterClientSession clientSession = DataCenterClientSession.builder(queryRunner.getCoordinator().getBaseUrl(), "user").withClientTimeout(new Duration(2, MINUTES)).withTypeManager(typeManager).build();
        StatementClient client1 = DataCenterStatementClient.newStatementClient(httpClient, clientSession, sql, UUID.randomUUID().toString());
        long client1Count = 0;
        // wait for query to be fully scheduled
        while (client1.isRunning()) {
            if (client1.currentData().getData() != null) {
                for (List<Object> row : client1.currentData().getData()) {
                    System.out.println(row);
                    client1Count++;
                }
            }
            client1.advance();
        }
        System.out.println("ROWS: " + client1Count);
        StatementClient client2 = newStatementClient(httpClient, clientSession, sql);
        long client2Count = 0;
        // wait for query to be fully scheduled
        while (client2.isRunning()) {
            if (client2.currentData().getData() != null) {
                for (List<Object> row : client2.currentData().getData()) {
                    System.out.println(row);
                    client2Count++;
                }
            }
            client2.advance();
        }
        System.out.println("ROWS: " + client2Count);
        assertEquals(client1Count, client2Count);
    } finally {
        // close the client since, query is not managed by the client protocol
        httpClient.dispatcher().executorService().shutdown();
        httpClient.connectionPool().evictAll();
    }
}
Also used : OkHttpClient(okhttp3.OkHttpClient) StatementClient(io.prestosql.client.StatementClient) DataCenterStatementClient(io.prestosql.client.DataCenterStatementClient) StatementClientFactory.newStatementClient(io.prestosql.client.StatementClientFactory.newStatementClient) DataCenterClientSession(io.prestosql.client.DataCenterClientSession) Duration(io.airlift.units.Duration)

Example 28 with OkHttpClient

use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project che-server by eclipse-che.

the class KubernetesClientFactory method create.

/**
 * Creates instance of {@link KubernetesClient} that uses an {@link OkHttpClient} instance derived
 * from the shared {@code httpClient} instance in which interceptors are overridden to
 * authenticate with the credentials (user/password or Oauth token) contained in the {@code
 * config} parameter.
 */
protected BaseKubernetesClient<?> create(Config config) {
    OkHttpClient clientHttpClient = httpClient.newBuilder().authenticator(Authenticator.NONE).build();
    OkHttpClient.Builder builder = clientHttpClient.newBuilder();
    builder.interceptors().clear();
    builder.addInterceptor(buildKubernetesInterceptor(config)).addInterceptor(new ImpersonatorInterceptor(config));
    initializeRequestTracing(builder);
    clientHttpClient = builder.build();
    return new UnclosableKubernetesClient(clientHttpClient, config);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) ImpersonatorInterceptor(io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor)

Example 29 with OkHttpClient

use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project Sentinel by alibaba.

the class SentinelOkHttpInterceptorTest method testSentinelOkHttpInterceptor0.

@Test
public void testSentinelOkHttpInterceptor0() throws Exception {
    // With prefix
    SentinelOkHttpConfig config = new SentinelOkHttpConfig("okhttp:");
    String url0 = "http://localhost:" + port + "/okhttp/back";
    OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new SentinelOkHttpInterceptor(config)).build();
    Request request = new Request.Builder().url(url0).build();
    System.out.println(client.newCall(request).execute().body().string());
    ClusterNode cn = ClusterBuilderSlot.getClusterNode(config.getResourcePrefix() + "GET:" + url0);
    assertNotNull(cn);
    Constants.ROOT.removeChildList();
    ClusterBuilderSlot.getClusterNodeMap().clear();
}
Also used : ClusterNode(com.alibaba.csp.sentinel.node.ClusterNode) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 30 with OkHttpClient

use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project titus-control-plane by Netflix.

the class StdKubeApiClients method createApiClient.

public static ApiClient createApiClient(String kubeApiServerUrl, String kubeConfigPath, String metricsNamePrefix, TitusRuntime titusRuntime, Function<Request, String> uriMapper, long readTimeoutMs, boolean enableCompressionForKubeApiClient) {
    OkHttpMetricsInterceptor metricsInterceptor = new OkHttpMetricsInterceptor(metricsNamePrefix, titusRuntime.getRegistry(), titusRuntime.getClock(), uriMapper);
    ApiClient client;
    if (Strings.isNullOrEmpty(kubeApiServerUrl)) {
        try {
            if (Strings.isNullOrEmpty(kubeConfigPath)) {
                client = Config.defaultClient();
            } else {
                client = Config.fromConfig(kubeConfigPath);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        client = Config.fromUrl(kubeApiServerUrl);
    }
    OkHttpClient.Builder newBuilder = client.getHttpClient().newBuilder();
    // See: https://github.com/kubernetes-client/java/pull/960
    newBuilder.protocols(Collections.singletonList(Protocol.HTTP_1_1)).addInterceptor(metricsInterceptor).readTimeout(readTimeoutMs, TimeUnit.SECONDS);
    // By default compression is enabled in OkHttpClient
    if (!enableCompressionForKubeApiClient) {
        newBuilder.addInterceptor(new DisableCompressionInterceptor());
    }
    client.setHttpClient(newBuilder.build());
    return client;
}
Also used : OkHttpClient(okhttp3.OkHttpClient) OkHttpMetricsInterceptor(com.netflix.titus.runtime.connector.kubernetes.okhttp.OkHttpMetricsInterceptor) IOException(java.io.IOException) DisableCompressionInterceptor(com.netflix.titus.runtime.connector.kubernetes.okhttp.DisableCompressionInterceptor) ApiClient(io.kubernetes.client.openapi.ApiClient)

Aggregations

OkHttpClient (okhttp3.OkHttpClient)1944 Request (okhttp3.Request)1024 Response (okhttp3.Response)880 IOException (java.io.IOException)567 Test (org.junit.Test)365 Call (okhttp3.Call)290 RequestBody (okhttp3.RequestBody)222 Test (org.junit.jupiter.api.Test)145 Retrofit (retrofit2.Retrofit)138 File (java.io.File)132 HttpUrl (okhttp3.HttpUrl)131 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)128 Callback (okhttp3.Callback)117 JSONObject (org.json.JSONObject)110 ArrayList (java.util.ArrayList)106 ResponseBody (okhttp3.ResponseBody)105 Gson (com.google.gson.Gson)98 MediaType (okhttp3.MediaType)98 List (java.util.List)92 Map (java.util.Map)85