use of org.teiid.common.buffer.CacheEntry in project teiid by teiid.
the class TestBufferFrontedFileStoreCache method testDefragMin.
@Test
public void testDefragMin() throws Exception {
cache = createLayeredCache(1 << 15, 1 << 15, true, true);
cache.setMinDefrag(10000000);
Serializer<Integer> s = new SimpleSerializer();
WeakReference<? extends Serializer<?>> ref = new WeakReference<Serializer<?>>(s);
cache.createCacheGroup(s.getId());
Integer cacheObject = Integer.valueOf(5000);
for (int i = 0; i < 100; i++) {
CacheEntry ce = new CacheEntry((long) i);
ce.setSerializer(ref);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
cache.add(ce, s);
}
assertEquals(3244032, cache.getDiskUsage());
for (int i = 0; i < 90; i++) {
cache.remove(1l, (long) i);
}
assertEquals(3244032, cache.getDiskUsage());
cache.setMinDefrag(5000);
cache.setTruncateInterval(1);
cache.defragTask.run();
assertEquals(1802240, cache.getDiskUsage());
cache.defragTask.run();
assertEquals(1114112, cache.getDiskUsage());
cache.defragTask.run();
assertEquals(655360, cache.getDiskUsage());
cache.defragTask.run();
// we've reached a stable size
assertEquals(655360, cache.getDiskUsage());
}
use of org.teiid.common.buffer.CacheEntry in project teiid by teiid.
the class TestBufferFrontedFileStoreCache method testDefragTruncateEmpty.
@Test
public void testDefragTruncateEmpty() throws Exception {
cache = createLayeredCache(1 << 15, 1 << 15, true, true);
cache.setMinDefrag(10000000);
Serializer<Integer> s = new SimpleSerializer();
WeakReference<? extends Serializer<?>> ref = new WeakReference<Serializer<?>>(s);
cache.createCacheGroup(s.getId());
Integer cacheObject = Integer.valueOf(5000);
for (int i = 0; i < 4; i++) {
CacheEntry ce = new CacheEntry((long) i);
ce.setSerializer(ref);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
cache.add(ce, s);
}
assertEquals(98304, cache.getDiskUsage());
for (int i = 0; i < 4; i++) {
cache.remove(1l, (long) i);
}
assertEquals(98304, cache.getDiskUsage());
cache.setMinDefrag(0);
cache.defragTask.run();
assertEquals(98304, cache.getDiskUsage());
cache.setTruncateInterval(1);
cache.defragTask.run();
assertEquals(0, cache.getDiskUsage());
}
use of org.teiid.common.buffer.CacheEntry in project teiid by teiid.
the class TestBufferFrontedFileStoreCache method get.
private static CacheEntry get(BufferFrontedFileStoreCache cache, Long oid, Serializer<Integer> s) throws TeiidComponentException {
PhysicalInfo o = cache.lockForLoad(oid, s);
CacheEntry ce = cache.get(o, oid, new WeakReference<Serializer<?>>(s));
cache.unlockForLoad(o);
return ce;
}
use of org.teiid.common.buffer.CacheEntry in project teiid by teiid.
the class TestBufferFrontedFileStoreCache method testEviction.
@Test
public void testEviction() throws Exception {
cache = createLayeredCache(1 << 15, 1 << 15, true, true);
assertEquals(3, cache.getMaxMemoryBlocks());
CacheEntry ce = new CacheEntry(2l);
Serializer<Integer> s = new SimpleSerializer();
WeakReference<? extends Serializer<?>> ref = new WeakReference<Serializer<?>>(s);
ce.setSerializer(ref);
cache.createCacheGroup(s.getId());
Integer cacheObject = Integer.valueOf(5000);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
cache.add(ce, s);
ce = new CacheEntry(3l);
ce.setSerializer(ref);
cacheObject = Integer.valueOf(5001);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
cache.add(ce, s);
assertTrue(cache.getDataBlocksInUse() < 4);
assertTrue(cache.getInodesInUse() < 2);
ce = get(cache, 2l, s);
assertEquals(Integer.valueOf(5000), ce.getObject());
ce = get(cache, 3l, s);
assertEquals(Integer.valueOf(5001), ce.getObject());
}
use of org.teiid.common.buffer.CacheEntry in project teiid by teiid.
the class TestBufferFrontedFileStoreCache method add.
private void add(BufferFrontedFileStoreCache cache, Serializer<Integer> s, WeakReference<? extends Serializer<?>> ref, int i) {
CacheEntry ce = new CacheEntry(Long.valueOf(i));
ce.setSerializer(ref);
Integer cacheObject = Integer.valueOf(5000 + i);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
cache.add(ce, s);
}
Aggregations