Search in sources :

Example 11 with ICache

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));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICache(com.hazelcast.cache.ICache) CacheManager(javax.cache.CacheManager) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with ICache

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)));
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Observable(com.hazelcast.jet.Observable) CompletableFuture(java.util.concurrent.CompletableFuture) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) StreamSerializer(com.hazelcast.nio.serialization.StreamSerializer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Cache(javax.cache.Cache) ClientConfig(com.hazelcast.client.config.ClientConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) Nonnull(javax.annotation.Nonnull) SimpleEntry(java.util.AbstractMap.SimpleEntry) IList(com.hazelcast.collection.IList) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) Config(com.hazelcast.config.Config) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) Category(org.junit.experimental.categories.Category) Sources(com.hazelcast.jet.pipeline.Sources) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) ICache(com.hazelcast.cache.ICache) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) SimpleEntry(java.util.AbstractMap.SimpleEntry) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with ICache

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());
}
Also used : ICache(com.hazelcast.cache.ICache) HazelcastExpiryPolicy(com.hazelcast.cache.HazelcastExpiryPolicy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with ICache

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());
}
Also used : ICache(com.hazelcast.cache.ICache)

Example 15 with ICache

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) ICache(com.hazelcast.cache.ICache)

Aggregations

ICache (com.hazelcast.cache.ICache)20 Test (org.junit.Test)16 QuickTest (com.hazelcast.test.annotation.QuickTest)15 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 CacheManager (javax.cache.CacheManager)9 CacheConfig (com.hazelcast.config.CacheConfig)7 Config (com.hazelcast.config.Config)6 CachingProvider (javax.cache.spi.CachingProvider)6 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)5 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)5 HazelcastExpiryPolicy (com.hazelcast.cache.HazelcastExpiryPolicy)5 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)4 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 IList (com.hazelcast.collection.IList)3 Job (com.hazelcast.jet.Job)3 Util.entry (com.hazelcast.jet.Util.entry)3 JobConfig (com.hazelcast.jet.config.JobConfig)3 IMap (com.hazelcast.map.IMap)3