@Test
public void testClientRetriesWithSSLHandshakeExceptionFailsAtEveryAttempt()
    throws Exception {

  Configuration conf = new Configuration();
  conf.setInt(
      CommonConfigurationKeysPublic.KMS_CLIENT_FAILOVER_MAX_RETRIES_KEY, 2);
  final String keyName = "test";
  final String exceptionMessage = "p1 exception message";
  KMSClientProvider p1 = mock(KMSClientProvider.class);
  Exception originalSslEx = new SSLHandshakeException(exceptionMessage);
  when(p1.createKey(Mockito.anyString(), Mockito.any(Options.class)))
      .thenThrow(originalSslEx);
  KMSClientProvider p2 = mock(KMSClientProvider.class);
  when(p2.createKey(Mockito.anyString(), Mockito.any(Options.class)))
      .thenThrow(new ConnectException("p2 exception message"));
  when(p1.getKMSUrl()).thenReturn("p1");
  when(p2.getKMSUrl()).thenReturn("p2");
  LoadBalancingKMSClientProvider kp = new LoadBalancingKMSClientProvider(
      new KMSClientProvider[] {p1, p2}, 0, conf);
  Exception interceptedEx = intercept(ConnectException.class,
      "SSLHandshakeException: " + exceptionMessage,
      ()-> kp.createKey(keyName, new Options(conf)));
  assertEquals(originalSslEx, interceptedEx.getCause());
  verify(p1, Mockito.times(2)).createKey(Mockito.eq(keyName),
      Mockito.any(Options.class));
  verify(p2, Mockito.times(1)).createKey(Mockito.eq(keyName),
      Mockito.any(Options.class));
}