use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testTwoMembers.
@Test
public void testTwoMembers() {
Config config = getConfig();
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
nodeFactory.newHazelcastInstance(config);
IMap<String, Employee> map = instance.getMap("employees");
QueryBasicTest.doFunctionalQueryTest(map);
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testTwoMembersWithIndexesAndShutdown3.
@Test
public void testTwoMembersWithIndexesAndShutdown3() {
Config config = getConfig();
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
IMap<String, Employee> map = instance1.getMap("employees");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.SORTED, "age");
map.addIndex(IndexType.HASH, "active");
QueryBasicTest.doFunctionalQueryTest(map);
assertEquals(101, map.size());
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
assertEquals(101, map.size());
instance1.getLifecycleService().shutdown();
map = instance2.getMap("employees");
assertEquals(101, map.size());
Set<Map.Entry<String, Employee>> entries = map.entrySet(Predicates.sql("active and age=23"));
assertEquals(2, entries.size());
for (Map.Entry<String, Employee> entry : entries) {
Employee employee = entry.getValue();
assertEquals(employee.getAge(), 23);
assertTrue(employee.isActive());
}
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testQueryWithTTL.
@Test
public void testQueryWithTTL() {
Config config = getConfig();
// disable background expiration task to keep test safe from jitter
config.setProperty(PROP_CLEANUP_ENABLED, "false");
String mapName = "default";
config.getMapConfig(mapName).setTimeToLiveSeconds(3);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<String, Employee> map = instance.getMap(mapName);
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.SORTED, "age");
map.addIndex(IndexType.HASH, "active");
int passiveEmployees = 5;
int activeEmployees = 5;
int allEmployees = passiveEmployees + activeEmployees;
final CountDownLatch latch = new CountDownLatch(allEmployees);
map.addEntryListener((EntryExpiredListener) event -> latch.countDown(), false);
for (int i = 0; i < activeEmployees; i++) {
Employee employee = new Employee("activeEmployee" + i, 60, true, i);
map.put("activeEmployee" + i, employee);
}
for (int i = 0; i < passiveEmployees; i++) {
Employee employee = new Employee("passiveEmployee" + i, 60, false, i);
map.put("passiveEmployee" + i, employee);
}
// check the query result before eviction
final Collection values = map.values(Predicates.sql("active"));
assertTrueEventually(() -> assertEquals(String.format("Expected %s results but got %s." + " Number of evicted entries: %s.", activeEmployees, values.size(), allEmployees - latch.getCount()), activeEmployees, values.size()));
// delete expire keys by explicitly calling `map#get`
assertTrueEventually(() -> {
for (int i = 0; i < activeEmployees; i++) {
assertNull(map.get("activeEmployee" + i));
}
for (int i = 0; i < passiveEmployees; i++) {
assertNull(map.get("passiveEmployee" + i));
}
});
// wait until eviction is completed
assertOpenEventually(latch);
// check the query result after eviction
assertEquals(0, map.values(Predicates.sql("active")).size());
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class MapTransactionTest method testValues_withPagingPredicate.
@Test(expected = IllegalArgumentException.class)
public void testValues_withPagingPredicate() throws TransactionException {
final int nodeCount = 1;
final String mapName = randomMapName("testValuesWithPagingPredicate");
final Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
final HazelcastInstance node = factory.newHazelcastInstance(config);
final IMap<Integer, Employee> map = node.getMap(mapName);
final Employee emp = new Employee("name", 77, true, 10D);
map.put(1, emp);
node.executeTransaction(options, (context) -> {
final TransactionalMap<Integer, Employee> txMap = context.getMap(mapName);
Predicate<Integer, Employee> predicate = Predicates.pagingPredicate(5);
txMap.values(predicate);
return true;
});
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class MapTransactionTest method testValuesWithPredicate_removingExistentEntry.
@Test
public void testValuesWithPredicate_removingExistentEntry() throws TransactionException {
final int nodeCount = 1;
final String mapName = randomMapName("_testValuesWithPredicate_removingExistentEntry_");
final Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
final HazelcastInstance node = factory.newHazelcastInstance(config);
final IMap map = node.getMap(mapName);
final Employee emp = new Employee("name", 77, true, 10D);
map.put(1, emp);
node.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap(mapName);
txMap.remove(1);
Collection<Object> coll = txMap.values(Predicates.sql("age > 70 "));
assertEquals(0, coll.size());
return true;
}
});
node.shutdown();
}
Aggregations