Search in sources :

Example 6 with ValueType

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

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

the class QueryBasicTest method testIteratorContract.

@Test(timeout = 1000 * 90)
public void testIteratorContract() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, SampleTestObjects.ValueType> map = instance.getMap("testIteratorContract");
    map.put("1", new ValueType("one"));
    map.put("2", new ValueType("two"));
    map.put("3", new ValueType("three"));
    Predicate predicate = Predicates.sql("typeName in ('one','two')");
    assertEquals(2, map.values(predicate).size());
    assertEquals(2, map.keySet(predicate).size());
    testIterator(map.keySet().iterator(), 3);
    testIterator(map.keySet(predicate).iterator(), 2);
    testIterator(map.entrySet().iterator(), 3);
    testIterator(map.entrySet(predicate).iterator(), 2);
    testIterator(map.values().iterator(), 3);
    testIterator(map.values(predicate).iterator(), 2);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with ValueType

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

the class QueryBasicTest method testInPredicate.

@Test(timeout = 1000 * 90)
public void testInPredicate() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, SampleTestObjects.ValueType> map = instance.getMap("testIteratorContract");
    map.put("1", new ValueType("one"));
    map.put("2", new ValueType("two"));
    map.put("3", new ValueType("three"));
    map.put("4", new ValueType("four"));
    map.put("5", new ValueType("five"));
    map.put("6", new ValueType("six"));
    map.put("7", new ValueType("seven"));
    Predicate predicate = Predicates.sql("typeName in ('one','two')");
    for (int i = 0; i < 10; i++) {
        Collection<SampleTestObjects.ValueType> values = map.values(predicate);
        assertEquals(2, values.size());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with ValueType

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

the class QueryBasicTest method testIndexingEnumAttributeIssue597.

@Test(timeout = 1000 * 90)
public void testIndexingEnumAttributeIssue597() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap("default");
    map.addIndex(IndexType.SORTED, "state");
    for (int i = 0; i < 4; i++) {
        Value v = new Value(i % 2 == 0 ? State.STATE1 : State.STATE2, new ValueType(), i);
        map.put(i, v);
    }
    Predicate predicate = Predicates.newPredicateBuilder().getEntryObject().get("state").equal(State.STATE1);
    Collection<Value> values = map.values(predicate);
    int[] expectedValues = new int[] { 0, 2 };
    assertEquals(expectedValues.length, values.size());
    int[] indexes = new int[2];
    int index = 0;
    for (Value configObject : values) {
        indexes[index++] = configObject.getIndex();
    }
    Arrays.sort(indexes);
    assertArrayEquals(indexes, expectedValues);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) Value(com.hazelcast.query.SampleTestObjects.Value) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 ValueType (com.hazelcast.query.SampleTestObjects.ValueType)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 Predicate (com.hazelcast.query.Predicate)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 Value (com.hazelcast.query.SampleTestObjects.Value)6 ArrayList (java.util.ArrayList)3 Config (com.hazelcast.config.Config)2 IndexConfig (com.hazelcast.config.IndexConfig)2 MapConfig (com.hazelcast.config.MapConfig)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 Collection (java.util.Collection)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1