Search in sources :

Example 6 with SplitBrainMergePolicy

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

Example 7 with SplitBrainMergePolicy

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();
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) SplitBrainMergePolicy(com.hazelcast.spi.merge.SplitBrainMergePolicy) HazelcastInstance(com.hazelcast.core.HazelcastInstance) PassThroughMergePolicy(com.hazelcast.spi.merge.PassThroughMergePolicy) 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 8 with SplitBrainMergePolicy

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

Example 9 with SplitBrainMergePolicy

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);
    }
}
Also used : MergePolicyConfig(com.hazelcast.config.MergePolicyConfig) SplitBrainMergePolicy(com.hazelcast.spi.merge.SplitBrainMergePolicy)

Aggregations

SplitBrainMergePolicy (com.hazelcast.spi.merge.SplitBrainMergePolicy)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Data (com.hazelcast.internal.serialization.Data)4 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)4 SimpleEntryView (com.hazelcast.map.impl.SimpleEntryView)4 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)4 SplitBrainMergePolicyProvider (com.hazelcast.spi.merge.SplitBrainMergePolicyProvider)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 NodeEngine (com.hazelcast.spi.impl.NodeEngine)3 PutIfAbsentMergePolicy (com.hazelcast.spi.merge.PutIfAbsentMergePolicy)2 MergePolicyConfig (com.hazelcast.config.MergePolicyConfig)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 MapService (com.hazelcast.map.impl.MapService)1 MapOperation (com.hazelcast.map.impl.operation.MapOperation)1 MapOperationProvider (com.hazelcast.map.impl.operation.MapOperationProvider)1 WanMapAddOrUpdateEvent (com.hazelcast.map.impl.wan.WanMapAddOrUpdateEvent)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1