LoadBalancingKMSClientProvider extends KeyProvider implements
    CryptoExtension,
    KeyProviderDelegationTokenExtension.DelegationTokenExtension { @Override public List<KeyVersion> getKeyVersions(final String name) throws IOException { return doOp(new ProviderCallable<List<KeyVersion>>() { @Override public List<KeyVersion> call(KMSClientProvider provider) throws IOException { return provider.getKeyVersions(name); } }, nextIdx(), true); } LoadBalancingKMSClientProvider(URI providerUri,
      KMSClientProvider[] providers, Configuration conf); @VisibleForTesting  LoadBalancingKMSClientProvider(KMSClientProvider[] providers, long seed,
      Configuration conf); private  LoadBalancingKMSClientProvider(URI uri,
      KMSClientProvider[] providers, long seed, Configuration conf); @VisibleForTesting KMSClientProvider[] getProviders(); @Override org.apache.hadoop.security.token.Token<? extends TokenIdentifier> selectDelegationToken(Credentials creds); @Override String getCanonicalServiceName(); @Override Token<?> getDelegationToken(String renewer); @Override long renewDelegationToken(final Token<?> token); @Override Void cancelDelegationToken(final Token<?> token); @Override void warmUpEncryptedKeys(String... keyNames); @Override void drain(String keyName); @Override void invalidateCache(String keyName); @Override EncryptedKeyVersion generateEncryptedKey(final String encryptionKeyName); @Override KeyVersion decryptEncryptedKey(final EncryptedKeyVersion encryptedKeyVersion); @Override EncryptedKeyVersion reencryptEncryptedKey(
      final EncryptedKeyVersion ekv); @Override void reencryptEncryptedKeys(final List<EncryptedKeyVersion> ekvs); @Override KeyVersion getKeyVersion(final String versionName); @Override List<String> getKeys(); @Override Metadata[] getKeysMetadata(final String... names); @Override List<KeyVersion> getKeyVersions(final String name); @Override KeyVersion getCurrentKey(final String name); @Override Metadata getMetadata(final String name); @Override KeyVersion createKey(final String name, final byte[] material,
      final Options options); @Override KeyVersion createKey(final String name, final Options options); @Override void deleteKey(final String name); @Override KeyVersion rollNewVersion(final String name, final byte[] material); @Override KeyVersion rollNewVersion(final String name); @Override void close(); @Override void flush(); static Logger LOG; }
@Test public void testClientRetriesIdempotentOpWithSocketTimeoutExceptionFails() 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 originalEx = new SocketTimeoutException(exceptionMessage); when(p1.getKeyVersions(Mockito.anyString())) .thenThrow(originalEx); KMSClientProvider p2 = mock(KMSClientProvider.class); when(p2.getKeyVersions(Mockito.anyString())) .thenThrow(new SocketTimeoutException("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(SocketTimeoutException.class, "SocketTimeoutException: " + exceptionMessage, ()-> kp.getKeyVersions(keyName)); assertEquals(originalEx, interceptedEx); verify(p1, Mockito.times(2)) .getKeyVersions(Mockito.eq(keyName)); verify(p2, Mockito.times(1)) .getKeyVersions(Mockito.eq(keyName)); }