Search in sources :

Example 16 with ICacheRecordStore

use of com.hazelcast.cache.impl.ICacheRecordStore in project hazelcast by hazelcast.

the class CacheReplicationOperation method run.

@Override
public void run() throws Exception {
    ICacheService service = getService();
    for (Map.Entry<String, Map<Data, CacheRecord>> entry : data.entrySet()) {
        ICacheRecordStore cache;
        cache = service.getOrCreateRecordStore(entry.getKey(), getPartitionId());
        cache.reset();
        Map<Data, CacheRecord> map = entry.getValue();
        Iterator<Map.Entry<Data, CacheRecord>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            if (cache.evictIfRequired()) {
                // We are already over eviction threshold, each put record will cause another eviction.
                break;
            }
            Map.Entry<Data, CacheRecord> next = iterator.next();
            Data key = next.getKey();
            CacheRecord record = next.getValue();
            iterator.remove();
            cache.putRecord(key, record, false);
        }
    }
    data.clear();
    if (getReplicaIndex() == 0) {
        nearCacheStateHolder.applyState();
    }
}
Also used : CacheRecord(com.hazelcast.cache.impl.record.CacheRecord) ICacheService(com.hazelcast.cache.impl.ICacheService) ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore) Data(com.hazelcast.internal.serialization.Data) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map)

Example 17 with ICacheRecordStore

use of com.hazelcast.cache.impl.ICacheRecordStore in project hazelcast by hazelcast.

the class CacheBackupTest method checkSavedRecordOnBackup.

private void checkSavedRecordOnBackup(String key, String expectedValue, String cacheName, int keyPartitionId, SerializationService serializationService, ICacheService cacheService) {
    ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
    assertNotNull(recordStore);
    assertEquals(expectedValue, serializationService.toObject(recordStore.get(serializationService.toData(key), null)));
}
Also used : ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore)

Example 18 with ICacheRecordStore

use of com.hazelcast.cache.impl.ICacheRecordStore in project hazelcast by hazelcast.

the class CacheClearTest method testClear.

@Test
public void testClear() {
    ICache<String, String> cache = createCache();
    String cacheName = cache.getName();
    Map<String, String> entries = createAndFillEntries();
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        cache.put(entry.getKey(), entry.getValue());
    }
    // Verify that put works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String expectedValue = entries.get(key);
        String actualValue = cache.get(key);
        assertEquals(expectedValue, actualValue);
    }
    Node node = getNode(hazelcastInstance);
    InternalPartitionService partitionService = node.getPartitionService();
    SerializationService serializationService = node.getSerializationService();
    // Verify that backup of put works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String expectedValue = entries.get(key);
        Data keyData = serializationService.toData(key);
        int keyPartitionId = partitionService.getPartitionId(keyData);
        for (int i = 0; i < INSTANCE_COUNT; i++) {
            Node n = getNode(hazelcastInstances[i]);
            ICacheService cacheService = n.getNodeEngine().getService(ICacheService.SERVICE_NAME);
            ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
            assertNotNull(recordStore);
            String actualValue = serializationService.toObject(recordStore.get(keyData, null));
            assertEquals(expectedValue, actualValue);
        }
    }
    cache.clear();
    // Verify that clear works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String actualValue = cache.get(key);
        assertNull(actualValue);
    }
    // Verify that backup of clear works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        Data keyData = serializationService.toData(key);
        int keyPartitionId = partitionService.getPartitionId(keyData);
        for (int i = 0; i < INSTANCE_COUNT; i++) {
            Node n = getNode(hazelcastInstances[i]);
            ICacheService cacheService = n.getNodeEngine().getService(ICacheService.SERVICE_NAME);
            ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
            assertNotNull(recordStore);
            String actualValue = serializationService.toObject(recordStore.get(keyData, null));
            assertNull(actualValue);
        }
    }
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) ICacheService(com.hazelcast.cache.impl.ICacheService) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore) HashMap(java.util.HashMap) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with ICacheRecordStore

use of com.hazelcast.cache.impl.ICacheRecordStore in project hazelcast by hazelcast.

the class CacheRecordStoreTest method putObjectAndGetDataExpiryPolicyFromCacheRecordStore.

@Test
public void putObjectAndGetDataExpiryPolicyFromCacheRecordStore() {
    ICacheRecordStore cacheRecordStore = createCacheRecordStore(InMemoryFormat.BINARY);
    putAndSetExpiryPolicyFromRecordStore(cacheRecordStore, InMemoryFormat.BINARY);
}
Also used : ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with ICacheRecordStore

use of com.hazelcast.cache.impl.ICacheRecordStore in project hazelcast by hazelcast.

the class CacheRecordStoreTest method putObjectAndGetObjectExpiryPolicyFromCacheRecordStore.

@Test
public void putObjectAndGetObjectExpiryPolicyFromCacheRecordStore() {
    ICacheRecordStore cacheRecordStore = createCacheRecordStore(InMemoryFormat.OBJECT);
    putAndSetExpiryPolicyFromRecordStore(cacheRecordStore, InMemoryFormat.OBJECT);
}
Also used : ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ICacheRecordStore (com.hazelcast.cache.impl.ICacheRecordStore)21 ICacheService (com.hazelcast.cache.impl.ICacheService)13 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 Data (com.hazelcast.internal.serialization.Data)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Node (com.hazelcast.instance.impl.Node)3 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)3 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 Accessors.getNode (com.hazelcast.test.Accessors.getNode)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 CacheConfig (com.hazelcast.config.CacheConfig)2 CachePartitionSegment (com.hazelcast.cache.impl.CachePartitionSegment)1 CacheRecordStore (com.hazelcast.cache.impl.CacheRecordStore)1 CacheService (com.hazelcast.cache.impl.CacheService)1 PreJoinCacheConfig (com.hazelcast.cache.impl.PreJoinCacheConfig)1 CacheRecord (com.hazelcast.cache.impl.record.CacheRecord)1 MetaDataGenerator (com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator)1 ObjectNamespace (com.hazelcast.internal.services.ObjectNamespace)1