Search in sources :

Example 66 with MapConfig

use of com.hazelcast.config.MapConfig in project hazelcast by hazelcast.

the class RecordStoreTest method testRecordStoreReset.

private IMap<Object, Object> testRecordStoreReset() {
    String mapName = randomName();
    Config config = new Config();
    MapConfig mapConfig = config.getMapConfig(mapName);
    MapIndexConfig indexConfig = new MapIndexConfig("name", false);
    mapConfig.addMapIndexConfig(indexConfig);
    HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
    IMap<Object, Object> map = hazelcastInstance.getMap(mapName);
    int key = 1;
    map.put(key, new SampleObjects.Employee("tom", 24, true, 10));
    DefaultRecordStore defaultRecordStore = getRecordStore(map, key);
    defaultRecordStore.reset();
    assertNull(map.get(key));
    return map;
}
Also used : MapIndexConfig(com.hazelcast.config.MapIndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SampleObjects(com.hazelcast.query.SampleObjects) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapConfig(com.hazelcast.config.MapConfig) MapConfig(com.hazelcast.config.MapConfig) DefaultRecordStore(com.hazelcast.map.impl.recordstore.DefaultRecordStore)

Example 67 with MapConfig

use of com.hazelcast.config.MapConfig in project hazelcast by hazelcast.

the class StoreLatencyPlugin_MapIntegrationTest method addMapConfig.

private static MapConfig addMapConfig(Config config) {
    MapConfig mapConfig = config.getMapConfig("mappy");
    mapConfig.getMapStoreConfig().setEnabled(true).setImplementation(new MapStore() {

        private final Random random = new Random();

        @Override
        public void store(Object key, Object value) {
        }

        @Override
        public Object load(Object key) {
            randomSleep();
            return null;
        }

        private void randomSleep() {
            long delay = random.nextInt(100);
            try {
                Thread.sleep(delay);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        @Override
        public Map loadAll(Collection keys) {
            return null;
        }

        @Override
        public void storeAll(Map map) {
        }

        @Override
        public void delete(Object key) {
        }

        @Override
        public Iterable loadAllKeys() {
            return null;
        }

        @Override
        public void deleteAll(Collection keys) {
        }
    });
    return mapConfig;
}
Also used : Random(java.util.Random) MapStore(com.hazelcast.core.MapStore) Collection(java.util.Collection) MapConfig(com.hazelcast.config.MapConfig) Map(java.util.Map)

Example 68 with MapConfig

use of com.hazelcast.config.MapConfig in project hazelcast by hazelcast.

the class MigrationTest method testMigration_whenRemovingInstances_withStatisticsDisabled.

@Test
public void testMigration_whenRemovingInstances_withStatisticsDisabled() {
    int size = 100;
    String name = randomString();
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(name);
    mapConfig.setStatisticsEnabled(false);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance3 = nodeFactory.newHazelcastInstance(config);
    IMap<Integer, Integer> map = instance1.getMap(name);
    for (int i = 0; i < size; i++) {
        map.put(i, i);
    }
    instance2.shutdown();
    instance3.shutdown();
    waitAllForSafeState(instance1);
    assertEquals("Some records have been lost.", size, map.values().size());
    for (int i = 0; i < size; i++) {
        assertEquals(i, map.get(i).intValue());
    }
    assertThatMigrationIsDoneAndReplicasAreIntact(singletonList(instance1));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 69 with MapConfig

use of com.hazelcast.config.MapConfig in project hazelcast by hazelcast.

the class AbstractMapStoreTest method newConfig.

public Config newConfig(String mapName, Object storeImpl, int writeDelaySeconds, MapStoreConfig.InitialLoadMode loadMode) {
    Config config = getConfig();
    config.getManagementCenterConfig().setEnabled(false);
    MapConfig mapConfig = config.getMapConfig(mapName);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setImplementation(storeImpl);
    mapStoreConfig.setWriteDelaySeconds(writeDelaySeconds);
    mapStoreConfig.setInitialLoadMode(loadMode);
    mapConfig.setMapStoreConfig(mapStoreConfig);
    return config;
}
Also used : MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig)

Example 70 with MapConfig

use of com.hazelcast.config.MapConfig in project hazelcast by hazelcast.

the class MapClassLoaderTest method testIssue2721.

// https://github.com/hazelcast/hazelcast/issues/2721
@Test
public void testIssue2721() throws InterruptedException {
    final Config config = new Config();
    // get map config
    final MapConfig mapConfig = config.getMapConfig(MAP_NAME);
    // create shared map store implementation
    final InMemoryMapStore store = new InMemoryMapStore();
    store.preload(PRE_LOAD_SIZE);
    // create map store config
    final MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
    mapStoreConfig.setWriteDelaySeconds(WRITE_DELAY_SECONDS);
    mapStoreConfig.setClassName(null);
    mapStoreConfig.setImplementation(store);
    mapConfig.setMapStoreConfig(mapStoreConfig);
    final HazelcastInstance instance = createHazelcastInstance(config);
    // Get map so map store is triggered
    instance.getMap(MAP_NAME);
    boolean anEmptyCtxClassLoaderExist = false;
    // test if all load threads had a context class loader set
    for (boolean hasCtxClassLoader : store.getContextClassLoaders().values()) {
        if (!hasCtxClassLoader) {
            anEmptyCtxClassLoaderExist = true;
            break;
        }
    }
    assertFalse(anEmptyCtxClassLoaderExist);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MapConfig (com.hazelcast.config.MapConfig)182 Config (com.hazelcast.config.Config)125 HazelcastInstance (com.hazelcast.core.HazelcastInstance)78 Test (org.junit.Test)75 QuickTest (com.hazelcast.test.annotation.QuickTest)68 ParallelTest (com.hazelcast.test.annotation.ParallelTest)62 MapStoreConfig (com.hazelcast.config.MapStoreConfig)43 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)41 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)28 NearCacheConfig (com.hazelcast.config.NearCacheConfig)27 MapIndexConfig (com.hazelcast.config.MapIndexConfig)20 QuorumConfig (com.hazelcast.config.QuorumConfig)19 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)18 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 NightlyTest (com.hazelcast.test.annotation.NightlyTest)12 PartitionedCluster (com.hazelcast.quorum.PartitionedCluster)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 BeforeClass (org.junit.BeforeClass)10 AssertTask (com.hazelcast.test.AssertTask)9