Search in sources :

Example 41 with MapStoreConfig

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

the class ClientMapNearCacheTest method testMemberLoadAll_invalidates_clientNearCache.

@Test
public void testMemberLoadAll_invalidates_clientNearCache() {
    int mapSize = 1000;
    String mapName = randomMapName();
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(newConfig());
    HazelcastInstance client = getClient(hazelcastFactory, newInvalidationOnChangeEnabledNearCacheConfig(mapName));
    Config config = member.getConfig();
    SimpleMapStore store = new SimpleMapStore();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(store);
    config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
    final IMap<Integer, Integer> clientMap = client.getMap(mapName);
    populateMap(clientMap, mapSize);
    populateNearCache(clientMap, mapSize);
    IMap<Integer, Integer> map = member.getMap(mapName);
    map.loadAll(true);
    assertTrueEventually(new AssertTask() {

        public void run() {
            assertThatOwnedEntryCountEquals(clientMap, 0);
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) MapStoreConfig(com.hazelcast.config.MapStoreConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 42 with MapStoreConfig

use of com.hazelcast.config.MapStoreConfig 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 43 with MapStoreConfig

use of com.hazelcast.config.MapStoreConfig 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)

Example 44 with MapStoreConfig

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

the class MapStoreTest method testInitialLoadModeEagerMultipleThread.

@Test(timeout = 120000)
public void testInitialLoadModeEagerMultipleThread() {
    final String mapName = "default";
    final int instanceCount = 2;
    final int size = 10000;
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(instanceCount);
    final CountDownLatch countDownLatch = new CountDownLatch(instanceCount - 1);
    final Config config = getConfig();
    GroupConfig groupConfig = new GroupConfig("testEager");
    config.setGroupConfig(groupConfig);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new SimpleMapLoader(size, true));
    mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
    config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    Runnable runnable = new Runnable() {

        public void run() {
            HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
            final IMap<Object, Object> map = instance2.getMap(mapName);
            assertEquals(size, map.size());
            countDownLatch.countDown();
        }
    };
    new Thread(runnable).start();
    assertOpenEventually(countDownLatch, 120);
    IMap map = instance1.getMap(mapName);
    assertEquals(size, map.size());
}
Also used : MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) CountDownLatch(java.util.concurrent.CountDownLatch) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) GroupConfig(com.hazelcast.config.GroupConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 45 with MapStoreConfig

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

the class MapStoreTest method testIssue1115EnablingMapstoreMutatingValue.

@Test(timeout = 120000)
public void testIssue1115EnablingMapstoreMutatingValue() throws InterruptedException {
    Config config = getConfig();
    String mapName = "testIssue1115";
    MapStore mapStore = new ProcessingStore();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(mapStore);
    config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    nodeFactory.newHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap(mapName);
    Random random = new Random();
    // testing put with new object
    for (int i = 0; i < 10; i++) {
        Employee emp = new Employee();
        emp.setAge(random.nextInt(20) + 20);
        map.put(i, emp);
    }
    for (int i = 0; i < 10; i++) {
        Employee employee = map.get(i);
        assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
    // testing put with existing object
    for (int i = 0; i < 10; i++) {
        Employee emp = map.get(i);
        emp.setAge(random.nextInt(20) + 20);
        map.put(i, emp);
    }
    for (int i = 0; i < 10; i++) {
        Employee employee = map.get(i);
        assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
    // testing put with replace
    for (int i = 0; i < 10; i++) {
        Employee emp = map.get(i);
        emp.setAge(random.nextInt(20) + 20);
        map.replace(i, emp);
    }
    for (int i = 0; i < 10; i++) {
        Employee employee = map.get(i);
        assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
    // testing put with putIfAbsent
    for (int i = 10; i < 20; i++) {
        Employee emp = new Employee();
        emp.setAge(random.nextInt(20) + 20);
        map.putIfAbsent(i, emp);
    }
    for (int i = 10; i < 20; i++) {
        Employee employee = map.get(i);
        assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) Random(java.util.Random) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) MapStore(com.hazelcast.core.MapStore) PostProcessingMapStore(com.hazelcast.core.PostProcessingMapStore) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MapStoreConfig (com.hazelcast.config.MapStoreConfig)76 Config (com.hazelcast.config.Config)70 MapConfig (com.hazelcast.config.MapConfig)61 HazelcastInstance (com.hazelcast.core.HazelcastInstance)51 Test (org.junit.Test)50 QuickTest (com.hazelcast.test.annotation.QuickTest)43 ParallelTest (com.hazelcast.test.annotation.ParallelTest)42 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)23 GroupConfig (com.hazelcast.config.GroupConfig)21 IMap (com.hazelcast.core.IMap)12 AssertTask (com.hazelcast.test.AssertTask)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 MapIndexConfig (com.hazelcast.config.MapIndexConfig)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 NightlyTest (com.hazelcast.test.annotation.NightlyTest)8 HashSet (java.util.HashSet)8 NearCacheConfig (com.hazelcast.config.NearCacheConfig)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 MapStoreAdapter (com.hazelcast.core.MapStoreAdapter)5