Search in sources :

Example 11 with Value

use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.

the class QueryIndexTest method testInnerIndex.

@Test(timeout = 1000 * 60)
public void testInnerIndex() {
    HazelcastInstance instance = createTestHazelcastInstance();
    IMap<String, SampleTestObjects.Value> map = instance.getMap("default");
    map.addIndex(IndexType.HASH, "name");
    map.addIndex(IndexType.HASH, "type.typeName");
    for (int i = 0; i < 10; i++) {
        Value v = new Value("name" + i, i < 5 ? null : new ValueType("type" + i), i);
        map.put("" + i, v);
    }
    Predicate predicate = Predicates.newPredicateBuilder().getEntryObject().get("type.typeName").in("type8", "type6");
    Collection<SampleTestObjects.Value> values = map.values(predicate);
    assertEquals(2, values.size());
    List<String> typeNames = new ArrayList<>();
    for (Value configObject : values) {
        typeNames.add(configObject.getType().getTypeName());
    }
    String[] array = typeNames.toArray(new String[0]);
    Arrays.sort(array);
    assertArrayEquals(typeNames.toString(), new String[] { "type6", "type8" }, array);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) Value(com.hazelcast.query.SampleTestObjects.Value) ArrayList(java.util.ArrayList) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with Value

use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.

the class QueryIndexTest method testInnerIndexSql.

@Test(timeout = 1000 * 60)
public void testInnerIndexSql() {
    HazelcastInstance instance = createTestHazelcastInstance();
    IMap<String, SampleTestObjects.Value> map = instance.getMap("default");
    map.addIndex(IndexType.HASH, "name");
    map.addIndex(IndexType.HASH, "type.typeName");
    for (int i = 0; i < 4; i++) {
        Value v = new Value("name" + i, new ValueType("type" + i), i);
        map.put("" + i, v);
    }
    Predicate predicate = Predicates.sql("type.typeName='type1'");
    Collection<SampleTestObjects.Value> values = map.values(predicate);
    assertEquals(1, values.size());
    List<String> typeNames = new ArrayList<>();
    for (Value configObject : values) {
        typeNames.add(configObject.getType().getTypeName());
    }
    assertArrayEquals(typeNames.toString(), new String[] { "type1" }, typeNames.toArray(new String[0]));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) Value(com.hazelcast.query.SampleTestObjects.Value) ArrayList(java.util.ArrayList) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with Value

use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.

the class PredicatesTest method testAndPredicate_whenFirstIndexAwarePredicateIsNotIndexed.

@Test
@Ignore("now will execute partition number of times")
public void testAndPredicate_whenFirstIndexAwarePredicateIsNotIndexed() {
    final HazelcastInstance instance = createHazelcastInstance();
    final IMap<Object, Object> map = instance.getMap("map");
    map.addIndex(IndexType.HASH, "name");
    String name = randomString();
    map.put("key", new Value(name));
    final ShouldExecuteOncePredicate<?, ?> indexAwareNotIndexedPredicate = new ShouldExecuteOncePredicate<>();
    final EqualPredicate equalPredicate = new EqualPredicate("name", name);
    final AndPredicate andPredicate = new AndPredicate(indexAwareNotIndexedPredicate, equalPredicate);
    map.values(andPredicate);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Value(com.hazelcast.query.SampleTestObjects.Value) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Ignore(org.junit.Ignore) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with Value

use of com.hazelcast.query.SampleTestObjects.Value 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 15 with Value

use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.

the class QueryBasicTest method testPredicateStringAttributesWithIndex.

/**
 * Github issues 98 and 131
 */
@Test(timeout = 1000 * 90)
public void testPredicateStringAttributesWithIndex() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap("testPredicateStringWithStringIndex");
    map.addIndex(IndexType.HASH, "name");
    testPredicateStringAttribute(map);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Value(com.hazelcast.query.SampleTestObjects.Value) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Value (com.hazelcast.query.SampleTestObjects.Value)25 Test (org.junit.Test)21 HazelcastInstance (com.hazelcast.core.HazelcastInstance)20 QuickTest (com.hazelcast.test.annotation.QuickTest)20 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 Predicate (com.hazelcast.query.Predicate)12 ArrayList (java.util.ArrayList)7 ValueType (com.hazelcast.query.SampleTestObjects.ValueType)6 Config (com.hazelcast.config.Config)2 IndexConfig (com.hazelcast.config.IndexConfig)2 MapConfig (com.hazelcast.config.MapConfig)1 EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)1 SqlPredicate (com.hazelcast.query.impl.predicates.SqlPredicate)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1 Future (java.util.concurrent.Future)1 Ignore (org.junit.Ignore)1