SharedCacheUploaderService extends AbstractService implements SCMUploaderProtocol { @Override public SCMUploaderNotifyResponse notify(SCMUploaderNotifyRequest request) throws YarnException, IOException { SCMUploaderNotifyResponse response = recordFactory.newRecordInstance(SCMUploaderNotifyResponse.class); String filename = store.addResource(request.getResourceKey(), request.getFileName()); boolean accepted = filename.equals(request.getFileName()); if (accepted) { this.metrics.incAcceptedUploads(); } else { this.metrics.incRejectedUploads(); } response.setAccepted(accepted); return response; } SharedCacheUploaderService(SCMStore store); @Override SCMUploaderNotifyResponse notify(SCMUploaderNotifyRequest request); @Override SCMUploaderCanUploadResponse canUpload(
      SCMUploaderCanUploadRequest request);  }
@Test public void testNotify_noEntry() throws Exception { long accepted = SharedCacheUploaderMetrics.getInstance().getAcceptedUploads(); SCMUploaderNotifyRequest request = recordFactory.newRecordInstance(SCMUploaderNotifyRequest.class); request.setResourceKey("key1"); request.setFilename("foo.jar"); assertTrue(proxy.notify(request).getAccepted()); Collection<SharedCacheResourceReference> set = store.getResourceReferences("key1"); assertNotNull(set); assertEquals(0, set.size()); assertEquals( "NM upload metrics aren't updated.", 1, SharedCacheUploaderMetrics.getInstance().getAcceptedUploads() - accepted); }
@Test public void testNotify_entryExists_differentName() throws Exception { long rejected = SharedCacheUploaderMetrics.getInstance().getRejectUploads(); store.addResource("key1", "foo.jar"); SCMUploaderNotifyRequest request = recordFactory.newRecordInstance(SCMUploaderNotifyRequest.class); request.setResourceKey("key1"); request.setFilename("foobar.jar"); assertFalse(proxy.notify(request).getAccepted()); Collection<SharedCacheResourceReference> set = store.getResourceReferences("key1"); assertNotNull(set); assertEquals(0, set.size()); assertEquals( "NM upload metrics aren't updated.", 1, SharedCacheUploaderMetrics.getInstance().getRejectUploads() - rejected); }
@Test public void testNotify_entryExists_sameName() throws Exception { long accepted = SharedCacheUploaderMetrics.getInstance().getAcceptedUploads(); store.addResource("key1", "foo.jar"); SCMUploaderNotifyRequest request = recordFactory.newRecordInstance(SCMUploaderNotifyRequest.class); request.setResourceKey("key1"); request.setFilename("foo.jar"); assertTrue(proxy.notify(request).getAccepted()); Collection<SharedCacheResourceReference> set = store.getResourceReferences("key1"); assertNotNull(set); assertEquals(0, set.size()); assertEquals( "NM upload metrics aren't updated.", 1, SharedCacheUploaderMetrics.getInstance().getAcceptedUploads() - accepted); }