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();
}
}
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)));
}
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);
}
}
}
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);
}
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);
}
Aggregations