use of com.hazelcast.spi.merge.SplitBrainMergePolicy 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);
}
use of com.hazelcast.spi.merge.SplitBrainMergePolicy in project hazelcast by hazelcast.
the class MapMergePolicyQuickTest method testPassThroughMapMergePolicy.
@Test
public void testPassThroughMapMergePolicy() {
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(PassThroughMergePolicy.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("value2", map.get("key"));
recordStore.afterOperation();
}
use of com.hazelcast.spi.merge.SplitBrainMergePolicy in project hazelcast by hazelcast.
the class MapMergePolicyQuickTest method testLatestUpdateMapMergePolicy.
@Test
public void testLatestUpdateMapMergePolicy() {
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(LatestUpdateMergePolicy.class.getName());
long now = Clock.currentTimeMillis();
SimpleEntryView<Data, Data> initialEntry = new SimpleEntryView<>(dataKey, dataValue);
initialEntry.setCreationTime(now);
initialEntry.setLastUpdateTime(now);
// need some latency to be sure that target members time is greater than now
sleepMillis(100);
recordStore.merge(createMergingEntry(nodeEngine.getSerializationService(), initialEntry), mergePolicy, CallerProvenance.NOT_WAN);
SimpleEntryView<Data, Data> mergingEntry = new SimpleEntryView<>(dataKey, dataValue2);
now = Clock.currentTimeMillis();
mergingEntry.setCreationTime(now);
mergingEntry.setLastUpdateTime(now);
recordStore.merge(createMergingEntry(nodeEngine.getSerializationService(), mergingEntry), mergePolicy, CallerProvenance.NOT_WAN);
assertEquals("value2", map.get("key"));
recordStore.afterOperation();
}
use of com.hazelcast.spi.merge.SplitBrainMergePolicy in project hazelcast by hazelcast.
the class TestContainerMerger method runInternal.
@Override
protected void runInternal() {
MergePolicyConfig mergePolicyConfig = new MergePolicyConfig();
SplitBrainMergePolicy mergePolicy = getMergePolicy(mergePolicyConfig);
assertNotNull("Expected to retrieve a merge policy, but was null", mergePolicy);
if (mergeOperation != null) {
invoke(MapService.SERVICE_NAME, mergeOperation, 1);
}
}
Aggregations