Search in sources :

Example 21 with MapServiceContext

use of com.hazelcast.map.impl.MapServiceContext 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");
    RecordStore recordStore = mapServiceContext.getRecordStore(getPartitionId(instance, "key"), name);
    MapMergePolicy mergePolicy = mapServiceContext.getMergePolicyProvider().getMergePolicy(PutIfAbsentMapMergePolicy.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("value1", map.get("key"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) 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 22 with MapServiceContext

use of com.hazelcast.map.impl.MapServiceContext in project hazelcast by hazelcast.

the class NearCacheTestSupport method getNearCache.

protected NearCache getNearCache(String mapName, HazelcastInstance instance) {
    NodeEngineImpl nodeEngine = getNode(instance).nodeEngine;
    MapService service = nodeEngine.getService(SERVICE_NAME);
    MapServiceContext mapServiceContext = service.getMapServiceContext();
    MapNearCacheManager mapNearCacheManager = mapServiceContext.getMapNearCacheManager();
    NearCacheConfig nearCacheConfig = nodeEngine.getConfig().getMapConfig(mapName).getNearCacheConfig();
    return mapNearCacheManager.getOrCreateNearCache(mapName, nearCacheConfig);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 23 with MapServiceContext

use of com.hazelcast.map.impl.MapServiceContext in project hazelcast by hazelcast.

the class InvalidationMetadataDistortionTest method distortRandomPartitionUuid.

private void distortRandomPartitionUuid(HazelcastInstance member) {
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(member);
    int partitionCount = nodeEngineImpl.getPartitionService().getPartitionCount();
    int partitionId = getInt(partitionCount);
    MapService mapService = nodeEngineImpl.getService(SERVICE_NAME);
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    MapNearCacheManager mapNearCacheManager = mapServiceContext.getMapNearCacheManager();
    Invalidator invalidator = mapNearCacheManager.getInvalidator();
    MetaDataGenerator metaDataGenerator = invalidator.getMetaDataGenerator();
    metaDataGenerator.setUuid(partitionId, UuidUtil.newSecureUUID());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MapNearCacheManager(com.hazelcast.map.impl.nearcache.MapNearCacheManager) Invalidator(com.hazelcast.internal.nearcache.impl.invalidation.Invalidator) MapService(com.hazelcast.map.impl.MapService) MetaDataGenerator(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 24 with MapServiceContext

use of com.hazelcast.map.impl.MapServiceContext in project hazelcast by hazelcast.

the class ContainsValueOperationTest method executeOperation.

protected InternalCompletableFuture<Object> executeOperation(Map map, String key, int value) {
    int partitionId = getNode(member1).getPartitionService().getPartitionId(key);
    MapProxyImpl mapProxy = (MapProxyImpl) map;
    MapServiceContext mapServiceContext = ((MapService) mapProxy.getService()).getMapServiceContext();
    MapOperationProvider operationProvider = mapServiceContext.getMapOperationProvider(mapProxy.getName());
    OperationFactory operationFactory = operationProvider.createContainsValueOperationFactory(mapProxy.getName(), mapServiceContext.toData(value));
    Operation operation = operationFactory.createOperation();
    InternalOperationService operationService = getOperationService(member1);
    return operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, partitionId).invoke();
}
Also used : MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) Operation(com.hazelcast.spi.Operation) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) OperationFactory(com.hazelcast.spi.OperationFactory)

Example 25 with MapServiceContext

use of com.hazelcast.map.impl.MapServiceContext in project hazelcast by hazelcast.

the class MapStoreWriteBehindTest method writeBehindQueueSize.

private 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();
        size += ((WriteBehindStore) mapDataStore).getWriteBehindQueue().size();
    }
    return size;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) WriteBehindStore(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore)

Aggregations

MapServiceContext (com.hazelcast.map.impl.MapServiceContext)63 MapService (com.hazelcast.map.impl.MapService)44 MapNearCacheManager (com.hazelcast.map.impl.nearcache.MapNearCacheManager)15 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)14 Invalidator (com.hazelcast.internal.nearcache.impl.invalidation.Invalidator)12 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)12 MetaDataGenerator (com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator)10 NodeEngine (com.hazelcast.spi.NodeEngine)10 MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 MapContainer (com.hazelcast.map.impl.MapContainer)6 Data (com.hazelcast.nio.serialization.Data)6 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)5 MapStoreConfig (com.hazelcast.config.MapStoreConfig)4 SimpleEntryView (com.hazelcast.map.impl.SimpleEntryView)4 HashMap (java.util.HashMap)4 Config (com.hazelcast.config.Config)3 MapConfig (com.hazelcast.config.MapConfig)3 NearCacheConfig (com.hazelcast.config.NearCacheConfig)3 Node (com.hazelcast.instance.Node)3