use of com.hazelcast.map.impl.SimpleEntryView in project hazelcast by hazelcast.
the class MapMergePolicyQuickTest method testPutIfAbsentMapMergePolicy.
@Test
public void testPutIfAbsentMapMergePolicy() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
String name = randomString();
IMap<String, String> map = instance.getMap(name);
MapServiceContext mapServiceContext = getMapServiceContext(instance);
Data dataKey = mapServiceContext.toData("key");
Data dataValue = mapServiceContext.toData("value1");
Data dataValue2 = mapServiceContext.toData("value2");
RecordStore recordStore = mapServiceContext.getRecordStore(getPartitionId(instance, "key"), name);
recordStore.beforeOperation();
NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
SplitBrainMergePolicyProvider mergePolicyProvider = nodeEngine.getSplitBrainMergePolicyProvider();
SplitBrainMergePolicy mergePolicy = mergePolicyProvider.getMergePolicy(PutIfAbsentMergePolicy.class.getName());
SimpleEntryView<Data, Data> initialEntry = new SimpleEntryView<>(dataKey, dataValue);
recordStore.merge(createMergingEntry(nodeEngine.getSerializationService(), initialEntry), mergePolicy, CallerProvenance.NOT_WAN);
SimpleEntryView<Data, Data> mergingEntry = new SimpleEntryView<>(dataKey, dataValue2);
recordStore.merge(createMergingEntry(nodeEngine.getSerializationService(), mergingEntry), mergePolicy, CallerProvenance.NOT_WAN);
assertEquals("value1", map.get("key"));
recordStore.afterOperation();
}
use of com.hazelcast.map.impl.SimpleEntryView in project hazelcast by hazelcast.
the class ClientMapProxy method getEntryView.
@Override
@SuppressWarnings("unchecked")
public EntryView<K, V> getEntryView(K key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
final Data keyData = toData(key);
ClientMessage request = MapGetEntryViewCodec.encodeRequest(name, keyData, getThreadId());
ClientMessage response = invoke(request, keyData);
MapGetEntryViewCodec.ResponseParameters parameters = MapGetEntryViewCodec.decodeResponse(response);
SimpleEntryView<K, V> entryView = new SimpleEntryView<K, V>();
SimpleEntryView<Data, Data> dataEntryView = parameters.response;
if (dataEntryView == null) {
return null;
}
entryView.setKey((K) toObject(dataEntryView.getKey()));
entryView.setValue((V) toObject(dataEntryView.getValue()));
entryView.setCost(dataEntryView.getCost());
entryView.setCreationTime(dataEntryView.getCreationTime());
entryView.setExpirationTime(dataEntryView.getExpirationTime());
entryView.setHits(dataEntryView.getHits());
entryView.setLastAccessTime(dataEntryView.getLastAccessTime());
entryView.setLastStoredTime(dataEntryView.getLastStoredTime());
entryView.setLastUpdateTime(dataEntryView.getLastUpdateTime());
entryView.setVersion(dataEntryView.getVersion());
entryView.setHits(dataEntryView.getHits());
entryView.setTtl(dataEntryView.getTtl());
//TODO putCache
return entryView;
}
use of com.hazelcast.map.impl.SimpleEntryView in project hazelcast by hazelcast.
the class MergePolicySerializationTest method testIssue2665.
@Test
public void testIssue2665() {
String name = randomString();
String serviceName = "hz:impl:mapService";
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, MyObject> map = instance.getMap(name);
MyObject myObjectExisting = new MyObject();
map.put("key", myObjectExisting);
NodeEngineImpl nodeEngine = HazelcastTestSupport.getNode(instance).getNodeEngine();
MapService mapService = nodeEngine.getService(serviceName);
MapServiceContext mapServiceContext = mapService.getMapServiceContext();
int partitionId = nodeEngine.getPartitionService().getPartitionId("key");
Data dataKey = mapServiceContext.toData("key");
RecordStore recordStore = mapServiceContext.getRecordStore(partitionId, name);
MapMergePolicy mergePolicy = mapServiceContext.getMergePolicyProvider().getMergePolicy(PutIfAbsentMapMergePolicy.class.getName());
EntryView<String, MyObject> mergingEntryView = new SimpleEntryView<String, MyObject>("key", new MyObject());
recordStore.merge(dataKey, mergingEntryView, mergePolicy);
int deSerializedCount = MyObject.deserializedCount;
assertEquals(0, deSerializedCount);
}
use of com.hazelcast.map.impl.SimpleEntryView in project hazelcast by hazelcast.
the class MapProxyImpl method getEntryView.
@Override
@SuppressWarnings("unchecked")
public EntryView<K, V> getEntryView(@Nonnull K key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
SimpleEntryView<K, V> entryViewInternal = (SimpleEntryView<K, V>) getEntryViewInternal(toDataWithStrategy(key));
if (entryViewInternal == null) {
return null;
}
Data value = (Data) entryViewInternal.getValue();
entryViewInternal.setKey(key);
entryViewInternal.setValue(toObject(value));
return entryViewInternal;
}
use of com.hazelcast.map.impl.SimpleEntryView in project hazelcast by hazelcast.
the class MapMergePolicySerializationTest method testIssue2665.
@Test
public void testIssue2665() {
String name = randomString();
String serviceName = "hz:impl:mapService";
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, MyObject> map = instance.getMap(name);
MyObject myObjectExisting = new MyObject();
map.put("key", myObjectExisting);
NodeEngineImpl nodeEngine = getNode(instance).getNodeEngine();
MapService mapService = nodeEngine.getService(serviceName);
MapServiceContext mapServiceContext = mapService.getMapServiceContext();
int partitionId = nodeEngine.getPartitionService().getPartitionId("key");
MyObject myObject = new MyObject();
Data dataKey = mapServiceContext.toData("key");
Data dataValue = mapServiceContext.toData(myObject);
RecordStore recordStore = mapServiceContext.getRecordStore(partitionId, name);
SplitBrainMergePolicyProvider mergePolicyProvider = nodeEngine.getSplitBrainMergePolicyProvider();
SplitBrainMergePolicy mergePolicy = mergePolicyProvider.getMergePolicy(PutIfAbsentMergePolicy.class.getName());
EntryView<Data, Data> mergingEntryView = new SimpleEntryView<>(dataKey, dataValue);
recordStore.merge(createMergingEntry(nodeEngine.getSerializationService(), mergingEntryView), mergePolicy, CallerProvenance.NOT_WAN);
int deSerializedCount = MyObject.deserializedCount;
assertEquals(0, deSerializedCount);
}
Aggregations