KeyProviderCache { public KeyProvider get(final Configuration conf) { URI kpURI = createKeyProviderURI(conf); if (kpURI == null) { return null; } try { return cache.get(kpURI, new Callable<KeyProvider>() { @Override public KeyProvider call() throws Exception { return DFSUtil.createKeyProvider(conf); } }); } catch (Exception e) { LOG.error("Could not create KeyProvider for DFSClient !!", e.getCause()); return null; } } KeyProviderCache(long expiryMs); KeyProvider get(final Configuration conf); @VisibleForTesting void setKeyProvider(Configuration conf, KeyProvider keyProvider); static final Log LOG; }
@Test public void testCache() throws Exception { KeyProviderCache kpCache = new KeyProviderCache(10000); Configuration conf = new Configuration(); conf.set(DFSConfigKeys.DFS_ENCRYPTION_KEY_PROVIDER_URI, "dummy: KeyProvider keyProvider1 = kpCache.get(conf); Assert.assertNotNull("Returned Key Provider is null !!", keyProvider1); conf.set(DFSConfigKeys.DFS_ENCRYPTION_KEY_PROVIDER_URI, "dummy: KeyProvider keyProvider2 = kpCache.get(conf); Assert.assertTrue("Different KeyProviders returned !!", keyProvider1 == keyProvider2); conf.set(DFSConfigKeys.DFS_ENCRYPTION_KEY_PROVIDER_URI, "dummy: KeyProvider keyProvider3 = kpCache.get(conf); Assert.assertFalse("Same KeyProviders returned !!", keyProvider1 == keyProvider3); conf.set(DFSConfigKeys.DFS_ENCRYPTION_KEY_PROVIDER_URI, "dummy: KeyProvider keyProvider4 = kpCache.get(conf); Assert.assertFalse("Same KeyProviders returned !!", keyProvider1 == keyProvider4); }