Search in sources :

Example 11 with MapContainer

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

the class MapContainerCreationUponDestroyStressTest method assertRecordStoresSharesSameMapContainerInstance.

private void assertRecordStoresSharesSameMapContainerInstance(IMap<Long, Long> map) {
    String mapName = map.getName();
    MapContainer expectedMapContainer = getMapContainer(map);
    for (int i = 0; i < PARTITION_COUNT; i++) {
        PartitionContainer partitionContainer = getMapServiceContext(map).getPartitionContainer(i);
        RecordStore recordStore = partitionContainer.getMaps().get(mapName);
        if (recordStore == null) {
            continue;
        }
        assertEquals(expectedMapContainer, recordStore.getMapContainer());
    }
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 12 with MapContainer

use of com.hazelcast.map.impl.MapContainer 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 13 with MapContainer

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

the class IndexIntegrationTest method getIndexOfAttributeForMap.

private static Index getIndexOfAttributeForMap(HazelcastInstance instance, String mapName, String attribute) {
    Node node = getNode(instance);
    MapService service = node.nodeEngine.getService(MapService.SERVICE_NAME);
    MapServiceContext mapServiceContext = service.getMapServiceContext();
    MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
    Indexes indexes = mapContainer.getIndexes();
    return indexes.getIndex(attribute);
}
Also used : Node(com.hazelcast.instance.Node) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 14 with MapContainer

use of com.hazelcast.map.impl.MapContainer 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 15 with MapContainer

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

the class PostJoinMapOperationTest method testPostJoinMapOperation_whenMapHasNoData.

@Test
public void testPostJoinMapOperation_whenMapHasNoData() {
    TestHazelcastInstanceFactory hzFactory = createHazelcastInstanceFactory(2);
    // given: a single node HazelcastInstance with a map configured with index and interceptor
    HazelcastInstance hz1 = hzFactory.newHazelcastInstance();
    IMap<String, Person> map = hz1.getMap("map");
    map.addIndex("age", true);
    map.addInterceptor(new FixedReturnInterceptor());
    assertEquals(RETURNED_FROM_INTERCEPTOR, map.get("foo"));
    // when: another member joins the cluster
    HazelcastInstance hz2 = hzFactory.newHazelcastInstance();
    waitAllForSafeState(hz1, hz2);
    // then: index & interceptor exist on internal MapContainer on node that joined the cluster
    MapService mapService = getNodeEngineImpl(hz2).getService(MapService.SERVICE_NAME);
    MapContainer mapContainerOnNode2 = mapService.getMapServiceContext().getMapContainer("map");
    assertEquals(1, mapContainerOnNode2.getIndexes().getIndexes().length);
    assertEquals(1, mapContainerOnNode2.getInterceptorRegistry().getInterceptors().size());
    assertEquals(Person.class, mapContainerOnNode2.getInterceptorRegistry().getInterceptors().get(0).interceptGet("anything").getClass());
    assertEquals(RETURNED_FROM_INTERCEPTOR.getAge(), ((Person) mapContainerOnNode2.getInterceptorRegistry().getInterceptors().get(0).interceptGet("anything")).getAge());
    // also verify via user API
    IMap<String, Person> mapOnNode2 = hz2.getMap("map");
    assertEquals(RETURNED_FROM_INTERCEPTOR, mapOnNode2.get("whatever"));
    hzFactory.terminateAll();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapService(com.hazelcast.map.impl.MapService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MapContainer(com.hazelcast.map.impl.MapContainer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MapContainer (com.hazelcast.map.impl.MapContainer)25 MapService (com.hazelcast.map.impl.MapService)10 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)6 Data (com.hazelcast.nio.serialization.Data)5 MapConfig (com.hazelcast.config.MapConfig)4 Record (com.hazelcast.map.impl.record.Record)4 Map (java.util.Map)4 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)3 MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)3 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)3 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)3 HashMap (java.util.HashMap)3 EntryView (com.hazelcast.core.EntryView)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 EntryViews.createSimpleEntryView (com.hazelcast.map.impl.EntryViews.createSimpleEntryView)2 Predicate (com.hazelcast.query.Predicate)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 Config (com.hazelcast.config.Config)1