CachedFsClient implements FsClient, EventloopService { public Promise<MemSize> getTotalCacheSize() { return cacheClient.list("**") .then(list -> Promise.of(MemSize.of(list.stream().mapToLong(FileMetadata::getSize).sum()))); } private  CachedFsClient(Eventloop eventloop, FsClient mainClient, FsClient cacheClient, Comparator<FullCacheStat> comparator); static CachedFsClient create(FsClient mainClient, FsClient cacheClient, Comparator<FullCacheStat> comparator); CachedFsClient with(@NotNull MemSize cacheSizeLimit); CachedFsClient with(@NotNull CurrentTimeProvider timeProvider); Promise<Void> setCacheSizeLimit(@NotNull MemSize cacheSizeLimit); MemSize getCacheSizeLimit(); Promise<MemSize> getTotalCacheSize(); @NotNull @Override Eventloop getEventloop(); @NotNull @Override Promise<Void> start(); @Override Promise<ChannelConsumer<ByteBuf>> upload(@NotNull String name, long offset); @Override Promise<ChannelConsumer<ByteBuf>> upload(@NotNull String name, long offset, long revision); @Override Promise<ChannelSupplier<ByteBuf>> download(@NotNull String name, long offset, long length);  }
@Test public void testEnsureCapacity() throws IOException { MemSize sizeLimit = MemSize.kilobytes(50); initializeCacheDownloadFiles(20, "testFile_"); MemSize cacheSize = await(cacheRemote.getTotalCacheSize()); assertTrue(sizeLimit.toLong() >= cacheSize.toLong()); }