#112: touch file to check is cache trimming is required after cache completion

This commit is contained in:
Alexey Danilov
2017-04-21 17:20:04 +03:00
parent e0ee4a7dde
commit 01bba67289
3 changed files with 6 additions and 4 deletions

View File

@@ -100,6 +100,7 @@ public class FileCache implements Cache {
file = completedFile; file = completedFile;
try { try {
dataFile = new RandomAccessFile(file, "r"); dataFile = new RandomAccessFile(file, "r");
diskUsage.touch(file);
} catch (IOException e) { } catch (IOException e) {
throw new ProxyCacheException("Error opening " + file + " as disc cache", e); throw new ProxyCacheException("Error opening " + file + " as disc cache", e);
} }

View File

@@ -365,6 +365,6 @@ public class HttpProxyCacheServerTest extends BaseTest {
} }
private void waitForAsyncTrimming() throws InterruptedException { private void waitForAsyncTrimming() throws InterruptedException {
Thread.sleep(500); Thread.sleep(100);
} }
} }

View File

@@ -161,14 +161,15 @@ public class FileCacheTest extends BaseTest {
public void testTrimAfterCompletionForTotalSizeLru() throws Exception { public void testTrimAfterCompletionForTotalSizeLru() throws Exception {
File cacheDir = newCacheFile(); File cacheDir = newCacheFile();
byte[] data = loadAssetFile(ASSETS_DATA_NAME); 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, saveAndCompleteCache(diskUsage, data,
new File(cacheDir, "0.dat"), new File(cacheDir, "0.dat"),
new File(cacheDir, "1.dat"), new File(cacheDir, "1.dat"),
new File(cacheDir, "2.dat") new File(cacheDir, "2.dat")
); );
waitForAsyncTrimming(); 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 { 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 { private void waitForAsyncTrimming() throws InterruptedException {
Thread.sleep(500); Thread.sleep(100);
} }
} }