Search in sources :

Example 6 with PerpetualCache

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

the class PerpetualCacheTest method shouldRemoveItemOnDemand.

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

Example 7 with PerpetualCache

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

the class SoftCacheTest method shouldDemonstrateCopiesAreEqual.

@Test
public void shouldDemonstrateCopiesAreEqual() {
    Cache cache = new SoftCache(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) SoftCache(org.apache.ibatis.cache.decorators.SoftCache) SerializedCache(org.apache.ibatis.cache.decorators.SerializedCache) SoftCache(org.apache.ibatis.cache.decorators.SoftCache) PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) SerializedCache(org.apache.ibatis.cache.decorators.SerializedCache) Test(org.junit.Test)

Example 8 with PerpetualCache

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

the class WeakCacheTest method shouldDemonstrateObjectsBeingCollectedAsNeeded.

@Test
public void shouldDemonstrateObjectsBeingCollectedAsNeeded() {
    final int N = 3000000;
    WeakCache cache = new WeakCache(new PerpetualCache("default"));
    for (int i = 0; i < N; i++) {
        cache.putObject(i, i);
        if (cache.getSize() < i + 1) {
            //System.out.println("Cache exceeded with " + (i + 1) + " entries.");
            break;
        }
        if ((i + 1) % 100000 == 0) {
            // Try performing GC.
            System.gc();
        }
    }
    assertTrue(cache.getSize() < N);
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) WeakCache(org.apache.ibatis.cache.decorators.WeakCache) Test(org.junit.Test)

Example 9 with PerpetualCache

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

the class WeakCacheTest method shouldFlushAllItemsOnDemand.

@Test
public void shouldFlushAllItemsOnDemand() {
    WeakCache cache = new WeakCache(new PerpetualCache("default"));
    for (int i = 0; i < 5; i++) {
        cache.putObject(i, i);
    }
    assertNotNull(cache.getObject(0));
    assertNotNull(cache.getObject(4));
    cache.clear();
    assertNull(cache.getObject(0));
    assertNull(cache.getObject(4));
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) WeakCache(org.apache.ibatis.cache.decorators.WeakCache) Test(org.junit.Test)

Example 10 with PerpetualCache

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

the class BaseCacheTest method shouldDemonstrateEqualsAndHashCodeForVariousCacheTypes.

@Test
public void shouldDemonstrateEqualsAndHashCodeForVariousCacheTypes() {
    PerpetualCache cache = new PerpetualCache("test_cache");
    assertTrue(cache.equals(cache));
    assertTrue(cache.equals(new SynchronizedCache(cache)));
    assertTrue(cache.equals(new SerializedCache(cache)));
    assertTrue(cache.equals(new LoggingCache(cache)));
    assertTrue(cache.equals(new ScheduledCache(cache)));
    assertEquals(cache.hashCode(), new SynchronizedCache(cache).hashCode());
    assertEquals(cache.hashCode(), new SerializedCache(cache).hashCode());
    assertEquals(cache.hashCode(), new LoggingCache(cache).hashCode());
    assertEquals(cache.hashCode(), new ScheduledCache(cache).hashCode());
    Set<Cache> caches = new HashSet<Cache>();
    caches.add(cache);
    caches.add(new SynchronizedCache(cache));
    caches.add(new SerializedCache(cache));
    caches.add(new LoggingCache(cache));
    caches.add(new ScheduledCache(cache));
    assertEquals(1, caches.size());
}
Also used : PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) ScheduledCache(org.apache.ibatis.cache.decorators.ScheduledCache) SynchronizedCache(org.apache.ibatis.cache.decorators.SynchronizedCache) LoggingCache(org.apache.ibatis.cache.decorators.LoggingCache) SerializedCache(org.apache.ibatis.cache.decorators.SerializedCache) HashSet(java.util.HashSet) LoggingCache(org.apache.ibatis.cache.decorators.LoggingCache) PerpetualCache(org.apache.ibatis.cache.impl.PerpetualCache) SynchronizedCache(org.apache.ibatis.cache.decorators.SynchronizedCache) ScheduledCache(org.apache.ibatis.cache.decorators.ScheduledCache) SerializedCache(org.apache.ibatis.cache.decorators.SerializedCache) 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