Search in sources :

Example 11 with MutableConfiguration

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

the class CacheListenerTest method testPutIfAbsentWithSyncListener_whenEntryExists.

@Test(timeout = 30000)
public void testPutIfAbsentWithSyncListener_whenEntryExists() {
    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.putIfAbsent(key, randomString());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project ignite by apache.

the class CacheStopAndDestroySelfTest method testTckStyleCreateDestroyClose.

/**
     * Tests start -> destroy -> start -> close using CacheManager.
     */
public void testTckStyleCreateDestroyClose() throws Exception {
    startGridsMultiThreaded(gridCount());
    CacheManager mgr = Caching.getCachingProvider().getCacheManager();
    String cacheName = "cache";
    mgr.createCache(cacheName, new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class));
    mgr.destroyCache(cacheName);
    Cache<Integer, String> cache = mgr.createCache(cacheName, new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class));
    cache.close();
    cache.close();
    try {
        cache.get(1);
        fail();
    } catch (IllegalStateException ignored) {
    // No-op;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration)

Example 13 with MutableConfiguration

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

the class CacheSerializationTest method test_CacheReplicationOperation_serialization.

@Test
public void test_CacheReplicationOperation_serialization() throws Exception {
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();
    try {
        CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(hazelcastInstance);
        CacheManager manager = provider.getCacheManager();
        CompleteConfiguration configuration = new MutableConfiguration();
        Cache cache1 = manager.createCache("cache1", configuration);
        Cache cache2 = manager.createCache("cache2", configuration);
        Cache cache3 = manager.createCache("cache3", configuration);
        for (int i = 0; i < 1000; i++) {
            cache1.put("key" + i, i);
            cache2.put("key" + i, i);
            cache3.put("key" + i, i);
        }
        HazelcastInstanceProxy proxy = (HazelcastInstanceProxy) hazelcastInstance;
        Field original = HazelcastInstanceProxy.class.getDeclaredField("original");
        original.setAccessible(true);
        HazelcastInstanceImpl impl = (HazelcastInstanceImpl) original.get(proxy);
        NodeEngineImpl nodeEngine = impl.node.nodeEngine;
        CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
        int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
        for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
            CachePartitionSegment segment = cacheService.getSegment(partitionId);
            CacheReplicationOperation operation = new CacheReplicationOperation(segment, 1);
            Data serialized = service.toData(operation);
            try {
                service.toObject(serialized);
            } catch (Exception e) {
                throw new Exception("Partition: " + partitionId, e);
            }
        }
    } finally {
        factory.shutdownAll();
    }
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CachePartitionSegment(com.hazelcast.cache.impl.CachePartitionSegment) CacheReplicationOperation(com.hazelcast.cache.impl.operation.CacheReplicationOperation) Data(com.hazelcast.nio.serialization.Data) CachePartitionEventData(com.hazelcast.cache.impl.CachePartitionEventData) HazelcastInstanceProxy(com.hazelcast.instance.HazelcastInstanceProxy) MutableConfiguration(javax.cache.configuration.MutableConfiguration) UnknownHostException(java.net.UnknownHostException) Field(java.lang.reflect.Field) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) CacheManager(javax.cache.CacheManager) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache) CacheService(com.hazelcast.cache.impl.CacheService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with MutableConfiguration

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

the class CacheListenerTest method testReplaceIfSameWithSyncListener_whenEntryNotExists.

@Test(timeout = 30000)
public void testReplaceIfSameWithSyncListener_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(), randomString());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with MutableConfiguration

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

the class CacheListenerTest method testRemoveWithSyncListener_whenEntryNotExists.

@Test(timeout = 30000)
public void testRemoveWithSyncListener_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.remove(randomString());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MutableConfiguration (javax.cache.configuration.MutableConfiguration)20 CacheManager (javax.cache.CacheManager)17 Test (org.junit.Test)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)12 CachingProvider (javax.cache.spi.CachingProvider)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 AssertTask (com.hazelcast.test.AssertTask)5 Cache (javax.cache.Cache)5 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)5 CacheService (com.hazelcast.cache.impl.CacheService)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 MutableCacheEntryListenerConfiguration (javax.cache.configuration.MutableCacheEntryListenerConfiguration)2 CacheContext (com.hazelcast.cache.impl.CacheContext)1 CachePartitionEventData (com.hazelcast.cache.impl.CachePartitionEventData)1 CachePartitionSegment (com.hazelcast.cache.impl.CachePartitionSegment)1 CacheReplicationOperation (com.hazelcast.cache.impl.operation.CacheReplicationOperation)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastInstanceImpl (com.hazelcast.instance.HazelcastInstanceImpl)1