Search in sources :

Example 46 with NearCacheConfig

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

the class NearCachedMapProxyImpl method initialize.

@Override
public void initialize() {
    super.initialize();
    mapNearCacheManager = mapServiceContext.getMapNearCacheManager();
    NearCacheConfig nearCacheConfig = mapConfig.getNearCacheConfig();
    nearCache = mapNearCacheManager.getOrCreateNearCache(name, nearCacheConfig);
    if (invalidateOnChange) {
        registerInvalidationListener();
    }
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 47 with NearCacheConfig

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

the class ClientRegressionWithMockNetworkTest method testNearCache_shutdownClient.

@Test
public void testNearCache_shutdownClient() {
    ClientConfig clientConfig = new ClientConfig();
    NearCacheConfig invalidateConfig = new NearCacheConfig();
    String mapName = randomMapName();
    invalidateConfig.setName(mapName);
    invalidateConfig.setInvalidateOnChange(true);
    clientConfig.addNearCacheConfig(invalidateConfig);
    hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    IMap<Integer, Integer> map = client.getMap(mapName);
    map.get(1);
    // test should finish without throwing any exception.
    client.shutdown();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 48 with NearCacheConfig

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

the class ClientRegressionWithMockNetworkTest method testDeadlock_whenDoingOperationFromLifecycleListener_withNearCache.

@Test
public void testDeadlock_whenDoingOperationFromLifecycleListener_withNearCache() {
    String mapName = randomMapName();
    EvictionConfig evictionConfig = new EvictionConfig().setMaxSizePolicy(ENTRY_COUNT).setSize(1);
    NearCacheConfig nearCacheConfig = new NearCacheConfig().setName(mapName).setEvictionConfig(evictionConfig);
    ClientConfig clientConfig = new ClientConfig().addNearCacheConfig(nearCacheConfig);
    CountDownLatch disconnectedLatch = new CountDownLatch(1);
    CountDownLatch finishedLatch = new CountDownLatch(1);
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    IMap<Object, Object> map = client.getMap(mapName);
    client.getLifecycleService().addLifecycleListener(event -> {
        if (event.getState() == CLIENT_DISCONNECTED) {
            disconnectedLatch.countDown();
            map.get(1);
            map.get(2);
            finishedLatch.countDown();
        }
    });
    instance.shutdown();
    assertOpenEventually(disconnectedLatch);
    hazelcastFactory.newHazelcastInstance();
    assertOpenEventually(finishedLatch);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EvictionConfig(com.hazelcast.config.EvictionConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) DistributedObject(com.hazelcast.core.DistributedObject) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 49 with NearCacheConfig

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

the class ClientRegressionWithMockNetworkTest method testNearCache_WhenRegisteredNodeIsDead.

@Test
public void testNearCache_WhenRegisteredNodeIsDead() {
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    String mapName = randomMapName();
    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setName(mapName);
    nearCacheConfig.setInvalidateOnChange(true);
    clientConfig.addNearCacheConfig(nearCacheConfig);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    IMap<Object, Object> map = client.getMap(mapName);
    map.put("a", "b");
    // populate Near Cache
    map.get("a");
    instance.shutdown();
    hazelcastFactory.newHazelcastInstance();
    assertTrueEventually(() -> assertNull(map.get("a")));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheConfig(com.hazelcast.config.NearCacheConfig) DistributedObject(com.hazelcast.core.DistributedObject) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 50 with NearCacheConfig

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

the class ClientNearCacheConfigTest method testSpecificNearCacheConfig_whenAsteriskAtTheEnd.

@Test
public void testSpecificNearCacheConfig_whenAsteriskAtTheEnd() {
    final ClientConfig clientConfig = new ClientConfig();
    final NearCacheConfig genericNearCacheConfig = new NearCacheConfig();
    genericNearCacheConfig.setName("map*");
    clientConfig.addNearCacheConfig(genericNearCacheConfig);
    final NearCacheConfig specificNearCacheConfig = new NearCacheConfig();
    specificNearCacheConfig.setName("mapStudent*");
    clientConfig.addNearCacheConfig(specificNearCacheConfig);
    final NearCacheConfig mapFoo = clientConfig.getNearCacheConfig("mapFoo");
    final NearCacheConfig mapStudentFoo = clientConfig.getNearCacheConfig("mapStudentFoo");
    assertEquals(genericNearCacheConfig, mapFoo);
    assertEquals(specificNearCacheConfig, mapStudentFoo);
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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