Search in sources :

Example 41 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class ClientStatisticsTest method createHazelcastClient.

private HazelcastClientInstanceImpl createHazelcastClient() {
    ClientConfig clientConfig = new ClientConfig().addNearCacheConfig(new NearCacheConfig(MAP_NAME)).addNearCacheConfig(new NearCacheConfig(CACHE_NAME));
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    clientConfig.getMetricsConfig().setCollectionFrequencySeconds(STATS_PERIOD_SECONDS);
    HazelcastInstance clientInstance = hazelcastFactory.newHazelcastClient(clientConfig);
    return getHazelcastClientInstanceImpl(clientInstance);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 42 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class ClientTxnMapTest method prepareServerAndGetServerMap.

private IMap prepareServerAndGetServerMap(String mapName, int keyInServerNearCache) {
    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setCacheLocalEntries(true);
    Config serverConfig = new Config();
    serverConfig.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
    HazelcastInstance server = hazelcastFactory.newHazelcastInstance(serverConfig);
    // populate server near cache.
    IMap map = server.getMap(mapName);
    map.put(keyInServerNearCache, 1);
    map.get(keyInServerNearCache);
    return map;
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 43 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class TestClientApplicationContext method testClient.

@Test
public void testClient() {
    assertNotNull(client);
    assertNotNull(client2);
    assertNotNull(client3);
    ClientConfig config = client.getClientConfig();
    assertEquals("13", config.getProperty("hazelcast.client.retry.count"));
    assertEquals(1000, config.getNetworkConfig().getConnectionTimeout());
    client.getMap("default").put("Q", "q");
    client2.getMap("default").put("X", "x");
    IMap<Object, Object> map = instance.getMap("default");
    assertEquals("q", map.get("Q"));
    assertEquals("x", map.get("X"));
    ClientConfig config3 = client3.getClientConfig();
    SerializationConfig serConf = config3.getSerializationConfig();
    assertEquals(ByteOrder.BIG_ENDIAN, serConf.getByteOrder());
    assertFalse(serConf.isAllowUnsafe());
    assertFalse(serConf.isCheckClassDefErrors());
    assertFalse(serConf.isEnableCompression());
    assertFalse(serConf.isEnableSharedObject());
    assertFalse(serConf.isUseNativeByteOrder());
    assertEquals(10, serConf.getPortableVersion());
    Map<Integer, String> map1 = serConf.getDataSerializableFactoryClasses();
    assertNotNull(map1);
    assertTrue(map1.containsKey(1));
    assertEquals("com.hazelcast.spring.serialization.DummyDataSerializableFactory", map1.get(1));
    Map<Integer, String> portableFactoryClasses = serConf.getPortableFactoryClasses();
    assertNotNull(portableFactoryClasses);
    assertTrue(portableFactoryClasses.containsKey(2));
    assertEquals("com.hazelcast.spring.serialization.DummyPortableFactory", portableFactoryClasses.get(2));
    Collection<SerializerConfig> serializerConfigs = serConf.getSerializerConfigs();
    assertNotNull(serializerConfigs);
    SerializerConfig serializerConfig = serializerConfigs.iterator().next();
    assertNotNull(serializerConfig);
    assertEquals("com.hazelcast.internal.serialization.impl.CustomSerializationTest$FooXmlSerializer", serializerConfig.getClassName());
    assertEquals("com.hazelcast.internal.serialization.impl.CustomSerializationTest$Foo", serializerConfig.getTypeClassName());
    List<ProxyFactoryConfig> proxyFactoryConfigs = config3.getProxyFactoryConfigs();
    assertNotNull(proxyFactoryConfigs);
    ProxyFactoryConfig proxyFactoryConfig = proxyFactoryConfigs.get(0);
    assertNotNull(proxyFactoryConfig);
    assertEquals("com.hazelcast.spring.DummyProxyFactory", proxyFactoryConfig.getClassName());
    assertEquals("MyService", proxyFactoryConfig.getService());
    LoadBalancer loadBalancer = config3.getLoadBalancer();
    assertNotNull(loadBalancer);
    assertTrue(loadBalancer instanceof RoundRobinLB);
    NearCacheConfig nearCacheConfig = config3.getNearCacheConfig("default");
    assertNotNull(nearCacheConfig);
    assertEquals(1, nearCacheConfig.getTimeToLiveSeconds());
    assertEquals(70, nearCacheConfig.getMaxIdleSeconds());
    assertEquals(EvictionPolicy.LRU, nearCacheConfig.getEvictionConfig().getEvictionPolicy());
    assertEquals(4000, nearCacheConfig.getEvictionConfig().getSize());
    assertTrue(nearCacheConfig.isInvalidateOnChange());
    assertFalse(nearCacheConfig.isSerializeKeys());
    assertEquals(CACHE_ON_UPDATE, nearCacheConfig.getLocalUpdatePolicy());
}
Also used : SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) LoadBalancer(com.hazelcast.client.LoadBalancer) NearCacheConfig(com.hazelcast.config.NearCacheConfig) RoundRobinLB(com.hazelcast.client.util.RoundRobinLB) SerializerConfig(com.hazelcast.config.SerializerConfig) ProxyFactoryConfig(com.hazelcast.client.config.ProxyFactoryConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class ClientCacheProxyFactory method create.

@Override
public ClientProxy create(String id, ClientContext context) {
    CacheConfig cacheConfig = findCacheConfig(id);
    if (cacheConfig == null) {
        throw new CacheNotExistsException("Cache " + id + " is already destroyed or not created yet");
    }
    NearCacheConfig nearCacheConfig = client.getClientConfig().getNearCacheConfig(cacheConfig.getName());
    if (nearCacheConfig != null) {
        return new NearCachedClientCacheProxy(cacheConfig, context);
    }
    return new ClientCacheProxy(cacheConfig, context);
}
Also used : NearCachedClientCacheProxy(com.hazelcast.client.cache.impl.nearcache.NearCachedClientCacheProxy) NearCachedClientCacheProxy(com.hazelcast.client.cache.impl.nearcache.NearCachedClientCacheProxy) NearCacheConfig(com.hazelcast.config.NearCacheConfig) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) CacheNotExistsException(com.hazelcast.cache.CacheNotExistsException)

Example 45 with NearCacheConfig

use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.

the class DefaultNearCacheManager method startPreloading.

@Override
public void startPreloading(NearCache nearCache, DataStructureAdapter dataStructureAdapter) {
    NearCacheConfig nearCacheConfig = nearCache.getNearCacheConfig();
    NearCachePreloaderConfig preloaderConfig = nearCacheConfig.getPreloaderConfig();
    if (preloaderConfig.isEnabled()) {
        createAndSchedulePreloadTask(nearCache, dataStructureAdapter);
        createAndScheduleStorageTask();
    }
}
Also used : NearCachePreloaderConfig(com.hazelcast.config.NearCachePreloaderConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Aggregations

NearCacheConfig (com.hazelcast.config.NearCacheConfig)212 Test (org.junit.Test)89 QuickTest (com.hazelcast.test.annotation.QuickTest)82 Config (com.hazelcast.config.Config)66 HazelcastInstance (com.hazelcast.core.HazelcastInstance)65 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)62 ClientConfig (com.hazelcast.client.config.ClientConfig)51 MapConfig (com.hazelcast.config.MapConfig)37 EvictionConfig (com.hazelcast.config.EvictionConfig)24 Before (org.junit.Before)17 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)16 CacheConfig (com.hazelcast.config.CacheConfig)15 ParallelTest (com.hazelcast.test.annotation.ParallelTest)15 NearCacheTestUtils.getBaseConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig)14 AssertTask (com.hazelcast.test.AssertTask)14 NightlyTest (com.hazelcast.test.annotation.NightlyTest)12 MapStoreConfig (com.hazelcast.config.MapStoreConfig)11 Data (com.hazelcast.nio.serialization.Data)11 MatchingPointConfigPatternMatcher (com.hazelcast.config.matcher.MatchingPointConfigPatternMatcher)10 CachingProvider (javax.cache.spi.CachingProvider)10