Skip to content

Commit 1d8c507

Browse files
committed
Client: Add missing test
Previously I added wrapping for an SSL exception without a test. That was lame. This adds the test.
1 parent f1029aa commit 1d8c507

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

client/rest/src/test/java/org/elasticsearch/client/SyncResponseListenerTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.StringWriter;
3636
import java.net.SocketTimeoutException;
3737
import java.net.URISyntaxException;
38+
import javax.net.ssl.SSLHandshakeException;
3839

3940
import static org.junit.Assert.assertEquals;
4041
import static org.junit.Assert.assertNotNull;
@@ -211,6 +212,23 @@ public void testConnectionClosedExceptionIsWrapped() throws Exception {
211212
}
212213
}
213214

215+
public void testSSLHandshakeExceptionIsWrapped() throws Exception {
216+
RestClient.SyncResponseListener syncResponseListener = new RestClient.SyncResponseListener(10000);
217+
SSLHandshakeException exception = new SSLHandshakeException(randomAsciiAlphanumOfLength(5));
218+
syncResponseListener.onFailure(exception);
219+
try {
220+
syncResponseListener.get();
221+
fail("get should have failed");
222+
} catch (SSLHandshakeException e) {
223+
// We preserve the original exception in the cause
224+
assertSame(exception, e.getCause());
225+
// We copy the message
226+
assertEquals(exception.getMessage(), e.getMessage());
227+
// And we do all that so the thrown exception has our method in the stacktrace
228+
assertExceptionStackContainsCallingMethod(e);
229+
}
230+
}
231+
214232
public void testIOExceptionIsBuiltCorrectly() throws Exception {
215233
RestClient.SyncResponseListener syncResponseListener = new RestClient.SyncResponseListener(10000);
216234
IOException ioException = new IOException();

0 commit comments

Comments
 (0)