use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class CacheHazelcastInstanceAwareTest method test_inject_hazelcastInstance_to_partitionLostListener_if_itIs_hazelcastInstanceAware.
@Test
public void test_inject_hazelcastInstance_to_partitionLostListener_if_itIs_hazelcastInstanceAware() {
long id = generateUniqueHazelcastInjectionId();
CacheConfig<Integer, Integer> cacheConfig = createCacheConfig(CACHE_NAME);
HazelcastInstance hazelcastInstance = createInstance();
CacheManager cacheManager = createCachingProvider(hazelcastInstance).getCacheManager();
ICache<Integer, Integer> cache = (ICache<Integer, Integer>) cacheManager.createCache(CACHE_NAME, cacheConfig);
cache.addPartitionLostListener(new HazelcastInstanceAwareCachePartitionLostListener(id));
assertEquals("Hazelcast instance has not been injected into partition lost listener!", Boolean.TRUE, HAZELCAST_INSTANCE_INJECTION_RESULT_MAP.get(id));
}
use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class JobSerializerTest method when_serializerIsRegistered_then_itIsAvailableForLocalCacheSink.
@Test
public void when_serializerIsRegistered_then_itIsAvailableForLocalCacheSink() {
Pipeline pipeline = Pipeline.create();
pipeline.readFrom(TestSources.items(1, 2)).map(i -> new SimpleEntry<>(i, new Value(i))).writeTo(Sinks.cache(SINK_CACHE_NAME));
client().getJet().newJob(pipeline, jobConfig()).join();
ICache<Integer, Value> cache = client().getCacheManager().getCache(SINK_CACHE_NAME);
assertThat(cache).hasSize(2);
assertThat(cache.getAll(ImmutableSet.of(1, 2))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(1, new Value(1), 2, new Value(2)));
}
use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class CacheExpirationTest method testSimpleExpiration_putAsync.
@Test
public void testSimpleExpiration_putAsync() {
SimpleExpiryListener listener = new SimpleExpiryListener();
CacheConfig<String, String> cacheConfig = createCacheConfig(new HazelcastExpiryPolicy(1, 1, 1), listener);
Cache<String, String> cache = createCache(cacheConfig);
((ICache<String, String>) cache).putAsync("key", "value");
assertEqualsEventually(1, listener.getExpirationCount());
}
use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class CacheCreateUseDestroyTest method assertStatistics.
private void assertStatistics(int expectedHits) {
ICache iCache = cache.unwrap(ICache.class);
assertEquals("Unexpected cache hits count", expectedHits, iCache.getLocalCacheStatistics().getCacheHits());
}
use of com.hazelcast.cache.ICache in project hazelcast by hazelcast.
the class CacheThroughHazelcastInstanceTest method getCache_whenCacheIsDestroyed_thenCacheIsRemovedFromDistributedObject.
private void getCache_whenCacheIsDestroyed_thenCacheIsRemovedFromDistributedObject(boolean getCache) {
Config config = createConfig();
config.addCacheConfig(createCacheSimpleConfig(CACHE_NAME));
HazelcastInstance instance = createInstance(config);
ICache cache = retrieveCache(instance, getCache);
assertNotNull(cache);
assertContains(instance.getDistributedObjects(), cache);
cache.destroy();
assertNotContains(instance.getDistributedObjects(), cache);
}
Aggregations