use of com.hazelcast.map.impl.recordstore.RecordStore 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.recordstore.RecordStore 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"));
}
use of com.hazelcast.map.impl.recordstore.RecordStore 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;
}
use of com.hazelcast.map.impl.recordstore.RecordStore in project hazelcast by hazelcast.
the class DynamicMapConfigTest method isRecordStoreExpirable.
private boolean isRecordStoreExpirable(IMap map) {
MapProxyImpl mapProxy = (MapProxyImpl) map;
MapService mapService = (MapService) mapProxy.getService();
MapServiceContext mapServiceContext = (MapServiceContext) mapService.getMapServiceContext();
PartitionContainer container = mapServiceContext.getPartitionContainer(0);
RecordStore recordStore = container.getExistingRecordStore(map.getName());
return recordStore.isExpirable();
}
use of com.hazelcast.map.impl.recordstore.RecordStore in project hazelcast by hazelcast.
the class QueryResultSizeLimiterTest method initMocksWithConfiguration.
private void initMocksWithConfiguration(int maxResultSizeLimit, int maxLocalPartitionLimitForPreCheck, int partitionCount) {
Config config = new Config();
config.setProperty(QUERY_RESULT_SIZE_LIMIT.getName(), valueOf(maxResultSizeLimit));
config.setProperty(QUERY_MAX_LOCAL_PARTITION_LIMIT_FOR_PRE_CHECK.getName(), valueOf(maxLocalPartitionLimitForPreCheck));
config.setProperty(PARTITION_COUNT.getName(), valueOf(partitionCount));
HazelcastProperties hazelcastProperties = new HazelcastProperties(config);
InternalPartitionService partitionService = mock(InternalPartitionService.class);
when(partitionService.getPartitionCount()).thenReturn(partitionCount);
NodeEngine nodeEngine = mock(NodeEngine.class);
when(nodeEngine.getProperties()).thenReturn(hazelcastProperties);
when(nodeEngine.getPartitionService()).thenReturn(partitionService);
RecordStore recordStore = mock(RecordStore.class);
when(recordStore.size()).then(new RecordStoreAnswer(localPartitions.values()));
MapServiceContext mapServiceContext = mock(MapServiceContext.class);
when(mapServiceContext.getNodeEngine()).thenReturn(nodeEngine);
when(mapServiceContext.getRecordStore(anyInt(), anyString())).thenReturn(recordStore);
when(mapServiceContext.getOwnedPartitions()).thenReturn(localPartitions.keySet());
limiter = new QueryResultSizeLimiter(mapServiceContext, Logger.getLogger(QueryResultSizeLimiterTest.class));
}
Aggregations