use of com.hazelcast.map.impl.MapServiceContext in project hazelcast by hazelcast.
the class EvictionMaxSizePolicyTest method setTestSizeEstimator.
public static void setTestSizeEstimator(IMap map, final long oneEntryHeapCostInBytes) {
final MapProxyImpl mapProxy = (MapProxyImpl) map;
final MapService mapService = (MapService) mapProxy.getService();
final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
final IPartitionService partitionService = nodeEngine.getPartitionService();
for (int i = 0; i < partitionService.getPartitionCount(); i++) {
final Address owner = partitionService.getPartitionOwner(i);
if (nodeEngine.getThisAddress().equals(owner)) {
final PartitionContainer container = mapServiceContext.getPartitionContainer(i);
if (container == null) {
continue;
}
final RecordStore recordStore = container.getRecordStore(map.getName());
final DefaultRecordStore defaultRecordStore = (DefaultRecordStore) recordStore;
defaultRecordStore.setSizeEstimator(new EntryCostEstimator() {
long size;
@Override
public long getEstimate() {
return size;
}
@Override
public void adjustEstimateBy(long size) {
this.size += size;
}
@Override
public long calculateValueCost(Object record) {
if (record == null) {
return 0L;
}
return oneEntryHeapCostInBytes;
}
@Override
public long calculateEntryCost(Object key, Object record) {
if (record == null) {
return 0L;
}
return 2 * oneEntryHeapCostInBytes;
}
@Override
public void reset() {
size = 0;
}
});
}
}
}
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");
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(PutIfAbsentMergePolicy.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("value1", map.get("key"));
recordStore.afterOperation();
}
use of com.hazelcast.map.impl.MapServiceContext in project hazelcast by hazelcast.
the class LocalListenerTest method injectLogger.
private void injectLogger(HazelcastInstance instance, MapEventPublisherLogger mapEventPublisherLogger) throws IllegalAccessException {
NodeEngineImpl nodeEngine1 = getNodeEngineImpl(instance);
MapService mapService = nodeEngine1.getService(MapService.SERVICE_NAME);
MapServiceContext mapServiceContext = mapService.getMapServiceContext();
MapEventPublisher mapEventPublisher = mapServiceContext.getMapEventPublisher();
setFieldValueReflectively(mapEventPublisher, "logger", mapEventPublisherLogger);
}
use of com.hazelcast.map.impl.MapServiceContext in project hazelcast by hazelcast.
the class EntryEventDataCacheTest method parameters.
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> parameters() {
// setup mock MapServiceContext & NodeEngine, required by FilteringStrategy's
MapServiceContext mapServiceContext = mock(MapServiceContext.class);
NodeEngine mockNodeEngine = mock(NodeEngine.class);
when(mockNodeEngine.getThisAddress()).thenReturn(ADDRESS);
when(mapServiceContext.toData(anyObject())).thenReturn(new HeapData());
when(mapServiceContext.getNodeEngine()).thenReturn(mockNodeEngine);
return Arrays.asList(new Object[][] { { new DefaultEntryEventFilteringStrategy(null, mapServiceContext) }, { new QueryCacheNaturalFilteringStrategy(null, mapServiceContext) } });
}
use of com.hazelcast.map.impl.MapServiceContext in project hazelcast by hazelcast.
the class EntryLoaderSimpleTest method testLoadEntryAtCurrentTime.
@Test
public void testLoadEntryAtCurrentTime() {
testEntryLoader.putExternally("key", "value", 42);
MapService service = getNodeEngineImpl(instances[0]).getService(MapService.SERVICE_NAME);
MapServiceContext mapServiceContext = service.getMapServiceContext();
Config config = mapServiceContext.getNodeEngine().getConfig();
MapContainer mapContainer = new MapContainer("anyName", config, mapServiceContext);
Data key = mapServiceContext.toData("key");
DefaultRecordStore recordStore = new DefaultRecordStore(mapContainer, 0, mock(MapKeyLoader.class), mock(ILogger.class));
assertNull(recordStore.loadRecordOrNull(key, false, null));
}
Aggregations