Search in sources :

Example 1 with NearCachedClientMapProxy

use of com.hazelcast.client.proxy.NearCachedClientMapProxy in project hazelcast by hazelcast.

the class ClientMapNearCacheTest method receives_one_clearEvent_after_mapEvictAll_call_from_member.

@Test
public void receives_one_clearEvent_after_mapEvictAll_call_from_member() {
    // populate Near Cache
    IMap<Integer, Integer> clientMap = getNearCachedMapFromClient(newNearCacheConfig());
    populateMap(clientMap, 1000);
    populateNearCache(clientMap, 1000);
    // member comes
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(newConfig());
    // add test listener to count clear events
    final ClearEventCounterEventHandler handler = new ClearEventCounterEventHandler();
    ((NearCachedClientMapProxy) clientMap).addNearCacheInvalidationListener(handler);
    // call evictAll
    IMap memberMap = member.getMap(clientMap.getName());
    memberMap.evictAll();
    // 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) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) NearCachedClientMapProxy(com.hazelcast.client.proxy.NearCachedClientMapProxy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with NearCachedClientMapProxy

use of com.hazelcast.client.proxy.NearCachedClientMapProxy 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 3 with NearCachedClientMapProxy

use of com.hazelcast.client.proxy.NearCachedClientMapProxy in project hazelcast by hazelcast.

the class GetAllTest method ensure_supplied_number_of_keys_are_in_near_cache.

@Test
public void ensure_supplied_number_of_keys_are_in_near_cache() throws Exception {
    final int entryCount = 100000;
    final String mapName = "test";
    factory.newHazelcastInstance();
    NearCacheConfig nearCacheConfig = new NearCacheConfig(mapName);
    nearCacheConfig.setInvalidateOnChange(true);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.addNearCacheConfig(nearCacheConfig);
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    IMap map = client.getMap(mapName);
    for (int i = 0; i < entryCount; i++) {
        map.put(i, i);
    }
    HashSet keys = new HashSet();
    for (int i = 0; i < entryCount; i++) {
        keys.add(i);
    }
    map.getAll(keys);
    assertEquals(entryCount, ((NearCachedClientMapProxy) map).getNearCache().size());
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) NearCachedClientMapProxy(com.hazelcast.client.proxy.NearCachedClientMapProxy) HashSet(java.util.HashSet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with NearCachedClientMapProxy

use of com.hazelcast.client.proxy.NearCachedClientMapProxy in project hazelcast by hazelcast.

the class ClientMapMetaDataFetcherTest method getRepairingTask.

private RepairingTask getRepairingTask(String mapName, int partition, long givenSequence, UUID givenUuid) {
    HazelcastInstance member = factory.newHazelcastInstance();
    distortRandomPartitionSequence(mapName, partition, givenSequence, member);
    distortRandomPartitionUuid(partition, givenUuid, member);
    ClientConfig clientConfig = new ClientConfig().addNearCacheConfig(new NearCacheConfig(mapName));
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    IMap<Integer, Integer> clientMap = client.getMap(mapName);
    ClientContext clientContext = ((NearCachedClientMapProxy) clientMap).getClientContext();
    return clientContext.getRepairingTask(SERVICE_NAME);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientContext(com.hazelcast.client.spi.ClientContext) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) NearCachedClientMapProxy(com.hazelcast.client.proxy.NearCachedClientMapProxy)

Example 5 with NearCachedClientMapProxy

use of com.hazelcast.client.proxy.NearCachedClientMapProxy in project hazelcast by hazelcast.

the class InvalidationMemberAddRemoveTest method ensure_nearCachedClient_and_member_data_sync_eventually.

@Test
public void ensure_nearCachedClient_and_member_data_sync_eventually() throws Exception {
    final String mapName = "default";
    final AtomicBoolean stopTest = new AtomicBoolean();
    // members are created.
    final Config config = createConfig();
    HazelcastInstance member = factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    // map is populated form member.
    final IMap<Integer, Integer> memberMap = member.getMap(mapName);
    for (int i = 0; i < KEY_COUNT; i++) {
        memberMap.put(i, i);
    }
    // a new client comes.
    ClientConfig clientConfig = createClientConfig().addNearCacheConfig(createNearCacheConfig(mapName));
    final HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    final IMap<Integer, Integer> clientMap = client.getMap(mapName);
    ArrayList<Thread> threads = new ArrayList<Thread>();
    // continuously adds and removes member
    Thread shadowMember = new Thread(new Runnable() {

        @Override
        public void run() {
            while (!stopTest.get()) {
                HazelcastInstance member = factory.newHazelcastInstance(config);
                sleepSeconds(5);
                member.getLifecycleService().terminate();
            }
        }
    });
    threads.add(shadowMember);
    // populates client near-cache
    for (int i = 0; i < NEAR_CACHE_POPULATOR_THREAD_COUNT; i++) {
        Thread populateClientNearCache = new Thread(new Runnable() {

            public void run() {
                while (!stopTest.get()) {
                    for (int i = 0; i < KEY_COUNT; i++) {
                        clientMap.get(i);
                    }
                }
            }
        });
        threads.add(populateClientNearCache);
    }
    // updates map data from member.
    Thread putFromMember = new Thread(new Runnable() {

        public void run() {
            while (!stopTest.get()) {
                int key = getInt(KEY_COUNT);
                int value = getInt(Integer.MAX_VALUE);
                memberMap.put(key, value);
                sleepAtLeastMillis(2);
            }
        }
    });
    threads.add(putFromMember);
    Thread clearFromMember = new Thread(new Runnable() {

        public void run() {
            while (!stopTest.get()) {
                memberMap.clear();
                sleepSeconds(5);
            }
        }
    });
    threads.add(clearFromMember);
    for (Thread thread : threads) {
        thread.start();
    }
    // stress system some seconds
    sleepSeconds(TEST_RUN_SECONDS);
    //stop threads
    stopTest.set(true);
    for (Thread thread : threads) {
        thread.join();
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (int i = 0; i < KEY_COUNT; i++) {
                Integer valueSeenFromMember = memberMap.get(i);
                Integer valueSeenFromClient = clientMap.get(i);
                int nearCacheSize = ((NearCachedClientMapProxy) clientMap).getNearCache().size();
                assertEquals("Stale value found. (nearCacheSize=" + nearCacheSize + ")", valueSeenFromMember, valueSeenFromClient);
            }
        }
    });
}
Also used : Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ArrayList(java.util.ArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) NearCachedClientMapProxy(com.hazelcast.client.proxy.NearCachedClientMapProxy) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

NearCachedClientMapProxy (com.hazelcast.client.proxy.NearCachedClientMapProxy)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 Test (org.junit.Test)6 AssertTask (com.hazelcast.test.AssertTask)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ClientConfig (com.hazelcast.client.config.ClientConfig)4 NearCacheConfig (com.hazelcast.config.NearCacheConfig)4 IMap (com.hazelcast.core.IMap)3 NearCache (com.hazelcast.internal.nearcache.NearCache)2 Data (com.hazelcast.nio.serialization.Data)2 ArrayList (java.util.ArrayList)2 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 MapPutAllCodec (com.hazelcast.client.impl.protocol.codec.MapPutAllCodec)1 ClientMapProxy (com.hazelcast.client.proxy.ClientMapProxy)1 ClientContext (com.hazelcast.client.spi.ClientContext)1 ClientPartitionService (com.hazelcast.client.spi.ClientPartitionService)1 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)1