use of com.hazelcast.query.impl.predicates.EqualPredicate in project hazelcast by hazelcast.
the class QueryRunnerTest method verifyIndexedQueryFailureWhileMigrating.
@Test
public void verifyIndexedQueryFailureWhileMigrating() {
map.addIndex(IndexType.HASH, "this");
Predicate predicate = new EqualPredicate("this", value);
mapService.beforeMigration(new PartitionMigrationEvent(MigrationEndpoint.SOURCE, partitionId, 0, 1, UUID.randomUUID()));
Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(IterationType.ENTRY).partitionIdSet(SetUtil.allPartitionIds(instance.getPartitionService().getPartitions().size())).build();
QueryResult result = (QueryResult) queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query);
assertNull(result.getPartitionIds());
}
use of com.hazelcast.query.impl.predicates.EqualPredicate in project hazelcast by hazelcast.
the class QueryRunnerTest method verifyFullScanFailureWhileMigrating.
@Test
public void verifyFullScanFailureWhileMigrating() {
Predicate predicate = new EqualPredicate("this", value);
mapService.beforeMigration(new PartitionMigrationEvent(MigrationEndpoint.SOURCE, partitionId, 0, 1, UUID.randomUUID()));
Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(IterationType.ENTRY).partitionIdSet(SetUtil.allPartitionIds(instance.getPartitionService().getPartitions().size())).build();
QueryResult result = (QueryResult) queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query);
assertNull(result.getPartitionIds());
}
use of com.hazelcast.query.impl.predicates.EqualPredicate in project hazelcast by hazelcast.
the class IndexTest method testIndex.
@Test
public void testIndex() throws QueryException {
Indexes indexes = Indexes.newBuilder(ss, copyBehavior, DEFAULT_IN_MEMORY_FORMAT).build();
Index dIndex = indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "d"));
Index boolIndex = indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "bool"));
Index strIndex = indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "str"));
for (int i = 0; i < 1000; i++) {
Data key = ss.toData(i);
Data value = ss.toData(new MainPortable(i % 2 == 0, -10.34d, "joe" + i));
indexes.putEntry(new QueryEntry(ss, key, value, newExtractor()), null, Index.OperationSource.USER);
}
assertEquals(1000, dIndex.getRecords(-10.34d).size());
assertEquals(1, strIndex.getRecords("joe23").size());
assertEquals(500, boolIndex.getRecords(true).size());
clearIndexes(dIndex, boolIndex, strIndex);
for (int i = 0; i < 1000; i++) {
Data key = ss.toData(i);
Data value = ss.toData(new MainPortable(false, 11.34d, "joe"));
indexes.putEntry(new QueryEntry(ss, key, value, newExtractor()), null, Index.OperationSource.USER);
}
assertEquals(0, dIndex.getRecords(-10.34d).size());
assertEquals(0, strIndex.getRecords("joe23").size());
assertEquals(1000, strIndex.getRecords("joe").size());
assertEquals(1000, boolIndex.getRecords(false).size());
assertEquals(0, boolIndex.getRecords(true).size());
clearIndexes(dIndex, boolIndex, strIndex);
for (int i = 0; i < 1000; i++) {
Data key = ss.toData(i);
Data value = ss.toData(new MainPortable(false, -1 * (i + 1), "joe" + i));
indexes.putEntry(new QueryEntry(ss, key, value, newExtractor()), null, Index.OperationSource.USER);
}
assertEquals(0, dIndex.getRecords(1d, true, 1001d, true).size());
assertEquals(1000, dIndex.getRecords(-1001d, true, -1d, true).size());
assertEquals(0, dIndex.getRecords(-1d, true, -1001d, true).size());
clearIndexes(dIndex, boolIndex, strIndex);
for (int i = 0; i < 1000; i++) {
Data key = ss.toData(i);
Data value = ss.toData(new MainPortable(false, 1 * (i + 1), "joe" + i));
indexes.putEntry(new QueryEntry(ss, key, value, newExtractor()), null, Index.OperationSource.USER);
}
assertEquals(1000, dIndex.getRecords(1d, true, 1001d, true).size());
assertEquals(0, dIndex.getRecords(-1d, true, -1001d, true).size());
assertEquals(400, dIndex.getRecords(Comparison.GREATER, 600d).size());
assertEquals(401, dIndex.getRecords(Comparison.GREATER_OR_EQUAL, 600d).size());
assertEquals(9, dIndex.getRecords(Comparison.LESS, 10d).size());
assertEquals(10, dIndex.getRecords(Comparison.LESS_OR_EQUAL, 10d).size());
assertEquals(1, size(indexes.query(new AndPredicate(new EqualPredicate("d", 1d), new EqualPredicate("bool", "false")), SKIP_PARTITIONS_COUNT_CHECK)));
assertEquals(1, size(indexes.query(new AndPredicate(new EqualPredicate("d", 1), new EqualPredicate("bool", Boolean.FALSE)), SKIP_PARTITIONS_COUNT_CHECK)));
assertEquals(1, size(indexes.query(new AndPredicate(new EqualPredicate("d", "1"), new EqualPredicate("bool", false)), SKIP_PARTITIONS_COUNT_CHECK)));
}
use of com.hazelcast.query.impl.predicates.EqualPredicate in project hazelcast by hazelcast.
the class QueryRunnerTest method verifyIndexedQueryFailureWhileMigratingInFlight.
@Test
public void verifyIndexedQueryFailureWhileMigratingInFlight() {
map.addIndex(IndexType.HASH, "this");
Predicate predicate = new EqualPredicate("this", value) {
@Override
public Set<QueryableEntry> filter(QueryContext queryContext) {
// start a new migration while executing an indexed query
mapService.beforeMigration(new PartitionMigrationEvent(MigrationEndpoint.SOURCE, partitionId, 0, 1, UUID.randomUUID()));
return super.filter(queryContext);
}
};
Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(IterationType.ENTRY).partitionIdSet(SetUtil.allPartitionIds(instance.getPartitionService().getPartitions().size())).build();
QueryResult result = (QueryResult) queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query);
assertNull(result.getPartitionIds());
}
use of com.hazelcast.query.impl.predicates.EqualPredicate in project hazelcast by hazelcast.
the class QueryRunnerTest method verifyFullScanFailureWhileMigratingInFlight.
@Test
public void verifyFullScanFailureWhileMigratingInFlight() {
Predicate predicate = new EqualPredicate("this", value) {
@Override
protected boolean applyForSingleAttributeValue(Comparable attributeValue) {
// start a new migration while executing a full scan
mapService.beforeMigration(new PartitionMigrationEvent(MigrationEndpoint.SOURCE, partitionId, 0, 1, UUID.randomUUID()));
return super.applyForSingleAttributeValue(attributeValue);
}
};
Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(IterationType.ENTRY).partitionIdSet(SetUtil.allPartitionIds(instance.getPartitionService().getPartitions().size())).build();
QueryResult result = (QueryResult) queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query);
assertNull(result.getPartitionIds());
}
Aggregations