Search in sources :

Example 1 with CacheEntry

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());
}
Also used : WeakReference(java.lang.ref.WeakReference) CacheEntry(org.teiid.common.buffer.CacheEntry) Test(org.junit.Test)

Example 2 with CacheEntry

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());
}
Also used : WeakReference(java.lang.ref.WeakReference) CacheEntry(org.teiid.common.buffer.CacheEntry) Test(org.junit.Test)

Example 3 with CacheEntry

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;
}
Also used : CacheEntry(org.teiid.common.buffer.CacheEntry) Serializer(org.teiid.common.buffer.Serializer)

Example 4 with CacheEntry

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());
}
Also used : WeakReference(java.lang.ref.WeakReference) CacheEntry(org.teiid.common.buffer.CacheEntry) Test(org.junit.Test)

Example 5 with CacheEntry

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);
}
Also used : CacheEntry(org.teiid.common.buffer.CacheEntry)

Aggregations

CacheEntry (org.teiid.common.buffer.CacheEntry)10 Test (org.junit.Test)7 WeakReference (java.lang.ref.WeakReference)5 IOException (java.io.IOException)2 CacheKey (org.teiid.common.buffer.CacheKey)2 InputStream (java.io.InputStream)1 ObjectInput (java.io.ObjectInput)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutput (java.io.ObjectOutput)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 ExtensibleBufferedInputStream (org.teiid.common.buffer.ExtensibleBufferedInputStream)1 FileStore (org.teiid.common.buffer.FileStore)1 Serializer (org.teiid.common.buffer.Serializer)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1