Search in sources :

Example 76 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class InvalidationMemberAddRemoveTest method createClientConfig.

protected ClientConfig createClientConfig() {
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty("hazelcast.invalidation.max.tolerated.miss.count", "0");
    clientConfig.setProperty("hazelcast.invalidation.reconciliation.interval.seconds", Integer.toString(RECONCILIATION_INTERVAL_SECONDS));
    return clientConfig;
}
Also used : ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 77 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientEvictionTest method testMaxSizeEvictionWorks.

@Test
public void testMaxSizeEvictionWorks() throws Exception {
    final int maxSize = 1000;
    final int populationCount = 5000;
    String mapName = randomString();
    String cacheName = randomString();
    QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
    cacheConfig.getEvictionConfig().setSize(maxSize).setEvictionPolicy(EvictionPolicy.LFU).setMaximumSizePolicy(EvictionConfig.MaxSizePolicy.ENTRY_COUNT);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.addQueryCacheConfig(mapName, cacheConfig);
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    IMap<Integer, Integer> map = client.getMap(mapName);
    // expecting at least populationCount - maxSize + 10 evicted entries according to max size.
    // 10 states an error margin since eviction does not sweep precise number of entries.
    int margin = 10;
    final CountDownLatch evictedCount = new CountDownLatch(populationCount - maxSize - margin);
    final QueryCache<Integer, Integer> cache = map.getQueryCache(cacheName, TruePredicate.INSTANCE, true);
    String listener = cache.addEntryListener(new EntryEvictedListener() {

        @Override
        public void entryEvicted(EntryEvent event) {
            evictedCount.countDown();
        }
    }, false);
    for (int i = 0; i < populationCount; i++) {
        map.put(i, i);
    }
    assertOpenEventually(evictedCount);
    assertQueryCacheEvicted(maxSize, margin, cache);
    assertTrue(cache.removeEntryListener(listener));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) EntryEvent(com.hazelcast.core.EntryEvent) EntryEvictedListener(com.hazelcast.map.listener.EntryEvictedListener) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 78 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientMapNearCacheTest method testNearCache_clearFromRemote.

@Test
public void testNearCache_clearFromRemote() {
    String mapName = randomMapName();
    HazelcastInstance server = hazelcastFactory.newHazelcastInstance(newConfig());
    NearCacheConfig nearCacheConfig = newInvalidationEnabledNearCacheConfig();
    ClientConfig clientConfig = newClientConfig();
    clientConfig.addNearCacheConfig(nearCacheConfig);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final IMap<Integer, Integer> map = client.getMap(mapName);
    final int size = 147;
    populateMap(map, size);
    populateNearCache(map, size);
    server.getMap(mapName).clear();
    // Near Cache should be empty
    assertTrueEventually(new AssertTask() {

        public void run() {
            for (int i = 0; i < size; i++) {
                assertNull(map.get(i));
            }
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheConfig(com.hazelcast.config.NearCacheConfig) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 79 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientMapNearCacheTest method receives_one_clearEvent_after_mapClear_call_from_member.

@Test
public void receives_one_clearEvent_after_mapClear_call_from_member() {
    // start new member and populate map
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(newConfig());
    IMap<Integer, Integer> memberMap = member.getMap("test");
    populateMap(memberMap, 1000);
    // populate client near cache
    NearCacheConfig nearCacheConfig = newNearCacheConfig();
    ClientConfig clientConfig = newClientConfig();
    clientConfig.addNearCacheConfig(nearCacheConfig);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    IMap<Integer, Integer> clientMap = client.getMap("test");
    populateNearCache(clientMap, 1000);
    // add test listener to count clear events
    final ClearEventCounterEventHandler handler = new ClearEventCounterEventHandler();
    ((NearCachedClientMapProxy) clientMap).addNearCacheInvalidationListener(handler);
    // clear map from member side
    memberMap.clear();
    // sleep for a while to see there is another clear event coming
    sleepSeconds(2);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals("Expecting only 1 clear event", 1, handler.getClearEventCount());
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheConfig(com.hazelcast.config.NearCacheConfig) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) NearCachedClientMapProxy(com.hazelcast.client.proxy.NearCachedClientMapProxy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 80 with ClientConfig

use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.

the class ClientMapNearCacheTest method getNearCachedMapFromClient.

protected <K, V> IMap<K, V> getNearCachedMapFromClient(Config config, NearCacheConfig nearCacheConfig) {
    String mapName = randomMapName();
    hazelcastFactory.newHazelcastInstance(config);
    nearCacheConfig.setName(mapName + "*");
    ClientConfig clientConfig = newClientConfig();
    clientConfig.addNearCacheConfig(nearCacheConfig);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    return client.getMap(mapName);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig)

Aggregations

ClientConfig (com.hazelcast.client.config.ClientConfig)214 Test (org.junit.Test)129 HazelcastInstance (com.hazelcast.core.HazelcastInstance)110 QuickTest (com.hazelcast.test.annotation.QuickTest)107 ParallelTest (com.hazelcast.test.annotation.ParallelTest)81 Config (com.hazelcast.config.Config)45 NearCacheConfig (com.hazelcast.config.NearCacheConfig)32 NightlyTest (com.hazelcast.test.annotation.NightlyTest)32 CountDownLatch (java.util.concurrent.CountDownLatch)25 AssertTask (com.hazelcast.test.AssertTask)20 Before (org.junit.Before)20 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)16 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)15 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)13 CachingProvider (javax.cache.spi.CachingProvider)13 IMap (com.hazelcast.core.IMap)12 LifecycleListener (com.hazelcast.core.LifecycleListener)12 LifecycleEvent (com.hazelcast.core.LifecycleEvent)11 Data (com.hazelcast.nio.serialization.Data)11 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)10