Search in sources :

Example 96 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class ClientNearCacheTestSupport method putToCacheAndRemoveFromOtherNodeThenCantGetUpdatedFromClientNearCache.

protected void putToCacheAndRemoveFromOtherNodeThenCantGetUpdatedFromClientNearCache(InMemoryFormat inMemoryFormat) {
    NearCacheConfig nearCacheConfig = createNearCacheConfig(inMemoryFormat);
    nearCacheConfig.setInvalidateOnChange(true);
    NearCacheTestContext nearCacheTestContext1 = createNearCacheTest(DEFAULT_CACHE_NAME, nearCacheConfig);
    final NearCacheTestContext nearCacheTestContext2 = createNearCacheTest(DEFAULT_CACHE_NAME, nearCacheConfig);
    // put cache record from client-1
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        nearCacheTestContext1.cache.put(i, generateValueFromKey(i));
    }
    // get records from client-2
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        final Integer key = i;
        final String value = nearCacheTestContext2.cache.get(key);
        // records are stored in the cache as async not sync, so these records will be there in cache eventually
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                Data keyData = nearCacheTestContext2.serializationService.toData(key);
                assertEquals(value, nearCacheTestContext2.nearCache.get(keyData));
            }
        });
    }
    // delete cache record from client-1
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        nearCacheTestContext1.cache.remove(i);
    }
    // can't get deleted records from client-2
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        final int key = i;
        // records are stored in the Near Cache will be invalidated eventually, since cache records are updated.
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                Data keyData = nearCacheTestContext2.serializationService.toData(key);
                assertNull(nearCacheTestContext2.nearCache.get(keyData));
            }
        });
    }
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig) AssertTask(com.hazelcast.test.AssertTask) Data(com.hazelcast.nio.serialization.Data) CacheLoaderException(javax.cache.integration.CacheLoaderException)

Example 97 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class ClientNearCacheTestSupport method putAndGetFromCacheAndThenGetFromClientNearCache.

protected void putAndGetFromCacheAndThenGetFromClientNearCache(InMemoryFormat inMemoryFormat) {
    NearCacheConfig nearCacheConfig = createNearCacheConfig(inMemoryFormat);
    NearCacheTestContext nearCacheTestContext = createNearCacheTestAndFillWithData(DEFAULT_CACHE_NAME, nearCacheConfig);
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        assertNull(nearCacheTestContext.nearCache.get(nearCacheTestContext.serializationService.toData(i)));
    }
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        // get records so they will be stored in Near Cache
        nearCacheTestContext.cache.get(i);
    }
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        String expectedValue = generateValueFromKey(i);
        Data keyData = nearCacheTestContext.serializationService.toData(i);
        assertEquals(expectedValue, nearCacheTestContext.nearCache.get(keyData));
    }
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig) Data(com.hazelcast.nio.serialization.Data)

Example 98 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class ClientNearCacheTestSupport method createNearCacheTest.

protected NearCacheTestContext createNearCacheTest(String cacheName, NearCacheConfig nearCacheConfig, CacheConfig cacheConfig) {
    ClientConfig clientConfig = createClientConfig();
    clientConfig.addNearCacheConfig(nearCacheConfig);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    NearCacheManager nearCacheManager = client.client.getNearCacheManager();
    CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    //noinspection unchecked
    ICache<Object, String> cache = cacheManager.createCache(cacheName, cacheConfig);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(cacheName));
    return new NearCacheTestContext(client, cacheManager, nearCacheManager, cache, nearCache);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) Data(com.hazelcast.nio.serialization.Data) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 99 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class ClientMapNearCacheBasicTest method createContext.

@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
    ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(getConfig());
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    IMap<K, V> memberMap = member.getMap(DEFAULT_NEAR_CACHE_NAME);
    IMap<K, V> clientMap = client.getMap(DEFAULT_NEAR_CACHE_NAME);
    NearCacheManager nearCacheManager = client.client.getNearCacheManager();
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
    return new NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, member, new IMapDataStructureAdapter<K, V>(clientMap), new IMapDataStructureAdapter<K, V>(memberMap), false, nearCache, nearCacheManager);
}
Also used : NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) Data(com.hazelcast.nio.serialization.Data) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy)

Example 100 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class ClientMapNearCachePreloaderTest method createContext.

@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext(boolean createClient) {
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(getConfig());
    IMap<K, V> memberMap = member.getMap(nearCacheConfig.getName());
    if (!createClient) {
        return new NearCacheTestContext<K, V, Data, String>(getSerializationService(member), member, new IMapDataStructureAdapter<K, V>(memberMap), false, null, null);
    }
    NearCacheTestContext<K, V, Data, String> clientContext = createClientContext();
    return new NearCacheTestContext<K, V, Data, String>(clientContext.serializationService, clientContext.nearCacheInstance, member, clientContext.nearCacheAdapter, new IMapDataStructureAdapter<K, V>(memberMap), false, clientContext.nearCache, clientContext.nearCacheManager);
}
Also used : NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Data(com.hazelcast.nio.serialization.Data)

Aggregations

Data (com.hazelcast.nio.serialization.Data)773 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)140 Test (org.junit.Test)121 QuickTest (com.hazelcast.test.annotation.QuickTest)118 ParallelTest (com.hazelcast.test.annotation.ParallelTest)108 ArrayList (java.util.ArrayList)81 Map (java.util.Map)64 SerializationService (com.hazelcast.spi.serialization.SerializationService)54 HashMap (java.util.HashMap)54 NodeEngine (com.hazelcast.spi.NodeEngine)50 HashSet (java.util.HashSet)39 Address (com.hazelcast.nio.Address)28 AbstractMap (java.util.AbstractMap)28 Record (com.hazelcast.map.impl.record.Record)27 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 HeapData (com.hazelcast.internal.serialization.impl.HeapData)26 List (java.util.List)20 Future (java.util.concurrent.Future)20 CacheEventData (com.hazelcast.cache.impl.CacheEventData)19 Operation (com.hazelcast.spi.Operation)18