Search in sources :

Example 16 with CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class CallbackAwareClientDelegatingFutureTest method createCache.

private Cache createCache(int blockMilis, boolean throwError) {
    CachingProvider cachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CacheConfiguration cacheConfig = new CacheConfig().setReadThrough(true).setCacheLoaderFactory(new BlockableCacheLoaderFactory(blockMilis, throwError));
    return cacheManager.createCache(CACHE_NAME, cacheConfig);
}
Also used : HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) CacheManager(javax.cache.CacheManager) CacheConfig(com.hazelcast.config.CacheConfig) CacheConfiguration(com.hazelcast.config.CacheConfiguration) CachingProvider(javax.cache.spi.CachingProvider)

Example 17 with CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class ClientCacheNearCachePreloaderTest method createClientContext.

private <K, V> NearCacheTestContext<K, V, Data, String> createClientContext(CacheConfig<K, V> cacheConfig) {
    ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    NearCacheManager nearCacheManager = client.client.getNearCacheManager();
    CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(nearCacheConfig.getName());
    ICache<K, V> clientCache = cacheManager.createCache(nearCacheConfig.getName(), cacheConfig);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
    return new com.hazelcast.internal.nearcache.NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, null, new ICacheDataStructureAdapter<K, V>(clientCache), null, false, nearCache, nearCacheManager, cacheManager, null);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) Data(com.hazelcast.nio.serialization.Data) NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 18 with CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class ClientCacheConfigTest method testGetPreConfiguredCache.

@Test
public void testGetPreConfiguredCache() {
    ClientConfig config = new ClientConfig();
    config.getGroupConfig().setName("cluster1");
    config.getGroupConfig().setPassword("cluster1pass");
    for (int i = 0; i < 4; i++) {
        HazelcastInstance client = HazelcastClient.newHazelcastClient(config);
        CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
        CacheManager cacheManager = provider.getCacheManager();
        Cache<Object, Object> cache = cacheManager.getCache(simpleConfig.getName());
        Assert.assertNotNull("Cache cannot be retrieved on client: " + i, cache);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class ClientNearCacheTestSupport method createNearCacheTest.

protected NearCacheTestContext createNearCacheTest(String cacheName, NearCacheConfig nearCacheConfig, CacheConfig cacheConfig) {
    ClientConfig clientConfig = createClientConfig();
    clientConfig.addNearCacheConfig(nearCacheConfig);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    NearCacheManager nearCacheManager = client.client.getNearCacheManager();
    CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    //noinspection unchecked
    ICache<Object, String> cache = cacheManager.createCache(cacheName, cacheConfig);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(cacheName));
    return new NearCacheTestContext(client, cacheManager, nearCacheManager, cache, nearCache);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) Data(com.hazelcast.nio.serialization.Data) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 20 with CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class CacheEntryProcessorTest method removeRecordWithEntryProcessor.

@Test
public void removeRecordWithEntryProcessor() {
    final int ENTRY_COUNT = 10;
    CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(node1);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CompleteConfiguration<Integer, String> cacheConfig = new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class);
    ICache<Integer, String> cache = cacheManager.createCache("MyCache", cacheConfig).unwrap(ICache.class);
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.put(i * 1000, "Value-" + (i * 1000));
    }
    assertEquals(ENTRY_COUNT, cache.size());
    for (int i = 0; i < ENTRY_COUNT; i++) {
        if (i % 2 == 0) {
            cache.invoke(i * 1000, new RemoveRecordEntryProcessor());
        }
    }
    assertEquals(ENTRY_COUNT / 2, cache.size());
}
Also used : 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)

Aggregations

CachingProvider (javax.cache.spi.CachingProvider)66 CacheManager (javax.cache.CacheManager)48 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)42 Test (org.junit.Test)33 QuickTest (com.hazelcast.test.annotation.QuickTest)28 HazelcastInstance (com.hazelcast.core.HazelcastInstance)24 ParallelTest (com.hazelcast.test.annotation.ParallelTest)24 CacheConfig (com.hazelcast.config.CacheConfig)21 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)18 ClientConfig (com.hazelcast.client.config.ClientConfig)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 MutableConfiguration (javax.cache.configuration.MutableConfiguration)12 ICache (com.hazelcast.cache.ICache)10 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)10 Cache (javax.cache.Cache)10 HazelcastCachingProvider (com.hazelcast.cache.HazelcastCachingProvider)9 Config (com.hazelcast.config.Config)8 Data (com.hazelcast.nio.serialization.Data)8 Before (org.junit.Before)8 HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)7