@Test(timeout = 1000 * 60)
public void testTwoNodesWithPartialIndexes() throws Exception {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
IMap imap = h1.getMap("employees");
imap.addIndex("name", false);
imap.addIndex("age", true);
imap.addIndex("active", false);
for (int i = 0; i < 500; i++) {
Employee employee = new Employee(i, "name" + i % 100, "city" + (i % 100), i % 60, ((i & 1) == 1), (double) i);
imap.put(String.valueOf(i), employee);
}
assertEquals(2, h1.getCluster().getMembers().size());
assertEquals(2, h2.getCluster().getMembers().size());
imap = h2.getMap("employees");
imap.addIndex("name", false);
imap.addIndex("age", true);
imap.addIndex("active", false);
Collection<Employee> entries = imap.values(new SqlPredicate("name='name3' and city='city3' and age > 2"));
assertEquals(5, entries.size());
for (Employee e : entries) {
assertEquals("name3", e.getName());
assertEquals("city3", e.getCity());
}
entries = imap.values(new SqlPredicate("name LIKE '%name3' and city like '%city3' and age > 2"));
assertEquals(5, entries.size());
for (Employee e : entries) {
assertEquals("name3", e.getName());
assertEquals("city3", e.getCity());
assertTrue(e.getAge() > 2);
}
entries = imap.values(new SqlPredicate("name LIKE '%name3%' and city like '%city30%'"));
assertEquals(5, entries.size());
for (Employee e : entries) {
assertTrue(e.getName().startsWith("name3"));
assertTrue(e.getCity().startsWith("city3"));
}