Search in sources :

Example 1 with Value

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

the class QueryBasicTest method issue393SqlIn.

@Test(timeout = 1000 * 90)
public void issue393SqlIn() {
    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 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)

Example 2 with Value

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

the class QueryBasicTest method testQueryIndexNullValues.

@Test
public void testQueryIndexNullValues() {
    final HazelcastInstance instance = createHazelcastInstance(getConfig());
    final IMap<String, Value> map = instance.getMap("default");
    map.addIndex(IndexType.SORTED, "name");
    map.put("first", new Value("first", 1));
    map.put("second", new Value(null, 2));
    map.put("third", new Value(null, 3));
    final Predicate predicate = Predicates.sql("name=null");
    final Collection<Value> values = map.values(predicate);
    final int[] expectedIndexValues = { 2, 3 };
    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 3 with Value

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

the class QueryBasicTest method issue393Fail.

@Test(timeout = 1000 * 90)
public void issue393Fail() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Value> map = instance.getMap("default");
    map.addIndex(IndexType.SORTED, "qwe");
    Value v = new Value("name");
    try {
        map.put("0", v);
        fail();
    } catch (Throwable e) {
        assertContains(e.getMessage(), "There is no suitable accessor for 'qwe'");
    }
}
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)

Example 4 with Value

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

the class QueryBasicTest method testNotEqual.

@Test
public void testNotEqual() {
    final HazelcastInstance instance = createHazelcastInstance(getConfig());
    final IMap<String, Value> map = instance.getMap("default");
    map.addIndex(IndexType.SORTED, "name");
    map.put("first", new Value("first", 1));
    map.put("second", new Value(null, 2));
    map.put("third", new Value(null, 3));
    final Predicate predicate = Predicates.sql("name != null");
    final Collection<Value> values = map.values(predicate);
    final int[] expectedIndexValues = { 1 };
    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 5 with Value

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

the class QueryBasicTest method testInPredicateWithEmptyArray.

@Test(timeout = 1000 * 90)
public void testInPredicateWithEmptyArray() {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    Config cfg = getConfig();
    cfg.setProperty(QueryEngineImpl.DISABLE_MIGRATION_FALLBACK.getName(), "true");
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(cfg);
    final IMap<String, Value> map = instance.getMap("default");
    for (int i = 0; i < 10; i++) {
        final Value v = new Value("name" + i, new ValueType("type" + i), i);
        map.put("" + i, v);
    }
    String[] emptyArray = new String[2];
    final Predicate predicate = Predicates.newPredicateBuilder().getEntryObject().get("name").in(emptyArray);
    final Collection<Value> values = map.values(predicate);
    assertEquals(values.size(), 0);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) Value(com.hazelcast.query.SampleTestObjects.Value) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) 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