From 1d8c507684a47bd298c6f090ee387fc246a337d8 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Sat, 17 Mar 2018 20:08:03 -0400 Subject: [PATCH] Client: Add missing test Previously I added wrapping for an SSL exception without a test. That was lame. This adds the test. --- .../client/SyncResponseListenerTests.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/client/rest/src/test/java/org/elasticsearch/client/SyncResponseListenerTests.java b/client/rest/src/test/java/org/elasticsearch/client/SyncResponseListenerTests.java index f9406a6c490..683b23a596a 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/SyncResponseListenerTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/SyncResponseListenerTests.java @@ -35,6 +35,7 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.net.SocketTimeoutException; import java.net.URISyntaxException; +import javax.net.ssl.SSLHandshakeException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -211,6 +212,23 @@ public class SyncResponseListenerTests extends RestClientTestCase { } } + public void testSSLHandshakeExceptionIsWrapped() throws Exception { + RestClient.SyncResponseListener syncResponseListener = new RestClient.SyncResponseListener(10000); + SSLHandshakeException exception = new SSLHandshakeException(randomAsciiAlphanumOfLength(5)); + syncResponseListener.onFailure(exception); + try { + syncResponseListener.get(); + fail("get should have failed"); + } catch (SSLHandshakeException e) { + // We preserve the original exception in the cause + assertSame(exception, e.getCause()); + // We copy the message + assertEquals(exception.getMessage(), e.getMessage()); + // And we do all that so the thrown exception has our method in the stacktrace + assertExceptionStackContainsCallingMethod(e); + } + } + public void testIOExceptionIsBuiltCorrectly() throws Exception { RestClient.SyncResponseListener syncResponseListener = new RestClient.SyncResponseListener(10000); IOException ioException = new IOException();