use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class QueryIndexMigrationTest method testQueryDuringAndAfterMigrationWithIndex.
@Test
public void testQueryDuringAndAfterMigrationWithIndex() throws Exception {
Config config = new Config();
HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
IMap<String, Employee> map = instance.getMap("employees");
map.addIndex("name", false);
map.addIndex("active", false);
int size = 500;
for (int i = 0; i < size; i++) {
map.put(String.valueOf(i), new Employee("joe" + i, i % 60, ((i & 1) == 1), (double) i));
}
nodeFactory.newInstances(config, 3);
final IMap<String, Employee> employees = instance.getMap("employees");
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
Collection<Employee> values = employees.values(new SqlPredicate("active and name LIKE 'joe15%'"));
for (Employee employee : values) {
assertTrue(employee.isActive() && employee.getName().startsWith("joe15"));
}
assertEquals(6, values.size());
}
}, 3);
}
use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class QueryIndexMigrationTest method testQueryWithIndexesWhileMigrating.
@Test
public void testQueryWithIndexesWhileMigrating() throws Exception {
HazelcastInstance instance = nodeFactory.newHazelcastInstance();
IMap<String, Employee> map = instance.getMap("employees");
map.addIndex("age", true);
map.addIndex("active", false);
for (int i = 0; i < 500; i++) {
map.put("e" + i, new Employee("name" + i, i % 50, ((i & 1) == 1), (double) i));
}
assertEquals(500, map.size());
Set<Map.Entry<String, Employee>> entries = map.entrySet(new SqlPredicate("active=true and age>44"));
assertEquals(30, entries.size());
nodeFactory.newInstances(new Config(), 3);
long startNow = Clock.currentTimeMillis();
while ((Clock.currentTimeMillis() - startNow) < 10000) {
entries = map.entrySet(new SqlPredicate("active=true and age>44"));
assertEquals(30, entries.size());
}
}
use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class QueryIndexingTest method assertFieldsAreNull.
private static void assertFieldsAreNull(Collection<Employee> matchingEmployees) {
for (Employee employee : matchingEmployees) {
assertNull("city", employee.getCity());
assertNull("name", employee.getName());
}
}
use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class QueryNullIndexingTest method queryIndexedDateFieldAsNullValue.
private List<Long> queryIndexedDateFieldAsNullValue(boolean ordered, Predicate pred) {
HazelcastInstance instance = createHazelcastInstance();
IMap<Integer, SampleObjects.Employee> map = instance.getMap("default");
map.addIndex("date", ordered);
for (int i = 10; i >= 1; i--) {
Employee employee = new Employee(i, "name-" + i, i, true, i * 100);
if (i % 2 == 0) {
employee.setDate(new Timestamp(i * 1000000));
} else {
employee.setDate(null);
}
map.put(i, employee);
}
List<Long> dates = new ArrayList<Long>();
for (SampleObjects.Employee employee : map.values(pred)) {
Timestamp date = employee.getDate();
dates.add(date == null ? null : date.getTime());
}
return dates;
}
use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class QueryBasicTest method negativeDouble.
@Test(timeout = 1000 * 60)
public void negativeDouble() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Employee> map = instance.getMap("default");
map.addIndex("salary", false);
map.put("" + 4, new Employee(1, "default", 1, true, -70D));
map.put("" + 3, new Employee(1, "default", 1, true, -60D));
map.put("" + 1, new Employee(1, "default", 1, true, -10D));
map.put("" + 2, new Employee(2, "default", 2, true, 10D));
Predicate predicate = new SqlPredicate("salary >= -60");
Collection<Employee> values = map.values(predicate);
assertEquals(3, values.size());
predicate = new SqlPredicate("salary between -20 and 20");
values = map.values(predicate);
assertEquals(2, values.size());
}
Aggregations