Search in sources :

Example 6 with SplitBrainMergePolicyProvider

use of com.hazelcast.spi.merge.SplitBrainMergePolicyProvider in project hazelcast by hazelcast.

the class ConfigValidatorTest method setUp.

@Before
public void setUp() {
    Config config = new Config();
    nativeMemoryConfig = config.getNativeMemoryConfig();
    NodeEngine nodeEngine = Mockito.mock(NodeEngine.class);
    when(nodeEngine.getConfigClassLoader()).thenReturn(config.getClassLoader());
    splitBrainMergePolicyProvider = new SplitBrainMergePolicyProvider(config.getClassLoader());
    when(nodeEngine.getSplitBrainMergePolicyProvider()).thenReturn(splitBrainMergePolicyProvider);
    properties = nodeEngine.getProperties();
    logger = nodeEngine.getLogger(MapConfig.class);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) MapConfig(com.hazelcast.config.MapConfig) ConfigValidator.checkCacheConfig(com.hazelcast.internal.config.ConfigValidator.checkCacheConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) CPSubsystemConfig(com.hazelcast.config.cp.CPSubsystemConfig) Config(com.hazelcast.config.Config) ConfigValidator.checkNearCacheNativeMemoryConfig(com.hazelcast.internal.config.ConfigValidator.checkNearCacheNativeMemoryConfig) NativeMemoryConfig(com.hazelcast.config.NativeMemoryConfig) ConfigValidator.checkMapConfig(com.hazelcast.internal.config.ConfigValidator.checkMapConfig) ConfigValidator.checkCPSubsystemConfig(com.hazelcast.internal.config.ConfigValidator.checkCPSubsystemConfig) MapConfig(com.hazelcast.config.MapConfig) ConfigValidator.checkMapConfig(com.hazelcast.internal.config.ConfigValidator.checkMapConfig) SplitBrainMergePolicyProvider(com.hazelcast.spi.merge.SplitBrainMergePolicyProvider) Before(org.junit.Before)

Example 7 with SplitBrainMergePolicyProvider

use of com.hazelcast.spi.merge.SplitBrainMergePolicyProvider in project hazelcast by hazelcast.

the class MergePolicyValidatorTest method setUp.

@Before
public void setUp() {
    Config config = new Config();
    NodeEngine nodeEngine = Mockito.mock(NodeEngine.class);
    when(nodeEngine.getConfigClassLoader()).thenReturn(config.getClassLoader());
    mapMergePolicyProvider = new SplitBrainMergePolicyProvider(config.getClassLoader());
    when(nodeEngine.getSplitBrainMergePolicyProvider()).thenReturn(mapMergePolicyProvider);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Config(com.hazelcast.config.Config) SplitBrainMergePolicyProvider(com.hazelcast.spi.merge.SplitBrainMergePolicyProvider) Before(org.junit.Before)

Example 8 with SplitBrainMergePolicyProvider

use of com.hazelcast.spi.merge.SplitBrainMergePolicyProvider 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 9 with SplitBrainMergePolicyProvider

use of com.hazelcast.spi.merge.SplitBrainMergePolicyProvider 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 10 with SplitBrainMergePolicyProvider

use of com.hazelcast.spi.merge.SplitBrainMergePolicyProvider 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)

Aggregations

SplitBrainMergePolicyProvider (com.hazelcast.spi.merge.SplitBrainMergePolicyProvider)10 NodeEngine (com.hazelcast.spi.impl.NodeEngine)5 Config (com.hazelcast.config.Config)4 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 SplitBrainMergePolicy (com.hazelcast.spi.merge.SplitBrainMergePolicy)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 MapConfig (com.hazelcast.config.MapConfig)3 ConfigValidator.checkCacheConfig (com.hazelcast.internal.config.ConfigValidator.checkCacheConfig)2 ConfigValidator.checkMapConfig (com.hazelcast.internal.config.ConfigValidator.checkMapConfig)2 PutIfAbsentMergePolicy (com.hazelcast.spi.merge.PutIfAbsentMergePolicy)2 Before (org.junit.Before)2 CacheService (com.hazelcast.cache.impl.CacheService)1 ICacheService (com.hazelcast.cache.impl.ICacheService)1 PreJoinCacheConfig (com.hazelcast.cache.impl.PreJoinCacheConfig)1