Search in sources :

Example 6 with ValueType

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

the class QueryBasicTest method testIndexingEnumAttributeWithSqlIssue597.

/**
     * see pull request 616
     */
@Test(timeout = 1000 * 60)
public void testIndexingEnumAttributeWithSqlIssue597() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap("default");
    map.addIndex("state", true);
    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);
    }
    Collection<Value> values = map.values(new SqlPredicate("state = 'STATE1'"));
    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.SampleObjects.ValueType) Value(com.hazelcast.query.SampleObjects.Value) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with ValueType

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

the class QueryBasicTest method testIndexingEnumAttributeIssue597.

@Test(timeout = 1000 * 60)
public void testIndexingEnumAttributeIssue597() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap("default");
    map.addIndex("state", true);
    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 = new PredicateBuilder().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.SampleObjects.ValueType) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Value(com.hazelcast.query.SampleObjects.Value) Predicate(com.hazelcast.query.Predicate) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with ValueType

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

the class QueryBasicTest method testIteratorContract.

@Test(timeout = 1000 * 60)
public void testIteratorContract() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, SampleObjects.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 = new SqlPredicate("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.SampleObjects.ValueType) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with ValueType

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

the class QueryBasicTest method testInPredicate.

@Test(timeout = 1000 * 60)
public void testInPredicate() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, SampleObjects.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 = new SqlPredicate("typeName in ('one','two')");
    for (int i = 0; i < 10; i++) {
        Collection<SampleObjects.ValueType> values = map.values(predicate);
        assertEquals(2, values.size());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleObjects.ValueType) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 ValueType (com.hazelcast.query.SampleObjects.ValueType)9 SqlPredicate (com.hazelcast.query.SqlPredicate)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 Predicate (com.hazelcast.query.Predicate)7 Value (com.hazelcast.query.SampleObjects.Value)6 PredicateBuilder (com.hazelcast.query.PredicateBuilder)3 ArrayList (java.util.ArrayList)3 Config (com.hazelcast.config.Config)2 MapIndexConfig (com.hazelcast.config.MapIndexConfig)2 MapConfig (com.hazelcast.config.MapConfig)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 AssertTask (com.hazelcast.test.AssertTask)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 Collection (java.util.Collection)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1