Search in sources :

Example 86 with CacheManager

use of javax.cache.CacheManager in project hazelcast by hazelcast.

the class CacheDestroyTest method test_cacheDestroyOperation.

@Test
public void test_cacheDestroyOperation() throws ExecutionException, InterruptedException {
    final String CACHE_NAME = "MyCache";
    final String FULL_CACHE_NAME = HazelcastCacheManager.CACHE_MANAGER_PREFIX + CACHE_NAME;
    CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(getHazelcastInstance());
    CacheManager cacheManager = cachingProvider.getCacheManager();
    cacheManager.createCache(CACHE_NAME, new CacheConfig());
    NodeEngineImpl nodeEngine1 = getNode(getHazelcastInstance()).getNodeEngine();
    final ICacheService cacheService1 = nodeEngine1.getService(ICacheService.SERVICE_NAME);
    InternalOperationService operationService1 = nodeEngine1.getOperationService();
    NodeEngineImpl nodeEngine2 = getNode(hazelcastInstances[1]).getNodeEngine();
    final ICacheService cacheService2 = nodeEngine2.getService(ICacheService.SERVICE_NAME);
    assertNotNull(cacheService1.getCacheConfig(FULL_CACHE_NAME));
    assertNotNull(cacheService2.getCacheConfig(FULL_CACHE_NAME));
    // Invoke on single node and the operation is also forward to others nodes by the operation itself
    operationService1.invokeOnTarget(ICacheService.SERVICE_NAME, new CacheDestroyOperation(FULL_CACHE_NAME), nodeEngine1.getThisAddress());
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertNull(cacheService1.getCacheConfig(FULL_CACHE_NAME));
            assertNull(cacheService2.getCacheConfig(FULL_CACHE_NAME));
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CacheDestroyOperation(com.hazelcast.cache.impl.operation.CacheDestroyOperation) ICacheService(com.hazelcast.cache.impl.ICacheService) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) CacheConfig(com.hazelcast.config.CacheConfig) ExecutionException(java.util.concurrent.ExecutionException) 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 87 with CacheManager

use of javax.cache.CacheManager in project hazelcast by hazelcast.

the class CacheListenerTest method cacheEntryListenerCountIncreasedAndDecreasedCorrectly.

@Test
public void cacheEntryListenerCountIncreasedAndDecreasedCorrectly() {
    final CachingProvider provider = getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    CompleteConfiguration<String, String> config = new MutableConfiguration<String, String>().addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(new TestListener(new AtomicInteger())), null, true, true));
    final Cache<String, String> cache = cacheManager.createCache("MyCache", config);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(javax.cache.CacheManager) 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 88 with CacheManager

use of javax.cache.CacheManager in project hazelcast by hazelcast.

the class CachePartitionIteratorMigrationTest method getCacheProxy.

private <K, V> CacheProxy<K, V> getCacheProxy(CachingProvider cachingProvider) {
    String cacheName = randomString();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CacheConfig<K, V> config = new CacheConfig<K, V>();
    config.getEvictionConfig().setMaximumSizePolicy(EvictionConfig.MaxSizePolicy.ENTRY_COUNT).setSize(10000000);
    return (CacheProxy<K, V>) cacheManager.createCache(cacheName, config);
}
Also used : CacheProxy(com.hazelcast.cache.impl.CacheProxy) CacheManager(javax.cache.CacheManager) CacheConfig(com.hazelcast.config.CacheConfig)

Example 89 with CacheManager

use of javax.cache.CacheManager in project hazelcast by hazelcast.

the class CachePartitionIteratorTest method getCacheProxy.

private <K, V> CacheProxy<K, V> getCacheProxy() {
    String cacheName = randomString();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CacheConfig<K, V> config = new CacheConfig<K, V>();
    config.getEvictionConfig().setMaximumSizePolicy(EvictionConfig.MaxSizePolicy.ENTRY_COUNT).setSize(10000000);
    return (CacheProxy<K, V>) cacheManager.createCache(cacheName, config);
}
Also used : CacheProxy(com.hazelcast.cache.impl.CacheProxy) CacheManager(javax.cache.CacheManager) CacheConfig(com.hazelcast.config.CacheConfig)

Example 90 with CacheManager

use of javax.cache.CacheManager in project hazelcast by hazelcast.

the class CachePartitionLostListenerConfigTest method testCachePartitionLostListener_registeredViaImplementationInConfigObject.

@Test
public void testCachePartitionLostListener_registeredViaImplementationInConfigObject() {
    final String cacheName = "myCache";
    Config config = new Config();
    CacheSimpleConfig cacheConfig = config.getCacheConfig(cacheName);
    CachePartitionLostListener listener = mock(CachePartitionLostListener.class);
    cacheConfig.addCachePartitionLostListenerConfig(new CachePartitionLostListenerConfig(listener));
    cacheConfig.setBackupCount(0);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance instance = factory.newHazelcastInstance(config);
    HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    cacheManager.getCache(cacheName);
    final EventService eventService = getNode(instance).getNodeEngine().getEventService();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Collection<EventRegistration> registrations = eventService.getRegistrations(CacheService.SERVICE_NAME, cacheName);
            assertFalse(registrations.isEmpty());
        }
    });
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) Config(com.hazelcast.config.Config) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) EventService(com.hazelcast.spi.EventService) IOException(java.io.IOException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

CacheManager (javax.cache.CacheManager)105 Test (org.junit.Test)63 QuickTest (com.hazelcast.test.annotation.QuickTest)56 CachingProvider (javax.cache.spi.CachingProvider)48 ParallelTest (com.hazelcast.test.annotation.ParallelTest)41 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)40 HazelcastInstance (com.hazelcast.core.HazelcastInstance)34 CacheConfig (com.hazelcast.config.CacheConfig)32 AssertTask (com.hazelcast.test.AssertTask)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 MutableConfiguration (javax.cache.configuration.MutableConfiguration)17 URI (java.net.URI)16 Cache (javax.cache.Cache)15 HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)13 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)12 ICache (com.hazelcast.cache.ICache)10 Properties (java.util.Properties)10 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)9 ClientConfig (com.hazelcast.client.config.ClientConfig)8 HazelcastCachingProvider (com.hazelcast.cache.HazelcastCachingProvider)7