Search in sources :

Example 1 with HazelcastClientCacheManager

use of com.hazelcast.client.cache.impl.HazelcastClientCacheManager in project hazelcast by hazelcast.

the class ClientNearCacheInvalidationTest method setup.

@Before
public void setup() {
    hazelcastFactory = new TestHazelcastFactory();
    member = hazelcastFactory.newHazelcastInstance(getConfig());
    if (MEMBER_COUNT > 1) {
        HazelcastInstance[] allMembers = new HazelcastInstance[MEMBER_COUNT];
        allMembers[0] = member;
        for (int i = 1; i < MEMBER_COUNT; i++) {
            allMembers[i] = hazelcastFactory.newHazelcastInstance(getConfig());
        }
        waitAllForSafeState(allMembers);
    }
    ClientConfig clientConfig = createClientConfig();
    clientConfig.addNearCacheConfig(createNearCacheConfig(inMemoryFormat));
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    NearCacheManager nearCacheManager = client.client.getNearCacheManager();
    CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) HazelcastServerCachingProvider.createCachingProvider(member).getCacheManager();
    ICache<Object, String> cache = cacheManager.createCache(DEFAULT_CACHE_NAME, createCacheConfig(inMemoryFormat));
    ICache<Object, String> memberCache = member.getCacheManager().getCache(CacheUtil.getPrefixedCacheName(DEFAULT_CACHE_NAME, null, null));
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(DEFAULT_CACHE_NAME));
    testContext = new NearCacheTestContext(client, member, cacheManager, memberCacheManager, nearCacheManager, cache, memberCache, nearCache);
    // make sure several partitions are populated with data
    for (int i = 0; i < 1000; i++) {
        testContext.memberCache.put(Integer.toString(i), Integer.toString(i));
    }
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) Data(com.hazelcast.nio.serialization.Data) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) 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) Before(org.junit.Before)

Example 2 with HazelcastClientCacheManager

use of com.hazelcast.client.cache.impl.HazelcastClientCacheManager in project hazelcast by hazelcast.

the class ClientCacheNearCacheBasicTest method createContext.

@Override
protected <K, V> com.hazelcast.internal.nearcache.NearCacheTestContext<K, V, Data, String> createContext() {
    ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
    CacheConfig<K, V> cacheConfig = createCacheConfig(nearCacheConfig);
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(getConfig());
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider memberProvider = HazelcastServerCachingProvider.createCachingProvider(member);
    HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) memberProvider.getCacheManager();
    NearCacheManager nearCacheManager = client.client.getNearCacheManager();
    CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(DEFAULT_NEAR_CACHE_NAME);
    ICache<K, V> clientCache = cacheManager.createCache(DEFAULT_NEAR_CACHE_NAME, cacheConfig);
    ICache<K, V> memberCache = memberCacheManager.createCache(DEFAULT_NEAR_CACHE_NAME, cacheConfig);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
    return new NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, member, new ICacheDataStructureAdapter<K, V>(clientCache), new ICacheDataStructureAdapter<K, V>(memberCache), false, nearCache, nearCacheManager, cacheManager, memberCacheManager);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) Data(com.hazelcast.nio.serialization.Data) NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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 3 with HazelcastClientCacheManager

use of com.hazelcast.client.cache.impl.HazelcastClientCacheManager 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 4 with HazelcastClientCacheManager

use of com.hazelcast.client.cache.impl.HazelcastClientCacheManager 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 5 with HazelcastClientCacheManager

use of com.hazelcast.client.cache.impl.HazelcastClientCacheManager in project hazelcast by hazelcast.

the class ClientCacheNearCacheStaleReadTest method setUp.

@Before
public void setUp() {
    String cacheName = randomMapName();
    TestHazelcastFactory factory = new TestHazelcastFactory();
    Config config = getConfig().setProperty(CACHE_INVALIDATION_MESSAGE_BATCH_FREQUENCY_SECONDS.getName(), "2");
    ClientConfig clientConfig = getClientConfig(cacheName).setProperty(MAX_TOLERATED_MISS_COUNT.getName(), "0");
    member = factory.newHazelcastInstance(config);
    client = factory.newHazelcastClient(clientConfig);
    CachingProvider provider = createClientCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    CacheConfig<String, String> cacheConfig = createCacheConfig(cacheName);
    cache = cacheManager.createCache(cacheName, cacheConfig);
}
Also used : ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheTestUtils.getBaseConfig(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ClientConfig(com.hazelcast.client.config.ClientConfig) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager) Before(org.junit.Before)

Aggregations

HazelcastClientCacheManager (com.hazelcast.client.cache.impl.HazelcastClientCacheManager)14 ClientConfig (com.hazelcast.client.config.ClientConfig)13 CachingProvider (javax.cache.spi.CachingProvider)13 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)11 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)7 HazelcastClientProxy (com.hazelcast.client.impl.clientside.HazelcastClientProxy)7 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)6 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)6 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)6 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)5 ICacheDataStructureAdapter (com.hazelcast.internal.adapter.ICacheDataStructureAdapter)5 Data (com.hazelcast.nio.serialization.Data)5 HazelcastServerCacheManager (com.hazelcast.cache.impl.HazelcastServerCacheManager)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Data (com.hazelcast.internal.serialization.Data)4 TestHazelcastFactory (com.hazelcast.client.test.TestHazelcastFactory)3 CacheConfig (com.hazelcast.config.CacheConfig)3 Config (com.hazelcast.config.Config)3 NearCacheConfig (com.hazelcast.config.NearCacheConfig)3 NearCacheTestContext (com.hazelcast.internal.nearcache.NearCacheTestContext)3