Search in sources :

Example 31 with HazelcastClientProxy

use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.

the class ClientCacheNearCachePreloaderTest method createNearCacheContextBuilder.

private <K, V> NearCacheTestContextBuilder<K, V, Data, String> createNearCacheContextBuilder(CacheConfig<K, V> cacheConfig) {
    ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider provider = createClientCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(nearCacheConfig.getName());
    ICache<K, V> clientCache = cacheManager.createCache(nearCacheConfig.getName(), cacheConfig);
    NearCacheManager nearCacheManager = ((ClientCacheProxy) clientCache).getContext().getNearCacheManager(clientCache.getServiceName());
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
    return new NearCacheTestContextBuilder<K, V, Data, String>(nearCacheConfig, client.getSerializationService()).setNearCacheInstance(client).setNearCacheAdapter(new ICacheDataStructureAdapter<>(clientCache)).setNearCache(nearCache).setNearCacheManager(nearCacheManager).setCacheManager(cacheManager);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) Data(com.hazelcast.internal.serialization.Data) ICacheDataStructureAdapter(com.hazelcast.internal.adapter.ICacheDataStructureAdapter) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 32 with HazelcastClientProxy

use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.

the class ClientCacheNearCacheSerializationCountTest method createNearCacheContextBuilder.

private <K, V> NearCacheTestContextBuilder<K, V, Data, String> createNearCacheContextBuilder(CacheConfig<K, V> cacheConfig) {
    ClientConfig clientConfig = getClientConfig();
    if (nearCacheConfig != null) {
        clientConfig.addNearCacheConfig(nearCacheConfig);
    }
    prepareSerializationConfig(clientConfig.getSerializationConfig());
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider provider = createClientCachingProvider(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);
    NearCacheManager nearCacheManager = ((ClientCacheProxy) clientCache).getContext().getNearCacheManager(clientCache.getServiceName());
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
    return new NearCacheTestContextBuilder<K, V, Data, String>(nearCacheConfig, client.getSerializationService()).setNearCacheInstance(client).setNearCacheAdapter(new ICacheDataStructureAdapter<>(clientCache)).setNearCache(nearCache).setNearCacheManager(nearCacheManager).setCacheManager(cacheManager);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) Data(com.hazelcast.internal.serialization.Data) ICacheDataStructureAdapter(com.hazelcast.internal.adapter.ICacheDataStructureAdapter) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 33 with HazelcastClientProxy

use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.

the class ClientCacheNearCacheInvalidationTest method createNearCacheTest.

private <K, V, NK, NV> NearCacheTestContext<K, V, NK, NV> createNearCacheTest(String cacheName, NearCacheConfig nearCacheConfig, CacheConfig<K, V> cacheConfig) {
    ClientConfig clientConfig = getClientConfig().setProperty(RECONCILIATION_INTERVAL_SECONDS.getName(), "0").addNearCacheConfig(nearCacheConfig);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider provider = createClientCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    ICache<K, V> cache = cacheManager.createCache(cacheName, cacheConfig);
    NearCacheManager nearCacheManager = ((ClientCacheProxy) cache).getContext().getNearCacheManager(CacheService.SERVICE_NAME);
    NearCache<NK, NV> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(cacheName));
    NearCacheTestContextBuilder<K, V, NK, NV> builder = new NearCacheTestContextBuilder<>(nearCacheConfig, client.getSerializationService());
    return builder.setNearCacheInstance(client).setNearCacheAdapter(new ICacheDataStructureAdapter<>(cache)).setNearCacheManager(nearCacheManager).setNearCache(nearCache).build();
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) NearCacheTestContextBuilder(com.hazelcast.internal.nearcache.impl.NearCacheTestContextBuilder) ICacheDataStructureAdapter(com.hazelcast.internal.adapter.ICacheDataStructureAdapter) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 34 with HazelcastClientProxy

use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.

the class ClientCacheMetaDataGeneratorTest method createCacheFromNewClient.

private ICache<Integer, Integer> createCacheFromNewClient() {
    HazelcastClientProxy client = (HazelcastClientProxy) factory.newHazelcastClient(clientConfig);
    CachingProvider clientCachingProvider = createClientCachingProvider(client);
    CacheManager cacheManager = clientCachingProvider.getCacheManager();
    ICache<Integer, Integer> cache = (ICache<Integer, Integer>) cacheManager.createCache(CACHE_NAME, cacheConfig);
    assertInstanceOf(NearCachedClientCacheProxy.class, cache);
    return cache;
}
Also used : ICache(com.hazelcast.cache.ICache) CacheManager(javax.cache.CacheManager) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider)

Example 35 with HazelcastClientProxy

use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.

the class ClientCacheInvalidationMetadataDistortionTest method ensure_nearCachedClient_and_member_data_sync_eventually.

@Test
public void ensure_nearCachedClient_and_member_data_sync_eventually() {
    final Config config = createConfig();
    final HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
    CachingProvider provider = createServerCachingProvider(serverInstance);
    CacheManager serverCacheManager = provider.getCacheManager();
    // populated from member
    final Cache<Integer, Integer> memberCache = serverCacheManager.createCache(DEFAULT_CACHE_NAME, createCacheConfig(BINARY));
    for (int i = 0; i < CACHE_SIZE; i++) {
        memberCache.put(i, i);
    }
    ClientConfig clientConfig = createClientConfig();
    clientConfig.addNearCacheConfig(createNearCacheConfig(BINARY));
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider clientCachingProvider = createClientCachingProvider(client);
    final Cache<Integer, Integer> clientCache = clientCachingProvider.getCacheManager().createCache(DEFAULT_CACHE_NAME, createCacheConfig(BINARY));
    Thread populateNearCache = new Thread(new Runnable() {

        public void run() {
            while (!stopTest.get()) {
                for (int i = 0; i < CACHE_SIZE; i++) {
                    clientCache.get(i);
                }
            }
        }
    });
    Thread distortSequence = new Thread(new Runnable() {

        @Override
        public void run() {
            while (!stopTest.get()) {
                distortRandomPartitionSequence(DEFAULT_CACHE_NAME, member);
                sleepSeconds(1);
            }
        }
    });
    Thread distortUuid = new Thread(new Runnable() {

        @Override
        public void run() {
            while (!stopTest.get()) {
                distortRandomPartitionUuid(member);
                sleepSeconds(5);
            }
        }
    });
    Thread put = new Thread(new Runnable() {

        public void run() {
            // change some data
            while (!stopTest.get()) {
                int key = getInt(CACHE_SIZE);
                int value = getInt(Integer.MAX_VALUE);
                memberCache.put(key, value);
                sleepAtLeastMillis(100);
            }
        }
    });
    // start threads
    put.start();
    populateNearCache.start();
    distortSequence.start();
    distortUuid.start();
    sleepSeconds(60);
    // stop threads
    stopTest.set(true);
    assertJoinable(distortUuid, distortSequence, populateNearCache, put);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            for (int i = 0; i < CACHE_SIZE; i++) {
                Integer valueSeenFromMember = memberCache.get(i);
                Integer valueSeenFromClient = clientCache.get(i);
                assertEquals(valueSeenFromMember, valueSeenFromClient);
            }
        }
    });
}
Also used : EvictionConfig(com.hazelcast.config.EvictionConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

HazelcastClientProxy (com.hazelcast.client.impl.clientside.HazelcastClientProxy)42 ClientConfig (com.hazelcast.client.config.ClientConfig)27 Test (org.junit.Test)16 QuickTest (com.hazelcast.test.annotation.QuickTest)14 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)13 CachingProvider (javax.cache.spi.CachingProvider)13 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)12 Data (com.hazelcast.internal.serialization.Data)12 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 NearCacheTestContextBuilder (com.hazelcast.internal.nearcache.impl.NearCacheTestContextBuilder)9 HazelcastClientCacheManager (com.hazelcast.client.cache.impl.HazelcastClientCacheManager)7 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)7 ClientMetricsConfig (com.hazelcast.client.config.ClientMetricsConfig)6 NearCacheConfig (com.hazelcast.config.NearCacheConfig)6 Config (com.hazelcast.config.Config)5 CacheManager (javax.cache.CacheManager)5 CacheConfig (com.hazelcast.config.CacheConfig)4 ICacheDataStructureAdapter (com.hazelcast.internal.adapter.ICacheDataStructureAdapter)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4