@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) {
      // Just catching IOException isn't enough.
      // RPC call can throw ConnectionException.
      // We don't handle different exceptions separately at this point.
      throw new YarnException(e);
    }
    if (resourcePath != null) {
      URL pathURL = URL.fromPath(resourcePath);
      return pathURL;
    } else {
      // The resource was not in the cache.
      return null;
    }
  }
@Test
  public void testUseCacheHit() throws Exception {
    Path file = new Path("viewfs://test/path");
    URL useUrl = URL.fromPath(new Path("viewfs://test/path"));
    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);
  }