### Question:
DFSClientCache { DFSClient getDfsClient(String userName) { DFSClient client = null; try { client = clientCache.get(userName); } catch (ExecutionException e) { LOG.error("Failed to create DFSClient for user:" + userName + " Cause:" + e); } return client; } DFSClientCache(NfsConfiguration config);   DFSClientCache(NfsConfiguration config, int clientCache); void invalidateDfsInputStream(String userName, String inodePath); static final int SHUTDOWN_HOOK_PRIORITY; }### Answer:
@Test public void testEviction() throws IOException { NfsConfiguration conf = new NfsConfiguration(); conf.set(FileSystem.FS_DEFAULT_NAME_KEY, "hdfs: final int MAX_CACHE_SIZE = 2; DFSClientCache cache = new DFSClientCache(conf, MAX_CACHE_SIZE); DFSClient c1 = cache.getDfsClient("test1"); assertTrue(cache.getDfsClient("test1").toString().contains("ugi=test1")); assertEquals(c1, cache.getDfsClient("test1")); assertFalse(isDfsClientClose(c1)); cache.getDfsClient("test2"); assertTrue(isDfsClientClose(c1)); assertEquals(MAX_CACHE_SIZE - 1, cache.clientCache.size()); }
@Test public void testEviction() throws IOException { NfsConfiguration conf = new NfsConfiguration(); conf.set(FileSystem.FS_DEFAULT_NAME_KEY, "hdfs: final int MAX_CACHE_SIZE = 1; DFSClientCache cache = new DFSClientCache(conf, MAX_CACHE_SIZE); DFSClient c1 = cache.getDfsClient("test1"); assertTrue(cache.getDfsClient("test1").toString().contains("ugi=test1")); assertEquals(c1, cache.getDfsClient("test1")); assertFalse(isDfsClientClose(c1)); cache.getDfsClient("test2"); assertTrue(isDfsClientClose(c1)); assertTrue("cache size should be the max size or less", cache.clientCache.size() <= MAX_CACHE_SIZE); }