Search in sources :

Example 6 with MapProxyImpl

use of com.hazelcast.map.impl.proxy.MapProxyImpl in project hazelcast by hazelcast.

the class EvictionMaxSizePolicyTest method setMockRuntimeMemoryInfoAccessor.

public static void setMockRuntimeMemoryInfoAccessor(IMap map, final long totalMemoryMB, final long freeMemoryMB, final long maxMemoryMB) {
    final MapProxyImpl mapProxy = (MapProxyImpl) map;
    final MapService mapService = (MapService) mapProxy.getService();
    final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    MemoryInfoAccessor memoryInfoAccessor = new MemoryInfoAccessor() {

        @Override
        public long getTotalMemory() {
            return MEGABYTES.toBytes(totalMemoryMB);
        }

        @Override
        public long getFreeMemory() {
            return MEGABYTES.toBytes(freeMemoryMB);
        }

        @Override
        public long getMaxMemory() {
            return MEGABYTES.toBytes(maxMemoryMB);
        }
    };
    MapContainer mapContainer = mapServiceContext.getMapContainer(map.getName());
    MapEvictionPolicy mapEvictionPolicy = mapContainer.getMapConfig().getMapEvictionPolicy();
    EvictionChecker evictionChecker = new EvictionChecker(memoryInfoAccessor, mapServiceContext);
    IPartitionService partitionService = mapServiceContext.getNodeEngine().getPartitionService();
    Evictor evictor = new TestEvictor(mapEvictionPolicy, evictionChecker, partitionService);
    mapContainer.setEvictor(evictor);
}
Also used : EvictionChecker(com.hazelcast.map.impl.eviction.EvictionChecker) IPartitionService(com.hazelcast.spi.partition.IPartitionService) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) MemoryInfoAccessor(com.hazelcast.util.MemoryInfoAccessor) MapService(com.hazelcast.map.impl.MapService) Evictor(com.hazelcast.map.impl.eviction.Evictor) MapEvictionPolicy(com.hazelcast.map.eviction.MapEvictionPolicy) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 7 with MapProxyImpl

use of com.hazelcast.map.impl.proxy.MapProxyImpl 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 8 with MapProxyImpl

use of com.hazelcast.map.impl.proxy.MapProxyImpl in project hazelcast by hazelcast.

the class DynamicMapConfigTest method isEvictionEnabled.

private boolean isEvictionEnabled(IMap map) {
    MapProxyImpl mapProxy = (MapProxyImpl) map;
    MapService mapService = (MapService) mapProxy.getService();
    MapServiceContext mapServiceContext = (MapServiceContext) mapService.getMapServiceContext();
    MapContainer mapContainer = mapServiceContext.getMapContainer(map.getName());
    EvictionPolicy evictionPolicy = mapContainer.getMapConfig().getEvictionPolicy();
    return evictionPolicy != NONE;
}
Also used : EvictionPolicy(com.hazelcast.config.EvictionPolicy) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 9 with MapProxyImpl

use of com.hazelcast.map.impl.proxy.MapProxyImpl in project hazelcast by hazelcast.

the class MapPartitionIteratorTest method test_next_Throws_Exception_On_EmptyPartition.

@Test(expected = NoSuchElementException.class)
public void test_next_Throws_Exception_On_EmptyPartition() throws Exception {
    HazelcastInstance instance = createHazelcastInstance();
    MapProxyImpl<Object, Object> proxy = (MapProxyImpl<Object, Object>) instance.getMap(randomMapName());
    Iterator<Map.Entry<Object, Object>> iterator = proxy.iterator(10, 1, prefetchValues);
    iterator.next();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with MapProxyImpl

use of com.hazelcast.map.impl.proxy.MapProxyImpl in project hazelcast by hazelcast.

the class MapPartitionIteratorTest method test_HasNext_Returns_True_On_NonEmptyPartition.

@Test
public void test_HasNext_Returns_True_On_NonEmptyPartition() throws Exception {
    HazelcastInstance instance = createHazelcastInstance();
    MapProxyImpl<Object, Object> proxy = (MapProxyImpl<Object, Object>) instance.getMap(randomMapName());
    String key = generateKeyForPartition(instance, 1);
    String value = randomString();
    proxy.put(key, value);
    Iterator<Map.Entry<Object, Object>> iterator = proxy.iterator(10, 1, prefetchValues);
    assertTrue(iterator.hasNext());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)24 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 ParallelTest (com.hazelcast.test.annotation.ParallelTest)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 MapService (com.hazelcast.map.impl.MapService)10 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)7 Config (com.hazelcast.config.Config)3 DistributedObject (com.hazelcast.core.DistributedObject)3 MapContainer (com.hazelcast.map.impl.MapContainer)3 Map (java.util.Map)3 MapConfig (com.hazelcast.config.MapConfig)2 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)2 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)2 Address (com.hazelcast.nio.Address)2 NodeEngine (com.hazelcast.spi.NodeEngine)2 IPartitionService (com.hazelcast.spi.partition.IPartitionService)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 HashSet (java.util.HashSet)2 Ignore (org.junit.Ignore)2