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();
}
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);
}
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);
}
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();
}
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);
}
Aggregations