SharedCacheClientImpl extends SharedCacheClient { @Override public URL use(ApplicationId applicationId, String resourceKey) throws YarnException { Path resourcePath = null; UseSharedCacheResourceRequest request = Records.newRecord( UseSharedCacheResourceRequest.class); request.setAppId(applicationId); request.setResourceKey(resourceKey); try { UseSharedCacheResourceResponse response = this.scmClient.use(request); if (response != null && response.getPath() != null) { resourcePath = new Path(response.getPath()); } } catch (Exception e) { throw new YarnException(e); } if (resourcePath != null) { URL pathURL = URL.fromPath(resourcePath); return pathURL; } else { return null; } } SharedCacheClientImpl(); @Override URL use(ApplicationId applicationId, String resourceKey); @Override void release(ApplicationId applicationId, String resourceKey); @Override String getFileChecksum(Path sourceFile);  }
@Test public void testUseCacheMiss() throws Exception { UseSharedCacheResourceResponse response = new UseSharedCacheResourceResponsePBImpl(); response.setPath(null); when(cProtocol.use(isA(UseSharedCacheResourceRequest.class))).thenReturn( response); URL newURL = client.use(mock(ApplicationId.class), "key"); assertNull("The path is not null!", newURL); }
@Test public void testUseCacheHit() throws Exception { Path file = new Path("viewfs: URL useUrl = URL.fromPath(new Path("viewfs: UseSharedCacheResourceResponse response = new UseSharedCacheResourceResponsePBImpl(); response.setPath(file.toString()); when(cProtocol.use(isA(UseSharedCacheResourceRequest.class))).thenReturn( response); URL newURL = client.use(mock(ApplicationId.class), "key"); assertEquals("The paths are not equal!", useUrl, newURL); }
@Test(expected = YarnException.class) public void testUseError() throws Exception { String message = "Mock IOExcepiton!"; when(cProtocol.use(isA(UseSharedCacheResourceRequest.class))).thenThrow( new IOException(message)); client.use(mock(ApplicationId.class), "key"); }