import java.io.IOException;
-
/**
* Cached object test.
- *
+ *
* @author Erik Brakkee
*/
public class CachedObjectTest extends TestCase {
- /**
- *
- */
private static final String EHCACHE_CONFIG = "ehcache.xml";
private static final int OBJECT_KEY = 10;
private CachedObject.Computation<Integer, Integer> computation;
private int ncomputations;
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
computation = new CachedObject.Computation<Integer, Integer>() {
- public Integer getObject(Integer aObjectKey) {
- ncomputations++;
+ public Integer getObject(Integer aObjectKey) {
+ ncomputations++;
- return compute(aObjectKey);
- }
- ;
- };
+ return compute(aObjectKey);
+ };
+ };
ncomputations = 0;
}
/**
* Verifies that upon first use, the cached object uses the computation to
* retrieve the object.
- *
+ *
*/
public void testComputation() {
CachedObject<Integer, Integer> cached = createCached(new ZeroCache<Integer, Integer>());
}
public void testBehaviorEhCache() throws CacheException, IOException {
- Cache<Integer, Integer> cache = new EhCache<Integer, Integer>(new TestResource(
- CachedObjectTest.class, EHCACHE_CONFIG), "test");
+ Cache<Integer, Integer> cache = new EhCache<Integer, Integer>(
+ new TestResource(CachedObjectTest.class, EHCACHE_CONFIG), "test");
CachedObject<Integer, Integer> cached = createCached(cache);
assertTrue(cache == cached.getCache());
int value = cached.get();
assertEquals(compute(OBJECT_KEY), value);
assertEquals(1, ncomputations);
- // The value must still be cached.
+ // The value must still be cached.
value = cached.get();
assertEquals(compute(OBJECT_KEY), value);
assertEquals(1, ncomputations);
- // Cache expiry.
+ // Cache expiry.
TimingUtils.sleep(6000);
value = cached.get();
assertEquals(compute(OBJECT_KEY), value);
}
public void testBehaviorEhCacheDefault() throws CacheException, IOException {
- Cache<Integer, Integer> cache = new EhCache<Integer, Integer>(new TestResource(
- CachedObjectTest.class, EHCACHE_CONFIG), "undefined");
+ Cache<Integer, Integer> cache = new EhCache<Integer, Integer>(
+ new TestResource(CachedObjectTest.class, EHCACHE_CONFIG),
+ "undefined");
CachedObject<Integer, Integer> cached = createCached(cache);
assertTrue(cache == cached.getCache());
int value = cached.get();
assertEquals(compute(OBJECT_KEY), value);
assertEquals(1, ncomputations);
- // The value must still be cached.
+ // The value must still be cached.
value = cached.get();
assertEquals(compute(OBJECT_KEY), value);
assertEquals(1, ncomputations);
- // Cache expiry.
+ // Cache expiry.
TimingUtils.sleep(6000);
value = cached.get();
assertEquals(compute(OBJECT_KEY), value);