Search in sources :

Example 1 with SimpleEntryView

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();
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) SplitBrainMergePolicy(com.hazelcast.spi.merge.SplitBrainMergePolicy) HazelcastInstance(com.hazelcast.core.HazelcastInstance) PutIfAbsentMergePolicy(com.hazelcast.spi.merge.PutIfAbsentMergePolicy) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) Data(com.hazelcast.internal.serialization.Data) SplitBrainMergePolicyProvider(com.hazelcast.spi.merge.SplitBrainMergePolicyProvider) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with SimpleEntryView

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;
}
Also used : MapGetEntryViewCodec(com.hazelcast.client.impl.protocol.codec.MapGetEntryViewCodec) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 3 with SimpleEntryView

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);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Data(com.hazelcast.nio.serialization.Data) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) MapService(com.hazelcast.map.impl.MapService) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) MapMergePolicy(com.hazelcast.map.merge.MapMergePolicy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with SimpleEntryView

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;
}
Also used : SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) Data(com.hazelcast.internal.serialization.Data)

Example 5 with SimpleEntryView

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);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Data(com.hazelcast.internal.serialization.Data) SplitBrainMergePolicyProvider(com.hazelcast.spi.merge.SplitBrainMergePolicyProvider) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) SplitBrainMergePolicy(com.hazelcast.spi.merge.SplitBrainMergePolicy) HazelcastInstance(com.hazelcast.core.HazelcastInstance) PutIfAbsentMergePolicy(com.hazelcast.spi.merge.PutIfAbsentMergePolicy) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) MapService(com.hazelcast.map.impl.MapService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SimpleEntryView (com.hazelcast.map.impl.SimpleEntryView)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 Data (com.hazelcast.internal.serialization.Data)6 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)6 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 SplitBrainMergePolicy (com.hazelcast.spi.merge.SplitBrainMergePolicy)4 SplitBrainMergePolicyProvider (com.hazelcast.spi.merge.SplitBrainMergePolicyProvider)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 MapService (com.hazelcast.map.impl.MapService)3 NodeEngine (com.hazelcast.spi.impl.NodeEngine)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 Data (com.hazelcast.nio.serialization.Data)2 PutIfAbsentMergePolicy (com.hazelcast.spi.merge.PutIfAbsentMergePolicy)2 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 MapGetEntryViewCodec (com.hazelcast.client.impl.protocol.codec.MapGetEntryViewCodec)1 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1 MapOperation (com.hazelcast.map.impl.operation.MapOperation)1