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());
}
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"));
}
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)));
}
});
}
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);
}
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);
}
Aggregations