SharedCacheClientImpl extends SharedCacheClient { @Override public Path 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); } return resourcePath; } SharedCacheClientImpl(); @Override Path use(ApplicationId applicationId, String resourceKey); @Override void release(ApplicationId applicationId, String resourceKey); @Override String getFileChecksum(Path sourceFile);  }
@Test public void testUse() throws Exception { Path file = new Path("viewfs: UseSharedCacheResourceResponse response = new UseSharedCacheResourceResponsePBImpl(); response.setPath(file.toString()); when(cProtocol.use(isA(UseSharedCacheResourceRequest.class))).thenReturn( response); Path newPath = client.use(mock(ApplicationId.class), "key"); assertEquals(file, newPath); }
@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"); }