Search in sources :

Example 11 with HazelcastServerCachingProvider

use of com.hazelcast.cache.impl.HazelcastServerCachingProvider in project hazelcast by hazelcast.

the class CachePartitionLostListenerStressTest method testCachePartitionLostListener.

@Test
public void testCachePartitionLostListener() {
    List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp();
    List<HazelcastInstance> survivingInstances = new ArrayList<HazelcastInstance>(instances);
    List<HazelcastInstance> terminatingInstances = survivingInstances.subList(0, numberOfNodesToCrash);
    survivingInstances = survivingInstances.subList(numberOfNodesToCrash, instances.size());
    HazelcastInstance instance = survivingInstances.get(0);
    HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    List<EventCollectingCachePartitionLostListener> listeners = registerListeners(cacheManager);
    if (withData) {
        for (int i = 0; i < getNodeCount(); i++) {
            Cache<Integer, Integer> cache = cacheManager.getCache(getIthCacheName(i));
            for (int j = 0; j < getCacheEntryCount(); j++) {
                cache.put(j, j);
            }
        }
    }
    final String log = "Surviving: " + survivingInstances + " Terminating: " + terminatingInstances;
    Map<Integer, Integer> survivingPartitions = getMinReplicaIndicesByPartitionId(survivingInstances);
    stopInstances(terminatingInstances, nodeLeaveType);
    waitAllForSafeState(survivingInstances);
    if (shouldExpectPartitionLostEvents) {
        for (int i = 0; i < getNodeCount(); i++) {
            assertListenerInvocationsEventually(log, i, numberOfNodesToCrash, listeners.get(i), survivingPartitions);
        }
    } else {
        for (final EventCollectingCachePartitionLostListener listener : listeners) {
            assertTrueAllTheTime(new AssertTask() {

                @Override
                public void run() throws Exception {
                    assertTrue(listener.getEvents().isEmpty());
                }
            }, 1);
        }
    }
    for (int i = 0; i < getNodeCount(); i++) {
        cacheManager.destroyCache(getIthCacheName(i));
    }
    cacheManager.close();
    cachingProvider.close();
}
Also used : ArrayList(java.util.ArrayList) EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 12 with HazelcastServerCachingProvider

use of com.hazelcast.cache.impl.HazelcastServerCachingProvider in project hazelcast by hazelcast.

the class ICacheDataStructureAdapterTest method setUp.

@Before
public void setUp() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();
    HazelcastServerCachingProvider cachingProvider = createCachingProvider(hazelcastInstance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CacheConfig<Integer, String> cacheConfig = new CacheConfig<Integer, String>();
    cache = (ICache<Integer, String>) cacheManager.createCache("CacheDataStructureAdapterTest", cacheConfig);
    adapter = new ICacheDataStructureAdapter<Integer, String>(cache);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheConfig(com.hazelcast.config.CacheConfig) Before(org.junit.Before)

Example 13 with HazelcastServerCachingProvider

use of com.hazelcast.cache.impl.HazelcastServerCachingProvider in project hazelcast by hazelcast.

the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_invoked.

@Test
public void test_cachePartitionLostListener_invoked() {
    final String cacheName = randomName();
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    final HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance);
    final CacheManager cacheManager = cachingProvider.getCacheManager();
    final CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
    config.setBackupCount(0);
    cacheManager.createCache(cacheName, config);
    final CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
    final CacheManager clientCacheManager = clientCachingProvider.getCacheManager();
    final Cache<Integer, String> cache = clientCacheManager.getCache(cacheName);
    final ICache iCache = cache.unwrap(ICache.class);
    final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener();
    iCache.addPartitionLostListener(listener);
    final CacheService cacheService = getNode(instance).getNodeEngine().getService(CacheService.SERVICE_NAME);
    final int partitionId = 5;
    cacheService.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
    assertCachePartitionLostEventEventually(listener, partitionId);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICache(com.hazelcast.cache.ICache) CacheManager(javax.cache.CacheManager) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheConfig(com.hazelcast.config.CacheConfig) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastServerCachingProvider.createCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider.createCachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) 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 HazelcastServerCachingProvider

use of com.hazelcast.cache.impl.HazelcastServerCachingProvider in project hazelcast by hazelcast.

the class CacheCreationTest method creatingMultiCacheFromMultiProviders.

@Test
public void creatingMultiCacheFromMultiProviders() throws Exception {
    ExecutorService executorService = Executors.newFixedThreadPool(THREAD_COUNT);
    final CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
    for (int i = 0; i < THREAD_COUNT; i++) {
        final String cacheName = "xmlCache" + i;
        executorService.execute(new Runnable() {

            @Override
            public void run() {
                HazelcastServerCachingProvider cachingProvider = createCachingProvider(hzConfig);
                Cache<Object, Object> cache = cachingProvider.getCacheManager().getCache(cacheName);
                cache.get(1);
                latch.countDown();
            }
        });
    }
    HazelcastTestSupport.assertOpenEventually(latch);
    executorService.shutdown();
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) Cache(javax.cache.Cache) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 15 with HazelcastServerCachingProvider

use of com.hazelcast.cache.impl.HazelcastServerCachingProvider in project hazelcast by hazelcast.

the class CacheCreationTest method creatingASingleCache.

@Test
public void creatingASingleCache() throws URISyntaxException {
    HazelcastServerCachingProvider cachingProvider = createCachingProvider(hzConfig);
    Cache<Object, Object> cache = cachingProvider.getCacheManager().getCache("xmlCache" + 1);
    cache.get(1);
}
Also used : HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)17 Test (org.junit.Test)16 HazelcastInstance (com.hazelcast.core.HazelcastInstance)14 QuickTest (com.hazelcast.test.annotation.QuickTest)12 ParallelTest (com.hazelcast.test.annotation.ParallelTest)11 CacheManager (javax.cache.CacheManager)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 CacheConfig (com.hazelcast.config.CacheConfig)6 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)6 Config (com.hazelcast.config.Config)6 QuorumConfig (com.hazelcast.config.QuorumConfig)5 QuorumListenerConfig (com.hazelcast.config.QuorumListenerConfig)5 QuorumEvent (com.hazelcast.quorum.QuorumEvent)5 QuorumException (com.hazelcast.quorum.QuorumException)5 QuorumListener (com.hazelcast.quorum.QuorumListener)5 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 AssertTask (com.hazelcast.test.AssertTask)4 SlowTest (com.hazelcast.test.annotation.SlowTest)4 ICache (com.hazelcast.cache.ICache)3 CacheService (com.hazelcast.cache.impl.CacheService)3