use of com.hazelcast.query.impl.predicates.SqlPredicate in project hazelcast by hazelcast.
the class IndexConcurrencyTest method testIndexCreationAndQueryDeterministicConcurrency.
@Test
public void testIndexCreationAndQueryDeterministicConcurrency() {
Config config = getConfig();
HazelcastInstance node = createHazelcastInstance(config);
IMap<Integer, Person> map = node.getMap(randomMapName());
// put some data
for (int i = 0; i < 10000; ++i) {
map.put(i, new Person(i));
}
// initialize age field access counter
Person.accessCountDown = new AtomicLong(5000);
// start indexer, it will await for latch in the middle
AtomicReference<Throwable> exception = new AtomicReference<>();
Thread indexer = new Thread(() -> {
try {
map.addIndex(indexType, indexAttribute);
} catch (Throwable t) {
exception.compareAndSet(null, t);
}
});
indexer.start();
// await for query latch
assertOpenEventually(Person.queryLatch);
Person.accessCountDown = null;
// run checking query
assertQuery(map, new SqlPredicate("age >= 5000"), 5000);
assertQuery(map, equal("age", "6000"), 1);
assertQuery(map, greaterThan("age", "6000"), 3999);
assertQuery(map, and(greaterThan("age", 6000), lessThan("age", 7000)), 999);
assertQuery(map, or(equal("age", 6000), equal("age", 7000)), 2);
assertQuery(map, greaterEqual("age", 5000), 5000);
assertQuery(map, lessThan("age", 9000), 9000);
assertQuery(map, lessEqual("age", 9000), 9001);
assertQuery(map, between("age", 9000, 10000), 1000);
assertQuery(map, in("age", 5000, 6000, 7000, 11111), 3);
assertQuery(map, equal("age", "6000"), 1);
assertQuery(map, like("name", "9999"), 1);
// open indexer latch
Person.indexerLatch.countDown();
// wait for indexer to finish
assertJoinable(indexer);
// assert no unexpected exceptions
assertNull(exception.get());
}
use of com.hazelcast.query.impl.predicates.SqlPredicate in project hazelcast by hazelcast.
the class IndexesTest method testIndex.
@Test
public void testIndex() {
Indexes indexes = Indexes.newBuilder(serializationService, copyBehavior, DEFAULT_IN_MEMORY_FORMAT).build();
indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "name"));
indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.SORTED, "age"));
indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.SORTED, "salary"));
for (int i = 0; i < 2000; i++) {
Employee employee = new Employee(i + "Name", i % 80, (i % 2 == 0), 100 + (i % 100));
indexes.putEntry(new QueryEntry(serializationService, toData(i), employee, newExtractor()), null, Index.OperationSource.USER);
}
for (int i = 0; i < 10; i++) {
SqlPredicate predicate = new SqlPredicate("salary=161 and age >20 and age <23");
assertEquals(5, size(indexes.query(predicate, SKIP_PARTITIONS_COUNT_CHECK)));
}
}
use of com.hazelcast.query.impl.predicates.SqlPredicate in project hazelcast by hazelcast.
the class IndexesTest method shouldNotThrowException_withNullValue_whenIndexAddedForKeyField.
@Test
public void shouldNotThrowException_withNullValue_whenIndexAddedForKeyField() {
Indexes indexes = Indexes.newBuilder(serializationService, copyBehavior, DEFAULT_IN_MEMORY_FORMAT).build();
indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "__key"));
for (int i = 0; i < 100; i++) {
// passing null value to QueryEntry
indexes.putEntry(new QueryEntry(serializationService, toData(i), null, newExtractor()), null, Index.OperationSource.USER);
}
assertEquals(89, size(indexes.query(new SqlPredicate("__key > 10 "), SKIP_PARTITIONS_COUNT_CHECK)));
}
use of com.hazelcast.query.impl.predicates.SqlPredicate in project hazelcast by hazelcast.
the class IndexesTest method testIndex2.
@Test
public void testIndex2() {
Indexes indexes = Indexes.newBuilder(serializationService, copyBehavior, DEFAULT_IN_MEMORY_FORMAT).build();
indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "name"));
indexes.putEntry(new QueryEntry(serializationService, toData(1), new Value("abc"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(2), new Value("xyz"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(3), new Value("aaa"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(4), new Value("zzz"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(5), new Value("klm"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(6), new Value("prs"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(7), new Value("prs"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(8), new Value("def"), newExtractor()), null, Index.OperationSource.USER);
indexes.putEntry(new QueryEntry(serializationService, toData(9), new Value("qwx"), newExtractor()), null, Index.OperationSource.USER);
assertEquals(8, size(indexes.query(new SqlPredicate("name > 'aac'"), SKIP_PARTITIONS_COUNT_CHECK)));
}
use of com.hazelcast.query.impl.predicates.SqlPredicate in project hazelcast by hazelcast.
the class AbstractIndexConcurrencyTest method testIndexCreationAndQueryConcurrency.
@Test
public void testIndexCreationAndQueryConcurrency() throws InterruptedException {
Config config = getConfig();
HazelcastInstance node = createHazelcastInstance(config);
final IMap<Integer, Person> map = node.getMap(randomMapName());
// put some data
for (int i = 0; i < 10000; ++i) {
map.put(i, new Person(i));
}
AtomicReference<Throwable> exception = new AtomicReference<>();
// run index creation and queries concurrently
Thread[] threads = new Thread[QUERY_THREADS_NUM + 1];
threads[0] = new Thread(() -> {
try {
map.addIndex(indexType, indexAttribute);
} catch (Throwable t) {
exception.compareAndSet(null, t);
}
});
threads[0].start();
for (int i = 1; i < threads.length; i++) {
threads[i] = new Thread(() -> {
try {
Collection<Person> persons = map.values(new SqlPredicate("age >= 5000"));
assertEquals(5000, persons.size());
} catch (Throwable t) {
exception.compareAndSet(null, t);
}
});
threads[i].start();
}
// wait for for all threads to finish
for (int i = 0; i < threads.length; ++i) {
threads[i].join();
}
// assert no unexpected exceptions
assertNull(exception.get());
}
Aggregations