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