use of com.hazelcast.query.SampleTestObjects.Employee 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(IndexType.HASH, "name");
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.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class MapStoreWriteThroughTest method testOneMemberWriteThroughWithLRU.
@Test(timeout = 120000)
public void testOneMemberWriteThroughWithLRU() {
final int size = 10000;
TestMapStore testMapStore = new TestMapStore(size * 2, 1, 1);
testMapStore.setLoadAllKeys(false);
Config config = newConfig(testMapStore, 0);
config.setProperty(ClusterProperty.PARTITION_COUNT.getName(), "1");
MapConfig mapConfig = config.getMapConfig("default");
EvictionConfig evictionConfig = mapConfig.getEvictionConfig();
evictionConfig.setEvictionPolicy(EvictionPolicy.LRU);
evictionConfig.setSize(size);
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);
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testOneMemberWithIndex.
@Test
public void testOneMemberWithIndex() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Employee> map = instance.getMap("employees");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.SORTED, "age");
map.addIndex(IndexType.HASH, "active");
QueryBasicTest.doFunctionalQueryTest(map);
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testSecondMemberAfterAddingIndexes.
@Test
public void testSecondMemberAfterAddingIndexes() {
Config config = getConfig();
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
IMap<String, Employee> map = instance.getMap("employees");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.SORTED, "age");
map.addIndex(IndexType.HASH, "active");
nodeFactory.newHazelcastInstance(config);
QueryBasicTest.doFunctionalQueryTest(map);
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryBasicTest method doFunctionalQueryTest.
public static void doFunctionalQueryTest(IMap<String, Employee> map) {
map.put("1", new Employee("joe", 33, false, 14.56));
map.put("2", new Employee("ali", 23, true, 15.00));
for (int i = 3; i < 103; i++) {
map.put(String.valueOf(i), new Employee("name" + i, i % 60, ((i & 1) == 1), i));
}
Set<Map.Entry<String, Employee>> entries = map.entrySet();
assertEquals(102, entries.size());
int entryCount = 0;
for (Map.Entry entry : entries) {
Employee employee = (Employee) entry.getValue();
assertNotNull(employee);
entryCount++;
}
assertEquals(102, entryCount);
EntryObject entryObject = Predicates.newPredicateBuilder().getEntryObject();
Predicate predicate = entryObject.is("active").and(entryObject.get("age").equal(23));
entries = map.entrySet(predicate);
for (Map.Entry entry : entries) {
Employee employee = (Employee) entry.getValue();
assertEquals(employee.getAge(), 23);
assertTrue(employee.isActive());
}
map.remove("2");
entries = map.entrySet(predicate);
assertEquals(2, entries.size());
for (Map.Entry entry : entries) {
Employee employee = (Employee) entry.getValue();
assertEquals(employee.getAge(), 23);
assertTrue(employee.isActive());
}
entries = map.entrySet(Predicates.sql(" (age >= " + 30 + ") AND (age <= " + 40 + ")"));
assertEquals(23, entries.size());
for (Map.Entry entry : entries) {
Employee employee = (Employee) entry.getValue();
assertTrue(employee.getAge() >= 30);
assertTrue(employee.getAge() <= 40);
}
}
Aggregations