Search in sources :

Example 31 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.

the class CacheContextTest method cacheEntryListenerCountIncreasedAndDecreasedCorrectly.

protected void cacheEntryListenerCountIncreasedAndDecreasedCorrectly(DecreaseType decreaseType) {
    CacheManager cacheManager = provider.getCacheManager();
    CacheEntryListenerConfiguration<String, String> cacheEntryListenerConfig = new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(new TestListener()), null, true, true);
    CompleteConfiguration<String, String> cacheConfig = new MutableConfiguration<String, String>();
    Cache<String, String> cache = cacheManager.createCache(CACHE_NAME, cacheConfig);
    cache.registerCacheEntryListener(cacheEntryListenerConfig);
    final CacheService cacheService1 = getCacheService(hazelcastInstance1);
    final CacheService cacheService2 = getCacheService(hazelcastInstance2);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertNotNull(cacheService1.getCacheContext(CACHE_NAME_WITH_PREFIX));
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertNotNull(cacheService2.getCacheContext(CACHE_NAME_WITH_PREFIX));
        }
    });
    final CacheContext cacheContext1 = cacheService1.getCacheContext(CACHE_NAME_WITH_PREFIX);
    final CacheContext cacheContext2 = cacheService2.getCacheContext(CACHE_NAME_WITH_PREFIX);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals(1, cacheContext1.getCacheEntryListenerCount());
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals(1, cacheContext2.getCacheEntryListenerCount());
        }
    });
    switch(decreaseType) {
        case DEREGISTER:
            cache.deregisterCacheEntryListener(cacheEntryListenerConfig);
            break;
        case SHUTDOWN:
            driverInstance.getLifecycleService().shutdown();
            break;
        case TERMINATE:
            driverInstance.getLifecycleService().terminate();
            break;
        default:
            throw new IllegalArgumentException("Unsupported decrease type: " + decreaseType);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals(0, cacheContext1.getCacheEntryListenerCount());
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals(0, cacheContext2.getCacheEntryListenerCount());
        }
    });
}
Also used : MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) CacheContext(com.hazelcast.cache.impl.CacheContext) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) CacheService(com.hazelcast.cache.impl.CacheService)

Example 32 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.

the class CacheFromDifferentNodesTest method testCachesDestroy.

@Test
public void testCachesDestroy() {
    CacheManager cacheManager = cachingProvider1.getCacheManager();
    CacheManager cacheManager2 = cachingProvider2.getCacheManager();
    MutableConfiguration configuration = new MutableConfiguration();
    final Cache c1 = cacheManager.createCache("c1", configuration);
    final Cache c2 = cacheManager2.getCache("c1");
    c1.put("key", "value");
    cacheManager.destroyCache("c1");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            try {
                c2.get("key");
                throw new AssertionError("get should throw IllegalStateException");
            } catch (IllegalStateException e) {
            // ignored as expected
            }
        }
    });
}
Also used : CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) Cache(javax.cache.Cache) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 33 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.

the class CacheFromDifferentNodesTest method testCachesDestroyFromOtherManagers.

@Test
public void testCachesDestroyFromOtherManagers() {
    CacheManager cacheManager = cachingProvider1.getCacheManager();
    CacheManager cacheManager2 = cachingProvider2.getCacheManager();
    MutableConfiguration configuration = new MutableConfiguration();
    final Cache c1 = cacheManager.createCache("c1", configuration);
    final Cache c2 = cacheManager2.createCache("c2", configuration);
    c1.put("key", "value");
    c2.put("key", "value");
    cacheManager.close();
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() throws Exception {
            c2.get("key");
        }
    }, 10);
}
Also used : CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) Cache(javax.cache.Cache) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 34 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.

the class CacheListenerTest method testReplaceIfSameWithSyncListener_whenValueIsNotSame.

@Test(timeout = 30000)
public void testReplaceIfSameWithSyncListener_whenValueIsNotSame() {
    CachingProvider cachingProvider = getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CompleteConfiguration<String, String> config = new MutableConfiguration<String, String>().setTypes(String.class, String.class).addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(new TestListener(new AtomicInteger())), null, true, true));
    Cache<String, String> cache = cacheManager.createCache(randomString(), config);
    String key = randomString();
    cache.put(key, randomString());
    // there should not be any hanging due to sync listener
    cache.replace(key, randomString(), randomString());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 35 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.

the class CacheListenerTest method testReplaceWithSyncListener_whenEntryNotExists.

@Test(timeout = 30000)
public void testReplaceWithSyncListener_whenEntryNotExists() {
    CachingProvider cachingProvider = getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CompleteConfiguration<String, String> config = new MutableConfiguration<String, String>().setTypes(String.class, String.class).addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(new TestListener(new AtomicInteger())), null, true, true));
    Cache<String, String> cache = cacheManager.createCache(randomString(), config);
    // there should not be any hanging due to sync listener
    cache.replace(randomString(), randomString());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MutableConfiguration (javax.cache.configuration.MutableConfiguration)146 Test (org.junit.Test)97 CacheManager (javax.cache.CacheManager)76 CachingProvider (javax.cache.spi.CachingProvider)35 Cache (javax.cache.Cache)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)21 QuickTest (com.hazelcast.test.annotation.QuickTest)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 Test (org.junit.jupiter.api.Test)12 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)11 URI (java.net.URI)11 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)11 MutableCacheEntryListenerConfiguration (javax.cache.configuration.MutableCacheEntryListenerConfiguration)10 Duration (javax.cache.expiry.Duration)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)7 ExtendedMutableConfiguration (org.cache2k.jcache.ExtendedMutableConfiguration)7 AssertTask (com.hazelcast.test.AssertTask)6 BaseTest (org.redisson.BaseTest)6 RedisRunner (org.redisson.RedisRunner)6