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();
}
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();
}
}
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);
}
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();
}
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;
}
Aggregations