Search in sources :

Example 21 with PerpetualCache

use of org.apache.ibatis.cache.impl.PerpetualCache in project mybatis-3 by mybatis.

the class SoftCacheTest method shouldDemonstrateObjectsBeingCollectedAsNeeded.

@Test
public void shouldDemonstrateObjectsBeingCollectedAsNeeded() throws Exception {
    final int N = 3000000;
    SoftCache cache = new SoftCache(new PerpetualCache("default"));
    for (int i = 0; i < N; i++) {
        //waste a bunch of memory
        byte[] array = new byte[5001];
        array[5000] = 1;
        cache.putObject(i, array);
        Object value = cache.getObject(i);
        if (cache.getSize() < i + 1) {
            //System.out.println("Cache exceeded with " + (i + 1) + " entries.");
            break;
        }
    }
    assertTrue(cache.getSize() < N);
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) SoftCache(org.apache.ibatis.cache.decorators.SoftCache) Test(org.junit.Test)

Example 22 with PerpetualCache

use of org.apache.ibatis.cache.impl.PerpetualCache in project mybatis-3 by mybatis.

the class SuperCacheTest method shouldDemonstrate5LevelSuperCacheHandlesLotsOfEntriesWithoutCrashing.

@Test
public void shouldDemonstrate5LevelSuperCacheHandlesLotsOfEntriesWithoutCrashing() {
    final int N = 100000;
    Cache cache = new PerpetualCache("default");
    cache = new LruCache(cache);
    cache = new FifoCache(cache);
    cache = new SoftCache(cache);
    cache = new WeakCache(cache);
    cache = new ScheduledCache(cache);
    cache = new SerializedCache(cache);
    //    cache = new LoggingCache(cache);
    cache = new SynchronizedCache(cache);
    cache = new TransactionalCache(cache);
    for (int i = 0; i < N; i++) {
        cache.putObject(i, i);
        ((TransactionalCache) cache).commit();
        Object o = cache.getObject(i);
        assertTrue(o == null || i == ((Integer) o));
    }
    assertTrue(cache.getSize() < N);
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) Test(org.junit.Test)

Example 23 with PerpetualCache

use of org.apache.ibatis.cache.impl.PerpetualCache in project mybatis-3 by mybatis.

the class WeakCacheTest method shouldRemoveItemOnDemand.

@Test
public void shouldRemoveItemOnDemand() {
    WeakCache cache = new WeakCache(new PerpetualCache("default"));
    cache.putObject(0, 0);
    assertNotNull(cache.getObject(0));
    cache.removeObject(0);
    assertNull(cache.getObject(0));
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) WeakCache(org.apache.ibatis.cache.decorators.WeakCache) Test(org.junit.Test)

Example 24 with PerpetualCache

use of org.apache.ibatis.cache.impl.PerpetualCache in project mybatis-3 by mybatis.

the class WeakCacheTest method shouldDemonstrateCopiesAreEqual.

@Test
public void shouldDemonstrateCopiesAreEqual() {
    Cache cache = new WeakCache(new PerpetualCache("default"));
    cache = new SerializedCache(cache);
    for (int i = 0; i < 1000; i++) {
        cache.putObject(i, i);
        Object value = cache.getObject(i);
        assertTrue(value == null || value.equals(i));
    }
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) WeakCache(org.apache.ibatis.cache.decorators.WeakCache) SerializedCache(org.apache.ibatis.cache.decorators.SerializedCache) PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) WeakCache(org.apache.ibatis.cache.decorators.WeakCache) SerializedCache(org.apache.ibatis.cache.decorators.SerializedCache) Test(org.junit.Test)

Example 25 with PerpetualCache

use of org.apache.ibatis.cache.impl.PerpetualCache in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldResolveBothSimpleNameAndFullyQualifiedName.

@Test
public void shouldResolveBothSimpleNameAndFullyQualifiedName() {
    Configuration c = new Configuration();
    final String fullName = "com.mycache.MyCache";
    final String shortName = "MyCache";
    final PerpetualCache cache = new PerpetualCache(fullName);
    c.addCache(cache);
    assertEquals(cache, c.getCache(fullName));
    assertEquals(cache, c.getCache(shortName));
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Aggregations

PerpetualCache (org.apache.ibatis.cache.impl.PerpetualCache)27 Test (org.junit.Test)27 SerializedCache (org.apache.ibatis.cache.decorators.SerializedCache)9 SynchronizedCache (org.apache.ibatis.cache.decorators.SynchronizedCache)5 BaseDataTest (org.apache.ibatis.BaseDataTest)4 LoggingCache (org.apache.ibatis.cache.decorators.LoggingCache)4 ScheduledCache (org.apache.ibatis.cache.decorators.ScheduledCache)4 SoftCache (org.apache.ibatis.cache.decorators.SoftCache)4 WeakCache (org.apache.ibatis.cache.decorators.WeakCache)4 FifoCache (org.apache.ibatis.cache.decorators.FifoCache)3 LruCache (org.apache.ibatis.cache.decorators.LruCache)3 BindingException (org.apache.ibatis.binding.BindingException)2 TooManyResultsException (org.apache.ibatis.exceptions.TooManyResultsException)2 HashSet (java.util.HashSet)1