mirror of
https://github.com/zhigang1992/AndroidVideoCache.git
synced 2026-01-30 16:49:00 +08:00
#112: touch file to check is cache trimming is required after cache completion
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -365,6 +365,6 @@ public class HttpProxyCacheServerTest extends BaseTest {
|
||||
}
|
||||
|
||||
private void waitForAsyncTrimming() throws InterruptedException {
|
||||
Thread.sleep(500);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user