use of com.facebook.presto.cache.CacheManager in project presto by prestodb.
the class TestFileMergeCacheManager method testBasic.
@Test(timeOut = 30_000)
public void testBasic() throws InterruptedException, ExecutionException, IOException {
TestingCacheStats stats = new TestingCacheStats();
CacheManager cacheManager = fileMergeCacheManager(stats);
byte[] buffer = new byte[1024];
// new read
assertFalse(readFully(cacheManager, NO_CACHE_CONSTRAINTS, 42, buffer, 0, 100));
assertEquals(stats.getCacheMiss(), 1);
assertEquals(stats.getCacheHit(), 0);
stats.trigger();
assertEquals(stats.getInMemoryRetainedBytes(), 0);
validateBuffer(data, 42, buffer, 0, 100);
// within the range of the cache
assertTrue(readFully(cacheManager, NO_CACHE_CONSTRAINTS, 47, buffer, 0, 90));
assertEquals(stats.getCacheMiss(), 1);
assertEquals(stats.getCacheHit(), 1);
assertEquals(stats.getInMemoryRetainedBytes(), 0);
validateBuffer(data, 47, buffer, 0, 90);
// partially within the range of the cache
assertFalse(readFully(cacheManager, NO_CACHE_CONSTRAINTS, 52, buffer, 0, 100));
assertEquals(stats.getCacheMiss(), 2);
assertEquals(stats.getCacheHit(), 1);
stats.trigger();
assertEquals(stats.getInMemoryRetainedBytes(), 0);
validateBuffer(data, 52, buffer, 0, 100);
// partially within the range of the cache
assertFalse(readFully(cacheManager, NO_CACHE_CONSTRAINTS, 32, buffer, 10, 50));
assertEquals(stats.getCacheMiss(), 3);
assertEquals(stats.getCacheHit(), 1);
stats.trigger();
assertEquals(stats.getInMemoryRetainedBytes(), 0);
validateBuffer(data, 32, buffer, 10, 50);
// create a hole within two caches
assertFalse(readFully(cacheManager, NO_CACHE_CONSTRAINTS, 200, buffer, 40, 50));
assertEquals(stats.getCacheMiss(), 4);
assertEquals(stats.getCacheHit(), 1);
stats.trigger();
assertEquals(stats.getInMemoryRetainedBytes(), 0);
validateBuffer(data, 200, buffer, 40, 50);
// use a range to cover the hole
assertFalse(readFully(cacheManager, NO_CACHE_CONSTRAINTS, 40, buffer, 400, 200));
assertEquals(stats.getCacheMiss(), 5);
assertEquals(stats.getCacheHit(), 1);
stats.trigger();
assertEquals(stats.getInMemoryRetainedBytes(), 0);
validateBuffer(data, 40, buffer, 400, 200);
}
use of com.facebook.presto.cache.CacheManager in project presto by prestodb.
the class TestFileMergeCacheManager method testQuota.
@Test(timeOut = 30_000)
public void testQuota() throws InterruptedException, ExecutionException, IOException {
TestingCacheStats stats = new TestingCacheStats();
CacheManager cacheManager = fileMergeCacheManager(stats);
byte[] buffer = new byte[10240];
CacheQuota cacheQuota = new CacheQuota("test.table", Optional.of(DataSize.succinctDataSize(1, KILOBYTE)));
// read within the cache quota
assertFalse(readFully(cacheManager, cacheQuota, 42, buffer, 0, 100));
assertEquals(stats.getCacheMiss(), 1);
assertEquals(stats.getCacheHit(), 0);
assertEquals(stats.getQuotaExceed(), 0);
stats.trigger();
assertEquals(stats.getInMemoryRetainedBytes(), 0);
validateBuffer(data, 42, buffer, 0, 100);
// read beyond cache quota
assertFalse(readFully(cacheManager, cacheQuota, 47, buffer, 0, 9000));
assertEquals(stats.getCacheMiss(), 1);
assertEquals(stats.getCacheHit(), 0);
assertEquals(stats.getQuotaExceed(), 1);
assertEquals(stats.getInMemoryRetainedBytes(), 0);
validateBuffer(data, 47, buffer, 0, 90);
// previous data won't be evicted if last read exceed quota
assertTrue(readFully(cacheManager, cacheQuota, 47, buffer, 0, 90));
assertEquals(stats.getCacheMiss(), 1);
assertEquals(stats.getCacheHit(), 1);
assertEquals(stats.getQuotaExceed(), 1);
assertEquals(stats.getInMemoryRetainedBytes(), 0);
validateBuffer(data, 47, buffer, 0, 90);
}
use of com.facebook.presto.cache.CacheManager in project presto by prestodb.
the class TestFileMergeCacheManager method testStress.
@Test(invocationCount = 10)
public void testStress() throws ExecutionException, InterruptedException {
CacheConfig cacheConfig = new CacheConfig().setBaseDirectory(cacheDirectory);
FileMergeCacheConfig fileMergeCacheConfig = new FileMergeCacheConfig().setCacheTtl(new Duration(10, MILLISECONDS));
CacheManager cacheManager = fileMergeCacheManager(cacheConfig, fileMergeCacheConfig);
stressTest(data, (position, buffer, offset, length) -> readFully(cacheManager, NO_CACHE_CONSTRAINTS, position, buffer, offset, length));
}
Aggregations