Search in sources :

Example 6 with TestMapStore

use of com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore in project hazelcast by hazelcast.

the class MapStoreWriteThroughTest method testTwoMemberWriteThrough.

@Test(timeout = 120000)
public void testTwoMemberWriteThrough() throws Exception {
    TestMapStore testMapStore = new TestMapStore(1, 1, 1);
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 0);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    nodeFactory.newHazelcastInstance(config);
    Employee employee = new Employee("joe", 25, true, 100.00);
    Employee employee2 = new Employee("jay", 35, false, 100.00);
    testMapStore.insert("1", employee);
    IMap<String, Employee> map = instance.getMap("default");
    map.addIndex("name", false);
    assertEquals(0, map.size());
    assertEquals(employee, map.get("1"));
    assertEquals(employee, testMapStore.getStore().get("1"));
    assertEquals(1, map.size());
    map.put("2", employee2);
    assertEquals(employee2, testMapStore.getStore().get("2"));
    assertEquals(2, testMapStore.getStore().size());
    assertEquals(2, map.size());
    map.remove("2");
    assertEquals(1, testMapStore.getStore().size());
    assertEquals(1, map.size());
    testMapStore.assertAwait(10);
    assertEquals(5, testMapStore.callCount.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with TestMapStore

use of com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore in project hazelcast by hazelcast.

the class MapStoreWriteBehindTest method testOneMemberWriteBehindFlush.

@Test(timeout = 120000)
public void testOneMemberWriteBehindFlush() throws Exception {
    TestMapStore testMapStore = new TestMapStore(1, 1, 1);
    testMapStore.setLoadAllKeys(false);
    int writeDelaySeconds = 2;
    Config config = newConfig(testMapStore, writeDelaySeconds);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    IMap<String, String> map = instance.getMap("default");
    assertEquals(0, map.size());
    long timeBeforePut = System.nanoTime();
    assertEquals("Map produced a value out of thin air", null, map.put("1", "value1"));
    assertEquals("Map did not return a previously stored value", "value1", map.get("1"));
    String mapStoreValue = (String) testMapStore.getStore().get("1");
    if (mapStoreValue != null) {
        assertMapStoreDidNotFlushValueTooSoon(testMapStore, writeDelaySeconds, timeBeforePut);
        assertEquals("value1", mapStoreValue);
    }
    assertEquals(1, map.size());
    map.flush();
    assertEquals("value1", testMapStore.getStore().get("1"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with TestMapStore

use of com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore in project hazelcast by hazelcast.

the class MapStoreWriteBehindTest method testWriteBehindSameSecondSameKey.

@Test(timeout = 120000)
public void testWriteBehindSameSecondSameKey() throws Exception {
    // In some cases 2 store operation may happened
    final TestMapStore testMapStore = new TestMapStore(100, 0, 0);
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 2);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Object, Object> map = instance.getMap("testWriteBehindSameSecondSameKey");
    final int size1 = 20;
    final int size2 = 10;
    for (int i = 0; i < size1; i++) {
        map.put("key", "value" + i);
    }
    for (int i = 0; i < size2; i++) {
        map.put("key" + i, "value" + i);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals("value" + (size1 - 1), testMapStore.getStore().get("key"));
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals("value" + (size2 - 1), testMapStore.getStore().get("key" + (size2 - 1)));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with TestMapStore

use of com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore in project hazelcast by hazelcast.

the class MapStoreWriteBehindTest method testDelete_thenPutIfAbsent_withWriteBehindEnabled.

@Test(timeout = 120000)
public void testDelete_thenPutIfAbsent_withWriteBehindEnabled() throws Exception {
    TestMapStore testMapStore = new TestMapStore(1, 1, 1);
    Config config = newConfig(testMapStore, 100);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(1);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    IMap<Integer, Integer> map = instance.getMap("default");
    map.put(1, 1);
    map.delete(1);
    final Object putIfAbsent = map.putIfAbsent(1, 2);
    assertNull(putIfAbsent);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with TestMapStore

use of com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore in project hazelcast by hazelcast.

the class MapStoreWriteThroughTest method testOneMemberWriteThroughWithLRU.

@Test(timeout = 120000)
public void testOneMemberWriteThroughWithLRU() throws Exception {
    final int size = 10000;
    TestMapStore testMapStore = new TestMapStore(size * 2, 1, 1);
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 0);
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setSize(size);
    MapConfig mapConfig = config.getMapConfig("default");
    mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
    mapConfig.setMaxSizeConfig(maxSizeConfig);
    mapConfig.setMinEvictionCheckMillis(0);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap("default");
    final CountDownLatch countDownLatch = new CountDownLatch(size);
    map.addEntryListener(new EntryAdapter() {

        @Override
        public void entryEvicted(EntryEvent event) {
            countDownLatch.countDown();
        }
    }, false);
    for (int i = 0; i < size * 2; i++) {
        // trigger eviction.
        if (i == (size * 2) - 1 || i == size) {
            sleepMillis(1001);
        }
        map.put(i, new Employee("joe", i, true, 100.00));
    }
    assertEquals(testMapStore.getStore().size(), size * 2);
    assertOpenEventually(countDownLatch);
    final String msgFailure = String.format("map size: %d put count: %d", map.size(), size);
    assertTrue(msgFailure, map.size() > size / 2);
    assertTrue(msgFailure, map.size() <= size);
    assertEquals(testMapStore.getStore().size(), size * 2);
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) EntryAdapter(com.hazelcast.core.EntryAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) EntryEvent(com.hazelcast.core.EntryEvent) 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)

Aggregations

Config (com.hazelcast.config.Config)10 MapConfig (com.hazelcast.config.MapConfig)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 TestMapStore (com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore)10 ParallelTest (com.hazelcast.test.annotation.ParallelTest)10 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)8 MapStoreConfig (com.hazelcast.config.MapStoreConfig)5 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)5 NightlyTest (com.hazelcast.test.annotation.NightlyTest)5 Employee (com.hazelcast.query.SampleObjects.Employee)3 AssertTask (com.hazelcast.test.AssertTask)2 EntryAdapter (com.hazelcast.core.EntryAdapter)1 EntryEvent (com.hazelcast.core.EntryEvent)1 CountDownLatch (java.util.concurrent.CountDownLatch)1