|
@@ -42,15 +42,21 @@ import java.security.PrivilegedAction;
|
|
import java.security.cert.Certificate;
|
|
import java.security.cert.Certificate;
|
|
import java.security.cert.CertificateFactory;
|
|
import java.security.cert.CertificateFactory;
|
|
import java.security.spec.PKCS8EncodedKeySpec;
|
|
import java.security.spec.PKCS8EncodedKeySpec;
|
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import javax.net.ssl.KeyManagerFactory;
|
|
import javax.net.ssl.KeyManagerFactory;
|
|
import javax.net.ssl.SSLContext;
|
|
import javax.net.ssl.SSLContext;
|
|
import javax.net.ssl.SSLHandshakeException;
|
|
import javax.net.ssl.SSLHandshakeException;
|
|
import javax.net.ssl.TrustManagerFactory;
|
|
import javax.net.ssl.TrustManagerFactory;
|
|
|
|
|
|
|
|
+import static org.hamcrest.Matchers.allOf;
|
|
|
|
+import static org.hamcrest.Matchers.containsString;
|
|
import static org.hamcrest.Matchers.instanceOf;
|
|
import static org.hamcrest.Matchers.instanceOf;
|
|
|
|
+import static org.hamcrest.Matchers.startsWith;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertThat;
|
|
import static org.junit.Assert.assertThat;
|
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assert.fail;
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -105,6 +111,40 @@ public class RestClientBuilderIntegTests extends RestClientTestCase {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void testBuilderSetsThreadName() throws Exception {
|
|
|
|
+ assumeFalse("https://github.com/elastic/elasticsearch/issues/49094", inFipsJvm());
|
|
|
|
+ final SSLContext defaultSSLContext = SSLContext.getDefault();
|
|
|
|
+ try {
|
|
|
|
+ SSLContext.setDefault(getSslContext());
|
|
|
|
+ try (RestClient client = buildRestClient()) {
|
|
|
|
+ final CountDownLatch latch = new CountDownLatch(1);
|
|
|
|
+ client.performRequestAsync(new Request("GET", "/"), new ResponseListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onSuccess(Response response) {
|
|
|
|
+ assertThat(
|
|
|
|
+ Thread.currentThread().getName(),
|
|
|
|
+ allOf(
|
|
|
|
+ startsWith(RestClientBuilder.THREAD_NAME_PREFIX),
|
|
|
|
+ containsString("elasticsearch"),
|
|
|
|
+ containsString("rest-client")
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+ assertEquals(200, response.getStatusLine().getStatusCode());
|
|
|
|
+ latch.countDown();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onFailure(Exception exception) {
|
|
|
|
+ throw new AssertionError("unexpected", exception);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
|
|
+ SSLContext.setDefault(defaultSSLContext);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private RestClient buildRestClient() {
|
|
private RestClient buildRestClient() {
|
|
InetSocketAddress address = httpsServer.getAddress();
|
|
InetSocketAddress address = httpsServer.getAddress();
|
|
return RestClient.builder(new HttpHost(address.getHostString(), address.getPort(), "https")).build();
|
|
return RestClient.builder(new HttpHost(address.getHostString(), address.getPort(), "https")).build();
|