InMemorySCMStore extends SCMStore { @Override public String addResource(String key, String fileName) { String interned = intern(key); synchronized (interned) { SharedCacheResource resource = cachedResources.get(interned); if (resource == null) { resource = new SharedCacheResource(fileName); cachedResources.put(interned, resource); } return resource.getFileName(); } } InMemorySCMStore(); @VisibleForTesting  InMemorySCMStore(AppChecker appChecker); @Override String addResource(String key, String fileName); @Override String addResourceReference(String key,
      SharedCacheResourceReference ref); @Override Collection<SharedCacheResourceReference> getResourceReferences(String key); @Override boolean removeResourceReference(String key, SharedCacheResourceReference ref,
      boolean updateAccessTime); @Override void removeResourceReferences(String key,
      Collection<SharedCacheResourceReference> refs, boolean updateAccessTime); @Override void cleanResourceReferences(String key); @Override boolean removeResource(String key); @Override boolean isResourceEvictable(String key, FileStatus file);  }
@Test public void testAddResourceConcurrency() throws Exception { startEmptyStore(); final String key = "key1"; int count = 5; ExecutorService exec = Executors.newFixedThreadPool(count); List<Future<String>> futures = new ArrayList<Future<String>>(count); final CountDownLatch start = new CountDownLatch(1); for (int i = 0; i < count; i++) { final String fileName = "foo-" + i + ".jar"; Callable<String> task = new Callable<String>() { public String call() throws Exception { start.await(); String result = store.addResource(key, fileName); System.out.println("fileName: " + fileName + ", result: " + result); return result; } }; futures.add(exec.submit(task)); } start.countDown(); Set<String> results = new HashSet<String>(); for (Future<String> future: futures) { results.add(future.get()); } assertSame(1, results.size()); exec.shutdown(); }