use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project pulsar by apache.
the class ProxyAdditionalServletTest method httpGet.
String httpGet(String url) throws IOException {
OkHttpClient client = new OkHttpClient();
okhttp3.Request request = new okhttp3.Request.Builder().get().url(url).build();
try (Response response = client.newCall(request).execute()) {
return response.body().string();
}
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project pulsar by apache.
the class TestPulsarSQLBase method waitPulsarSQLReady.
public void waitPulsarSQLReady() throws Exception {
// wait until presto worker started
ContainerExecResult result;
do {
try {
result = execQuery("show catalogs;");
assertThat(result.getExitCode()).isEqualTo(0);
assertThat(result.getStdout()).contains("pulsar", "system");
break;
} catch (ContainerExecException cee) {
if (cee.getResult().getStderr().contains("Presto server is still initializing")) {
Thread.sleep(10000);
} else {
throw cee;
}
}
} while (true);
// check presto follow workers start finish.
if (pulsarCluster.getSqlFollowWorkerContainers() != null && pulsarCluster.getSqlFollowWorkerContainers().size() > 0) {
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder().url("http://" + pulsarCluster.getPrestoWorkerContainer().getUrl() + "/v1/node").build();
do {
try (Response response = okHttpClient.newCall(request).execute()) {
Assert.assertNotNull(response.body());
String nodeJsonStr = response.body().string();
Assert.assertTrue(nodeJsonStr.length() > 0);
log.info("presto node info: {}", nodeJsonStr);
if (nodeJsonStr.contains("uri")) {
log.info("presto node exist.");
break;
}
Thread.sleep(1000);
}
} while (true);
}
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project teamscale-jacoco-agent by cqse.
the class AgentHttpServerTest method getText.
private String getText(String endpointPath) throws Exception {
OkHttpClient client = new OkHttpClient();
HttpUrl endpointUrl = HttpUrl.get(baseUri.resolve(endpointPath));
Request request = new Request.Builder().url(endpointUrl).build();
Response response = client.newCall(request).execute();
return response.body() != null ? response.body().string() : "";
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project bonita-java-client by bonitasoft.
the class BonitaFeignClientBuilderImplTest method can_provide_custom_http_client.
@Test
void can_provide_custom_http_client() {
// Given
final OkHttpClient customHttpClient = new OkHttpClient();
clientBuilder.okHttpClient(customHttpClient);
// When
clientBuilder.build();
// Then
verify(clientBuilder, never()).configureHttpClient(any());
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project AnkiChinaAndroid by ankichinateam.
the class HttpFetcher method fetchThroughHttp.
public static String fetchThroughHttp(String address, String encoding) {
Timber.d("fetching %s", address);
Response response = null;
try {
Request.Builder requestBuilder = new Request.Builder();
requestBuilder.url(address).get();
Request httpGet = requestBuilder.build();
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
Tls12SocketFactory.enableTls12OnPreLollipop(clientBuilder).connectTimeout(Connection.CONN_TIMEOUT, TimeUnit.SECONDS).writeTimeout(Connection.CONN_TIMEOUT, TimeUnit.SECONDS).readTimeout(Connection.CONN_TIMEOUT, TimeUnit.SECONDS);
OkHttpClient client = clientBuilder.build();
response = client.newCall(httpGet).execute();
if (response.code() != 200) {
Timber.d("Response code was %s, returning failure", response.code());
return "FAILED";
}
BufferedReader reader = new BufferedReader(new InputStreamReader(response.body().byteStream(), Charset.forName(encoding)));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
}
return stringBuilder.toString();
} catch (Exception e) {
Timber.d(e, "Failed with an exception");
return "FAILED with exception: " + e.getMessage();
} finally {
if (response != null && response.body() != null) {
response.body().close();
}
}
}
Aggregations