use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class AttributeCanonicalizationTest method testIndexes.
@Test
public void testIndexes() {
Indexes indexes = Indexes.newBuilder(new DefaultSerializationServiceBuilder().build(), IndexCopyBehavior.NEVER, DEFAULT_IN_MEMORY_FORMAT).build();
checkIndex(indexes, "foo", "foo");
checkIndex(indexes, "this.foo", "foo");
checkIndex(indexes, "this", "this");
checkIndex(indexes, "foo.this.bar", "foo.this.bar");
checkIndex(indexes, "this.foo.bar", "foo.bar");
checkIndex(indexes, "foo.bar", "foo.bar");
checkIndex(indexes, "__key", "__key");
checkIndex(indexes, "__key.foo", "__key.foo");
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class AbstractVisitorTest method testAllVisitMethodReturnTheOriginalPredicate.
@Test
public void testAllVisitMethodReturnTheOriginalPredicate() throws Exception {
// Contract of AbstractVisitor mandates to return original predicate
// for all methods on Visitor interface.
// This test makes sure if a new method is added into Visitor interface
// then it's added to AbstractVisitor and honour its contract
AbstractVisitor visitor = new AbstractVisitor() {
};
Method[] methods = Visitor.class.getMethods();
for (Method method : methods) {
Class<?> predicateType = method.getParameterTypes()[0];
Predicate predicate = (Predicate) predicateType.newInstance();
Indexes indexes = mock(Indexes.class);
Object result = method.invoke(visitor, predicate, indexes);
assertSame("Method " + method + " does not return identity of the original predicate." + " See contract of " + AbstractVisitor.class.getSimpleName(), predicate, result);
}
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class AttributeCanonicalizationTest method testCompositeIndexes.
@Test
public void testCompositeIndexes() {
Indexes indexes = Indexes.newBuilder(new DefaultSerializationServiceBuilder().build(), IndexCopyBehavior.NEVER, DEFAULT_IN_MEMORY_FORMAT).build();
checkIndex(indexes, new String[] { "foo", "bar" }, new String[] { "foo", "bar" });
checkIndex(indexes, new String[] { "this.foo", "bar" }, new String[] { "foo", "bar" });
checkIndex(indexes, new String[] { "this", "__key" }, new String[] { "this", "__key" });
checkIndex(indexes, new String[] { "foo", "bar.this.baz" }, new String[] { "foo", "bar.this.baz" });
checkIndex(indexes, new String[] { "this.foo", "bar.this.baz" }, new String[] { "foo", "bar.this.baz" });
checkIndex(indexes, new String[] { "foo.bar", "baz" }, new String[] { "foo.bar", "baz" });
checkIndex(indexes, new String[] { "foo", "this.bar", "__key.baz" }, new String[] { "foo", "bar", "__key.baz" });
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class IndexCreateTest method checkIndex.
private void checkIndex(IndexConfig... indexConfigs) {
List<HazelcastInstanceProxy> members = handler.initialize(hazelcastFactory, indexConfigs);
for (HazelcastInstanceProxy member : members) {
MapService service = member.getOriginal().node.nodeEngine.getService(MapService.SERVICE_NAME);
MapServiceContext mapServiceContext = service.getMapServiceContext();
MapContainer mapContainer = mapServiceContext.getMapContainer(MAP_NAME);
Indexes indexes = mapContainer.getIndexes();
assertEquals(indexConfigs.length, indexes.getIndexes().length);
for (IndexConfig indexConfig : indexConfigs) {
String expectedName = getExpectedName(indexConfig);
InternalIndex index = indexes.getIndex(expectedName);
assertNotNull("Index not found: " + expectedName, index);
assertEquals(type == IndexType.SORTED, index.isOrdered());
assertEquals(type, index.getConfig().getType());
assertEquals(indexConfig.getAttributes().size(), index.getComponents().length);
for (int i = 0; i < indexConfig.getAttributes().size(); i++) {
String expAttributeName = indexConfig.getAttributes().get(i);
String componentName = index.getComponents()[i];
assertEquals(IndexUtils.canonicalizeAttribute(expAttributeName), componentName);
}
}
}
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class SingleValueBitmapIndexTest method testClearedIndexes.
@Test
public void testClearedIndexes() {
for (int i = BATCH_COUNT - 1; i >= 0; --i) {
for (long j = 0; j < BATCH_SIZE; ++j) {
long id = i * BATCH_SIZE + j;
put(id, (int) id);
}
verifyQueries();
}
for (HazelcastInstance instance : factory.getAllHazelcastInstances()) {
HazelcastInstanceImpl instanceImpl = (HazelcastInstanceImpl) instance;
MapService mapService = instanceImpl.node.getNodeEngine().getService(MapService.SERVICE_NAME);
Indexes indexes = mapService.getMapServiceContext().getMapContainer(persons.getName()).getIndexes();
indexes.clearAll();
for (Partition partition : instanceImpl.getPartitionService().getPartitions()) {
if (partition.getOwner().localMember()) {
Indexes.beginPartitionUpdate(indexes.getIndexes());
Indexes.markPartitionAsIndexed(partition.getPartitionId(), indexes.getIndexes());
}
}
}
for (ExpectedQuery expectedQuery : expectedQueries) {
expectedQuery.clear();
}
// Repopulate the index and run queries. Technically, we are doing index
// updates here instead of inserts since the map is still populated, but
// the index interprets them as inserts.
persons.getLocalMapStats().getIndexStats();
for (int i = BATCH_COUNT - 1; i >= 0; --i) {
for (long j = 0; j < BATCH_SIZE; ++j) {
long id = i * BATCH_SIZE + j;
put(id, (int) id);
}
verifyQueries();
}
LocalIndexStats statsA = personsA.getLocalMapStats().getIndexStats().values().iterator().next();
LocalIndexStats statsB = personsB.getLocalMapStats().getIndexStats().values().iterator().next();
assertEquals(BATCH_COUNT * BATCH_SIZE, statsA.getInsertCount() + statsB.getInsertCount());
assertEquals(BATCH_COUNT * BATCH_SIZE, statsA.getUpdateCount() + statsB.getUpdateCount());
}
Aggregations