IMap imap1 = h1.getMap("employees");
IMap imap2 = h2.getMap("employees");
for (int i = 0; i < 5000; i++) {
boolean test = i % 2 == 0;
imap1.put(String.valueOf(i), new Employee(test ? null : "name" + i,
test ? null : "city" + i, i % 60, true, (double) i));
}
long start = Clock.currentTimeMillis();
Set<Map.Entry> entries = imap2.entrySet(predicate);
long tookWithout = (Clock.currentTimeMillis() - start);
assertEquals(2500, entries.size());
for (Map.Entry entry : entries) {
Employee c = (Employee) entry.getValue();
assertNull(c.getName());
assertNull(c.getCity());
}
imap1.destroy();
imap1 = h1.getMap("employees2");
imap2 = h2.getMap("employees2");
imap1.addIndex("name", false);
imap1.addIndex("city", true);
imap1.addIndex("age", true);
imap1.addIndex("active", false);
for (int i = 0; i < 5000; i++) {
boolean test = i % 2 == 0;
imap1.put(String.valueOf(i), new Employee(test ? null : "name" + i,
test ? null : "city" + i, i % 60, true, (double) i));
}
start = Clock.currentTimeMillis();
entries = imap2.entrySet(predicate);
long tookWithIndex = (Clock.currentTimeMillis() - start);
assertEquals(2500, entries.size());
for (Map.Entry entry : entries) {
Employee c = (Employee) entry.getValue();
assertNull(c.getName());
assertNull(c.getCity());
}
assertTrue("WithIndex: " + tookWithIndex + ", without: " + tookWithout, tookWithIndex < tookWithout);
}