@Test(timeout = 120000) public void testOneMemberWriteThrough() throws Exception { TestMapStore testMapStore = new TestMapStore(1, 1, 1); testMapStore.setLoadAllKeys(false); Config config = newConfig(testMapStore, 0); HazelcastInstance h1 = createHazelcastInstance(config); Employee employee = new Employee("joe", 25, true, 100.00); Employee newEmployee = new Employee("ali", 26, true, 1000); testMapStore.insert("1", employee); testMapStore.insert("2", employee); testMapStore.insert("3", employee); testMapStore.insert("4", employee); testMapStore.insert("5", employee); testMapStore.insert("6", employee); testMapStore.insert("7", employee); IMap map = h1.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()); assertEquals(employee, map.put("2", newEmployee)); assertEquals(newEmployee, testMapStore.getStore().get("2")); assertEquals(2, map.size()); map.remove("1"); map.put("1", employee, 1, TimeUnit.SECONDS); map.put("1", employee); Thread.sleep(2000); assertEquals(employee, testMapStore.getStore().get("1")); assertEquals(employee, map.get("1")); map.evict("2"); assertEquals(newEmployee, map.get("2")); assertEquals(employee, map.get("3")); assertEquals(employee, map.put("3", newEmployee)); assertEquals(newEmployee, map.get("3")); assertEquals(employee, map.remove("4")); assertEquals(employee, map.get("5")); assertEquals(employee, map.remove("5")); assertEquals(employee, map.putIfAbsent("6", newEmployee)); assertEquals(employee, map.get("6")); assertEquals(employee, testMapStore.getStore().get("6")); assertTrue(map.containsKey("7")); assertEquals(employee, map.get("7")); assertNull(map.get("8")); assertFalse(map.containsKey("8")); assertNull(map.putIfAbsent("8", employee)); assertEquals(employee, map.get("8")); assertEquals(employee, testMapStore.getStore().get("8")); }
@Test(timeout = 120000) public void testOneMemberWriteThroughWithIndex() throws Exception { TestMapStore testMapStore = new TestMapStore(1, 1, 1); testMapStore.setLoadAllKeys(false); Config config = newConfig(testMapStore, 0); TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3); HazelcastInstance h1 = nodeFactory.newHazelcastInstance(config); testMapStore.insert("1", "value1"); IMap map = h1.getMap("default"); assertEquals(0, map.size()); assertTrue(map.tryLock("1", 1, TimeUnit.SECONDS)); assertEquals("value1", map.get("1")); map.unlock("1"); assertEquals("value1", map.put("1", "value2")); assertEquals("value2", map.get("1")); assertEquals("value2", testMapStore.getStore().get("1")); assertEquals(1, map.size()); assertTrue(map.evict("1")); assertEquals(0, map.size()); assertEquals(1, testMapStore.getStore().size()); assertEquals("value2", map.get("1")); assertEquals(1, map.size()); map.remove("1"); assertEquals(0, map.size()); assertEquals(0, testMapStore.getStore().size()); testMapStore.assertAwait(1); assertEquals(1, testMapStore.getInitCount()); assertEquals("default", testMapStore.getMapName()); assertEquals(TestUtil.getNode(h1), TestUtil.getNode(testMapStore.getHazelcastInstance())); }
@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 h1 = nodeFactory.newHazelcastInstance(config); HazelcastInstance h2 = 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 map = h1.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()); }