Search in sources :

Example 6 with Value

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

the class QueryBasicTest method testLesserEqual.

@Test
public void testLesserEqual() {
    final HazelcastInstance instance = createHazelcastInstance(getConfig());
    final IMap<String, Value> map = instance.getMap("default");
    map.addIndex(IndexType.SORTED, "index");
    for (int i = 0; i < 10; i++) {
        map.put("" + i, new Value("" + i, i));
    }
    final Predicate predicate = Predicates.sql("index<=5");
    final Collection<Value> values = map.values(predicate);
    final int[] expectedIndexValues = new int[6];
    for (int i = 0; i < expectedIndexValues.length; i++) {
        expectedIndexValues[i] = i;
    }
    assertEquals(expectedIndexValues.length, values.size());
    final int[] actualIndexValues = new int[values.size()];
    int i = 0;
    for (Value value : values) {
        actualIndexValues[i++] = value.getIndex();
    }
    Arrays.sort(actualIndexValues);
    assertArrayEquals(expectedIndexValues, actualIndexValues);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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)

Example 7 with Value

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

the class QueryBasicTest method issue393SqlInInteger.

@Test(timeout = 1000 * 90)
public void issue393SqlInInteger() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Value> map = instance.getMap("default");
    map.addIndex(IndexType.HASH, "index");
    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("index IN (0, 2)");
    Collection<Value> values = map.values(predicate);
    String[] expectedValues = new String[] { "name0", "name2" };
    assertEquals(expectedValues.length, values.size());
    List<String> names = new ArrayList<>();
    for (Value configObject : values) {
        names.add(configObject.getName());
    }
    String[] array = names.toArray(new String[0]);
    Arrays.sort(array);
    assertArrayEquals(names.toString(), expectedValues, 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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with Value

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

the class QueryBasicTest method issue393SqlEq.

@Test(timeout = 1000 * 90)
public void issue393SqlEq() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Value> map = instance.getMap("default");
    map.addIndex(IndexType.SORTED, "name");
    for (int i = 0; i < 4; i++) {
        Value v = new Value("name" + i);
        map.put("" + i, v);
    }
    Predicate predicate = Predicates.sql("name='name0'");
    Collection<Value> values = map.values(predicate);
    String[] expectedValues = new String[] { "name0" };
    assertEquals(expectedValues.length, values.size());
    List<String> names = new ArrayList<>();
    for (Value configObject : values) {
        names.add(configObject.getName());
    }
    String[] array = names.toArray(new String[0]);
    Arrays.sort(array);
    assertArrayEquals(names.toString(), expectedValues, array);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Value(com.hazelcast.query.SampleTestObjects.Value) ArrayList(java.util.ArrayList) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with Value

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

the class QueryBasicTest method testIndexingEnumAttributeWithSqlIssue597.

/**
 * see pull request 616
 */
@Test(timeout = 1000 * 90)
public void testIndexingEnumAttributeWithSqlIssue597() {
    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);
    }
    Collection<Value> values = map.values(Predicates.sql("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.SampleTestObjects.ValueType) Value(com.hazelcast.query.SampleTestObjects.Value) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with Value

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

the class QueryBasicTest method issue393.

@Test(timeout = 1000 * 90)
public void issue393() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Value> map = instance.getMap("default");
    map.addIndex(IndexType.SORTED, "name");
    for (int i = 0; i < 4; i++) {
        Value v = new Value("name" + i);
        map.put("" + i, v);
    }
    Predicate predicate = Predicates.newPredicateBuilder().getEntryObject().get("name").in("name0", "name2");
    Collection<Value> values = map.values(predicate);
    String[] expectedValues = new String[] { "name0", "name2" };
    assertEquals(expectedValues.length, values.size());
    List<String> names = new ArrayList<>();
    for (Value configObject : values) {
        names.add(configObject.getName());
    }
    String[] array = names.toArray(new String[0]);
    Arrays.sort(array);
    assertArrayEquals(names.toString(), expectedValues, array);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Value(com.hazelcast.query.SampleTestObjects.Value) ArrayList(java.util.ArrayList) Predicate(com.hazelcast.query.Predicate) 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