Search in sources :

Example 1 with SqlPredicate

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());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) SqlPredicate(com.hazelcast.query.impl.predicates.SqlPredicate) AtomicReference(java.util.concurrent.atomic.AtomicReference) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with SqlPredicate

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)));
    }
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee) SqlPredicate(com.hazelcast.query.impl.predicates.SqlPredicate) IndexMatchHint(com.hazelcast.query.impl.QueryContext.IndexMatchHint) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with SqlPredicate

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)));
}
Also used : SqlPredicate(com.hazelcast.query.impl.predicates.SqlPredicate) IndexMatchHint(com.hazelcast.query.impl.QueryContext.IndexMatchHint) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with SqlPredicate

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)));
}
Also used : Value(com.hazelcast.query.SampleTestObjects.Value) SqlPredicate(com.hazelcast.query.impl.predicates.SqlPredicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with SqlPredicate

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());
}
Also used : Config(com.hazelcast.config.Config) SqlPredicate(com.hazelcast.query.impl.predicates.SqlPredicate) AtomicReference(java.util.concurrent.atomic.AtomicReference) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

SqlPredicate (com.hazelcast.query.impl.predicates.SqlPredicate)7 Test (org.junit.Test)6 QuickTest (com.hazelcast.test.annotation.QuickTest)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 Config (com.hazelcast.config.Config)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 IndexMatchHint (com.hazelcast.query.impl.QueryContext.IndexMatchHint)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)1 Data (com.hazelcast.internal.serialization.Data)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1 IMap (com.hazelcast.map.IMap)1 Employee (com.hazelcast.query.SampleTestObjects.Employee)1 Value (com.hazelcast.query.SampleTestObjects.Value)1 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)1 AndPredicate (com.hazelcast.query.impl.predicates.AndPredicate)1 EqualPredicate (com.hazelcast.query.impl.predicates.EqualPredicate)1 Collection (java.util.Collection)1 Map (java.util.Map)1