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));
}
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));
}
}
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);
}
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));
}
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());
}
Aggregations