Search in sources :

Example 16 with RecordStore

use of com.hazelcast.map.impl.recordstore.RecordStore 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 17 with RecordStore

use of com.hazelcast.map.impl.recordstore.RecordStore 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");
    RecordStore recordStore = mapServiceContext.getRecordStore(getPartitionId(instance, "key"), name);
    MapMergePolicy mergePolicy = mapServiceContext.getMergePolicyProvider().getMergePolicy(LatestUpdateMapMergePolicy.class.getName());
    long now = Clock.currentTimeMillis();
    SimpleEntryView<String, String> initialEntry = new SimpleEntryView<String, String>("key", "value1");
    initialEntry.setCreationTime(now);
    initialEntry.setLastUpdateTime(now);
    // need some latency to be sure that target members time is greater than now
    sleepMillis(100);
    recordStore.merge(dataKey, initialEntry, mergePolicy);
    SimpleEntryView<String, String> mergingEntry = new SimpleEntryView<String, String>("key", "value2");
    now = Clock.currentTimeMillis();
    mergingEntry.setCreationTime(now);
    mergingEntry.setLastUpdateTime(now);
    recordStore.merge(dataKey, mergingEntry, mergePolicy);
    assertEquals("value2", map.get("key"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) Data(com.hazelcast.nio.serialization.Data) LatestUpdateMapMergePolicy(com.hazelcast.map.merge.LatestUpdateMapMergePolicy) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) MapMergePolicy(com.hazelcast.map.merge.MapMergePolicy) LatestUpdateMapMergePolicy(com.hazelcast.map.merge.LatestUpdateMapMergePolicy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with RecordStore

use of com.hazelcast.map.impl.recordstore.RecordStore 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");
    RecordStore recordStore = mapServiceContext.getRecordStore(getPartitionId(instance, "key"), name);
    MapMergePolicy mergePolicy = mapServiceContext.getMergePolicyProvider().getMergePolicy(PassThroughMergePolicy.class.getName());
    SimpleEntryView<String, String> initialEntry = new SimpleEntryView<String, String>("key", "value1");
    recordStore.merge(dataKey, initialEntry, mergePolicy);
    SimpleEntryView<String, String> mergingEntry = new SimpleEntryView<String, String>("key", "value2");
    recordStore.merge(dataKey, mergingEntry, mergePolicy);
    assertEquals("value2", map.get("key"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PassThroughMergePolicy(com.hazelcast.map.merge.PassThroughMergePolicy) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) Data(com.hazelcast.nio.serialization.Data) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) MapMergePolicy(com.hazelcast.map.merge.MapMergePolicy) LatestUpdateMapMergePolicy(com.hazelcast.map.merge.LatestUpdateMapMergePolicy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with RecordStore

use of com.hazelcast.map.impl.recordstore.RecordStore in project hazelcast by hazelcast.

the class MapDestroyTest method assertAllPartitionContainersAreEmpty.

private void assertAllPartitionContainersAreEmpty(HazelcastInstance instance) {
    MapServiceContext context = getMapServiceContext(instance);
    int partitionCount = getPartitionCount(instance);
    for (int i = 0; i < partitionCount; i++) {
        PartitionContainer container = context.getPartitionContainer(i);
        ConcurrentMap<String, RecordStore> maps = container.getMaps();
        assertTrue(maps.isEmpty());
    }
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 20 with RecordStore

use of com.hazelcast.map.impl.recordstore.RecordStore in project hazelcast by hazelcast.

the class WriteBehindOnBackupsTest method writeBehindQueueSize.

public static int writeBehindQueueSize(HazelcastInstance node, String mapName) {
    int size = 0;
    final NodeEngineImpl nodeEngine = getNode(node).getNodeEngine();
    MapService mapService = nodeEngine.getService(MapService.SERVICE_NAME);
    final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    final int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
    for (int i = 0; i < partitionCount; i++) {
        final RecordStore recordStore = mapServiceContext.getExistingRecordStore(i, mapName);
        if (recordStore == null) {
            continue;
        }
        final MapDataStore mapDataStore = recordStore.getMapDataStore();
        if (mapDataStore instanceof WriteBehindStore) {
            size += ((WriteBehindStore) mapDataStore).getWriteBehindQueue().size();
        }
    }
    return size;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MapDataStore(com.hazelcast.map.impl.mapstore.MapDataStore) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Aggregations

RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)31 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)12 MapService (com.hazelcast.map.impl.MapService)8 Data (com.hazelcast.nio.serialization.Data)7 Map (java.util.Map)7 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)6 HashMap (java.util.HashMap)6 IPartitionService (com.hazelcast.spi.partition.IPartitionService)5 ArrayList (java.util.ArrayList)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 SimpleEntryView (com.hazelcast.map.impl.SimpleEntryView)4 DelayedEntry (com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)4 Record (com.hazelcast.map.impl.record.Record)4 DefaultRecordStore (com.hazelcast.map.impl.recordstore.DefaultRecordStore)4 MapMergePolicy (com.hazelcast.map.merge.MapMergePolicy)4 PutIfAbsentMapMergePolicy (com.hazelcast.map.merge.PutIfAbsentMapMergePolicy)4 NodeEngine (com.hazelcast.spi.NodeEngine)4 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4