Search in sources :

Example 6 with NearCachedClientMapProxy

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

the class ClientMapNearCacheStaleReadTest method flushClientNearCache.

/**
     * Flush Near Cache from client map with Near Cache.
     * <p>
     * Warning: this uses Hazelcast internals which might change from one version to the other.
     */
private void flushClientNearCache(IMap map) {
    if (!(map instanceof NearCachedClientMapProxy)) {
        return;
    }
    NearCachedClientMapProxy clientMapProxy = (NearCachedClientMapProxy) map;
    clientMapProxy.getNearCache().clear();
}
Also used : NearCachedClientMapProxy(com.hazelcast.client.proxy.NearCachedClientMapProxy)

Example 7 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_client.

@Test
public void receives_one_clearEvent_after_mapEvictAll_call_from_client() {
    // populate Near Cache
    IMap<Integer, Integer> clientMap = getNearCachedMapFromClient(newNearCacheConfig());
    populateMap(clientMap, 1000);
    populateNearCache(clientMap, 1000);
    // add test listener to count clear events
    final ClearEventCounterEventHandler handler = new ClearEventCounterEventHandler();
    ((NearCachedClientMapProxy) clientMap).addNearCacheInvalidationListener(handler);
    // call evictAll
    HazelcastInstance anotherClient = hazelcastFactory.newHazelcastClient(newClientConfig());
    IMap<Object, Object> anotherClientMap = anotherClient.getMap(clientMap.getName());
    anotherClientMap.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) 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 8 with NearCachedClientMapProxy

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

the class ClientMapRecordStateStressTest method assertFinalRecordStateIsReadPermitted.

private void assertFinalRecordStateIsReadPermitted(IMap clientMap, InternalSerializationService ss) {
    NearCachedClientMapProxy proxy = (NearCachedClientMapProxy) clientMap;
    NearCache nearCache = proxy.getNearCache();
    DefaultNearCache unwrap = (DefaultNearCache) nearCache.unwrap(DefaultNearCache.class);
    for (int i = 0; i < KEY_SPACE; i++) {
        Data key = ss.toData(i);
        AbstractNearCacheRecordStore nearCacheRecordStore = (AbstractNearCacheRecordStore) unwrap.getNearCacheRecordStore();
        NearCacheRecord record = nearCacheRecordStore.getRecord(key);
        if (record != null) {
            assertEquals(record.toString(), READ_PERMITTED, record.getRecordState());
        }
    }
}
Also used : DefaultNearCache(com.hazelcast.internal.nearcache.impl.DefaultNearCache) NearCacheRecord(com.hazelcast.internal.nearcache.NearCacheRecord) DefaultNearCache(com.hazelcast.internal.nearcache.impl.DefaultNearCache) NearCache(com.hazelcast.internal.nearcache.NearCache) Data(com.hazelcast.nio.serialization.Data) AbstractNearCacheRecordStore(com.hazelcast.internal.nearcache.impl.store.AbstractNearCacheRecordStore) NearCachedClientMapProxy(com.hazelcast.client.proxy.NearCachedClientMapProxy)

Example 9 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_client.

@Test
public void receives_one_clearEvent_after_mapClear_call_from_client() {
    // populate Near Cache
    IMap<Integer, Integer> clientMap = getNearCachedMapFromClient(newNearCacheConfig());
    populateMap(clientMap, 1000);
    populateNearCache(clientMap, 1000);
    // add test listener to count clear events
    final ClearEventCounterEventHandler handler = new ClearEventCounterEventHandler();
    ((NearCachedClientMapProxy) clientMap).addNearCacheInvalidationListener(handler);
    // create a new client to send events
    HazelcastInstance anotherClient = hazelcastFactory.newHazelcastClient(newClientConfig());
    IMap<Object, Object> anotherClientMap = anotherClient.getMap(clientMap.getName());
    anotherClientMap.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) 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)

Aggregations

NearCachedClientMapProxy (com.hazelcast.client.proxy.NearCachedClientMapProxy)9 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 ClientConfig (com.hazelcast.client.config.ClientConfig)4 NearCacheConfig (com.hazelcast.config.NearCacheConfig)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 IMap (com.hazelcast.core.IMap)2 ClientContext (com.hazelcast.client.spi.ClientContext)1 Config (com.hazelcast.config.Config)1 NearCache (com.hazelcast.internal.nearcache.NearCache)1 NearCacheRecord (com.hazelcast.internal.nearcache.NearCacheRecord)1 DefaultNearCache (com.hazelcast.internal.nearcache.impl.DefaultNearCache)1 AbstractNearCacheRecordStore (com.hazelcast.internal.nearcache.impl.store.AbstractNearCacheRecordStore)1 Data (com.hazelcast.nio.serialization.Data)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1