From 01bba672892f447257e8ece2ff748dcf84cbdf4b Mon Sep 17 00:00:00 2001 From: Alexey Danilov Date: Fri, 21 Apr 2017 17:20:04 +0300 Subject: [PATCH] #112: touch file to check is cache trimming is required after cache completion --- .../main/java/com/danikula/videocache/file/FileCache.java | 1 + .../com/danikula/videocache/HttpProxyCacheServerTest.java | 2 +- .../java/com/danikula/videocache/file/FileCacheTest.java | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/src/main/java/com/danikula/videocache/file/FileCache.java b/library/src/main/java/com/danikula/videocache/file/FileCache.java index dc4a68e..62de7ab 100644 --- a/library/src/main/java/com/danikula/videocache/file/FileCache.java +++ b/library/src/main/java/com/danikula/videocache/file/FileCache.java @@ -100,6 +100,7 @@ public class FileCache implements Cache { file = completedFile; try { dataFile = new RandomAccessFile(file, "r"); + diskUsage.touch(file); } catch (IOException e) { throw new ProxyCacheException("Error opening " + file + " as disc cache", e); } diff --git a/test/src/test/java/com/danikula/videocache/HttpProxyCacheServerTest.java b/test/src/test/java/com/danikula/videocache/HttpProxyCacheServerTest.java index 116ef91..746d3b6 100644 --- a/test/src/test/java/com/danikula/videocache/HttpProxyCacheServerTest.java +++ b/test/src/test/java/com/danikula/videocache/HttpProxyCacheServerTest.java @@ -365,6 +365,6 @@ public class HttpProxyCacheServerTest extends BaseTest { } private void waitForAsyncTrimming() throws InterruptedException { - Thread.sleep(500); + Thread.sleep(100); } } diff --git a/test/src/test/java/com/danikula/videocache/file/FileCacheTest.java b/test/src/test/java/com/danikula/videocache/file/FileCacheTest.java index 41fa13f..98a9150 100644 --- a/test/src/test/java/com/danikula/videocache/file/FileCacheTest.java +++ b/test/src/test/java/com/danikula/videocache/file/FileCacheTest.java @@ -161,14 +161,15 @@ public class FileCacheTest extends BaseTest { public void testTrimAfterCompletionForTotalSizeLru() throws Exception { File cacheDir = newCacheFile(); byte[] data = loadAssetFile(ASSETS_DATA_NAME); - DiskUsage diskUsage = new TotalSizeLruDiskUsage(data.length*3-1); + DiskUsage diskUsage = new TotalSizeLruDiskUsage(data.length * 3 - 1); saveAndCompleteCache(diskUsage, data, new File(cacheDir, "0.dat"), new File(cacheDir, "1.dat"), new File(cacheDir, "2.dat") ); waitForAsyncTrimming(); - assertThat(new File(cacheDir, "0.dat")).doesNotExist(); + File deletedFile = new File(cacheDir, "0.dat"); + assertThat(deletedFile).doesNotExist(); } private void saveAndCompleteCache(DiskUsage diskUsage, byte[] data, File... files) throws ProxyCacheException, IOException { @@ -181,6 +182,6 @@ public class FileCacheTest extends BaseTest { } private void waitForAsyncTrimming() throws InterruptedException { - Thread.sleep(500); + Thread.sleep(100); } }