UploadStagingCache implements Closeable { public Optional<SettableFuture<Integer>> put(String id, File input) { return putOptionalDisregardingSize(id, input, false); } private  UploadStagingCache(File dir, File home, int uploadThreads, long size /* bytes */,
        StagingUploader uploader, @Nullable FileCache cache, StatisticsProvider statisticsProvider,
        @Nullable ListeningExecutorService executor,
        @Nullable ScheduledExecutorService scheduledExecutor,
        int purgeInterval /* secs */, int retryInterval /* secs */); private  UploadStagingCache(); static UploadStagingCache build(File dir, File home, int uploadThreads, long size
        /* bytes */, StagingUploader uploader, @Nullable FileCache cache,
        StatisticsProvider statisticsProvider, @Nullable ListeningExecutorService executor,
        @Nullable ScheduledExecutorService scheduledExecutor, int purgeInterval /* secs */,
        int retryInterval /* secs */); Optional<SettableFuture<Integer>> put(String id, File input); @Nullable File getIfPresent(String key); DataStoreCacheStatsMBean getStats(); @Override void close();  }
@Test public void testAdd() throws Exception { List<ListenableFuture<Integer>> futures = put(folder); taskLatch.countDown(); callbackLatch.countDown(); assertFuture(futures, 0); assertCacheStats(stagingCache, 0, 0, 1, 1); }
@Test public void testConcurrentSameAdd() throws Exception { LOG.info("Starting testConcurrentSameAdd"); List<ListenableFuture<Integer>> futures = put(folder); File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile()); Optional<SettableFuture<Integer>> future2 = stagingCache.put(ID_PREFIX + 0, f); assertTrue(future2.isPresent()); assertEquals(future2.get().get().intValue(), 0); taskLatch.countDown(); callbackLatch.countDown(); assertFuture(futures, 0); assertCacheStats(stagingCache, 0, 0, 1, 2); LOG.info("Finished testConcurrentSameAdd"); }
@Test public void testConcurrentDifferentAdd() throws Exception { List<ListenableFuture<Integer>> futures = put(folder); File f2 = copyToFile(randomStream(1, 4 * 1024), folder.newFile()); Optional<SettableFuture<Integer>> future2 = stagingCache.put(ID_PREFIX + 1, f2); if (future2.isPresent()) { futures.add(future2.get()); } taskLatch.countDown(); callbackLatch.countDown(); assertFuture(futures, 0, 1); assertCacheStats(stagingCache, 0, 0, 2, 2); }