Search in sources :

Example 41 with Cache

use of org.cache2k.Cache in project cache2k by cache2k.

the class Cache2kBuilderTest method duplicateCacheName.

@Test
public void duplicateCacheName() {
    String _managerName = getClass().getName() + ".duplicateCacheName";
    Log.registerSuppression(CacheManager.class.getName() + ":" + _managerName, new Log.SuppressionCounter());
    CacheManager mgr = CacheManager.getInstance(_managerName);
    try {
        Cache c0 = Cache2kBuilder.forUnknownTypes().manager(mgr).eternal(true).name(this.getClass(), "same").build();
        Cache c1 = Cache2kBuilder.forUnknownTypes().manager(mgr).eternal(true).name(this.getClass(), "same").build();
        fail("exception expected");
    } catch (IllegalStateException ex) {
    }
    mgr.close();
}
Also used : Log(org.cache2k.core.util.Log) CacheManager(org.cache2k.CacheManager) Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 42 with Cache

use of org.cache2k.Cache in project cache2k by cache2k.

the class Cache2kBuilderTest method noTypes.

@Test
public void noTypes() {
    Cache c = Cache2kBuilder.forUnknownTypes().eternal(true).build();
    c.put("hallo", 234);
    c.close();
}
Also used : Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 43 with Cache

use of org.cache2k.Cache in project cache2k by cache2k.

the class Cache2kBuilderTest method autoGeneratedCacheName.

@Test
public void autoGeneratedCacheName() {
    Cache c1 = Cache2kBuilder.forUnknownTypes().eternal(true).build();
    assertTrue(c1.getName().startsWith("_org.cache2k"));
    Cache c2 = Cache2kBuilder.forUnknownTypes().eternal(true).build();
    assertTrue(c1 != c2);
    c1.close();
    c2.close();
}
Also used : Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 44 with Cache

use of org.cache2k.Cache in project cache2k by cache2k.

the class Cache2kBuilderTest method cacheNameInConstructor2.

@Test
public void cacheNameInConstructor2() {
    Cache c = new BuildCacheInConstructor2().cache;
    assertThat(c.getName(), startsWith("_" + CLASSNAME + "$BuildCacheInConstructor2.INIT"));
    c.close();
}
Also used : Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 45 with Cache

use of org.cache2k.Cache in project cache2k by cache2k.

the class Cache2kBuilderTest method managerName.

@Test
public void managerName() {
    Cache c = Cache2kBuilder.forUnknownTypes().eternal(true).build();
    assertEquals("default", c.getCacheManager().getName());
    c.close();
}
Also used : Cache(org.cache2k.Cache) Test(org.junit.Test)

Aggregations

Cache (org.cache2k.Cache)60 Test (org.junit.Test)49 CacheManager (org.cache2k.CacheManager)11 Cache2kBuilder (org.cache2k.Cache2kBuilder)9 CacheEntry (org.cache2k.CacheEntry)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 ExceptionWrapper (org.cache2k.core.ExceptionWrapper)8 InternalCache (org.cache2k.core.InternalCache)8 CacheRule (org.cache2k.test.util.CacheRule)6 Condition (org.cache2k.test.util.Condition)6 IntCacheRule (org.cache2k.test.util.IntCacheRule)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 MBeanInfo (javax.management.MBeanInfo)3 Log (org.cache2k.core.util.Log)3 CacheEntryCreatedListener (org.cache2k.event.CacheEntryCreatedListener)3 CacheEntryUpdatedListener (org.cache2k.event.CacheEntryUpdatedListener)3 ArrayList (java.util.ArrayList)2 CacheLoaderException (org.cache2k.integration.CacheLoaderException)2 Collection (java.util.Collection)1 Date (java.util.Date)1