use of org.cache2k.Cache in project cache2k by cache2k.
the class ListenerTest method asyncUpdateListenerCalled.
/**
* If the listener is not executed in separate thread, this would block
*/
@Test(timeout = TestingParameters.MAX_FINISH_WAIT_MILLIS)
public void asyncUpdateListenerCalled() {
final AtomicInteger _callCount = new AtomicInteger();
final CountDownLatch _fire = new CountDownLatch(1);
Cache<Integer, Integer> c = target.cache(new CacheRule.Specialization<Integer, Integer>() {
@Override
public void extend(final Cache2kBuilder<Integer, Integer> b) {
b.addAsyncListener(new CacheEntryUpdatedListener<Integer, Integer>() {
@Override
public void onEntryUpdated(final Cache<Integer, Integer> cache, final CacheEntry<Integer, Integer> currentEntry, final CacheEntry<Integer, Integer> entryWithNewData) {
try {
_fire.await();
} catch (InterruptedException ignore) {
}
_callCount.incrementAndGet();
}
});
}
});
c.put(1, 2);
assertEquals(0, _callCount.get());
c.put(1, 2);
assertEquals(0, _callCount.get());
_fire.countDown();
ConcurrencyHelper.await(new Condition() {
@Override
public boolean check() throws Exception {
return _callCount.get() == 1;
}
});
}
use of org.cache2k.Cache in project cache2k by cache2k.
the class IntegrationTest method empty.
@Test(expected = UnknownCacheException.class)
public void empty() {
Cache c = new Cache2kBuilder<String, String>() {
}.manager(CacheManager.getInstance("empty")).name("anyCache").build();
c.close();
}
use of org.cache2k.Cache in project cache2k by cache2k.
the class IntegrationTest method onlyDefault.
@Test
public void onlyDefault() {
Cache c = new Cache2kBuilder<String, String>() {
}.manager(CacheManager.getInstance("onlyDefault")).name("anyCache").build();
c.close();
Cache2kConfiguration<String, String> cfg = new Cache2kBuilder<String, String>() {
}.manager(CacheManager.getInstance("onlyDefault")).name("anyCache").toConfiguration();
assertEquals(1234, cfg.getEntryCapacity());
assertTrue(cfg.isExternalConfigurationPresent());
}
use of org.cache2k.Cache in project cache2k by cache2k.
the class IntegrationTest method noManagerConfigurationAndBuild.
@Test
public void noManagerConfigurationAndBuild() {
Cache c = new Cache2kBuilder<String, String>() {
}.manager(CacheManager.getInstance("noManager")).entryCapacity(1234).build();
c.close();
}
use of org.cache2k.Cache in project cache2k by cache2k.
the class IntegrationTest method illegalBoolean.
@Test(expected = ConfigurationException.class)
public void illegalBoolean() {
Cache c = new Cache2kBuilder<String, String>() {
}.manager(CacheManager.getInstance("specialCases")).name("illegalBoolean").build();
c.close();
}
Aggregations