CachedFsClient implements FsClient, EventloopService { public Promise<Void> setCacheSizeLimit(@NotNull MemSize cacheSizeLimit) { this.cacheSizeLimit = cacheSizeLimit; return ensureSpace(); } 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 testSetCacheSizeLimit() throws IOException { MemSize sizeLimit = MemSize.kilobytes(50); initializeCacheDownloadFiles(20, "testFile_"); MemSize cacheSize = await(cacheRemote.getTotalCacheSize()); assertTrue(sizeLimit.toLong() >= cacheSize.toLong()); MemSize newSizeLimit = MemSize.kilobytes(20); await(cacheRemote.setCacheSizeLimit(newSizeLimit)); MemSize newCacheSize = await(cacheRemote.getTotalCacheSize()); assertTrue(newSizeLimit.toLong() >= newCacheSize.toLong()); }
@Test public void testLRUComparator() throws IOException { cacheRemote.setCacheSizeLimit(MemSize.kilobytes(100)); initializeCacheDownloadFiles(5, "testFile_"); initializeFiles(20, "newTestFile_"); downloadFiles(20, 1, "newTestFile_"); List<FileMetadata> list = await(cache.list("**")); list.forEach(val -> assertTrue(val.getName().startsWith("new"))); }