Search in sources :

Example 6 with Value

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

the class QueryBasicTest method issue393SqlInInteger.

@Test(timeout = 1000 * 60)
public void issue393SqlInInteger() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Value> map = instance.getMap("default");
    map.addIndex("index", false);
    for (int i = 0; i < 4; i++) {
        Value v = new Value("name" + i, new ValueType("type" + i), i);
        map.put("" + i, v);
    }
    Predicate predicate = new SqlPredicate("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<String>();
    for (Value configObject : values) {
        names.add(configObject.getName());
    }
    String[] array = names.toArray(new String[names.size()]);
    Arrays.sort(array);
    assertArrayEquals(names.toString(), expectedValues, array);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleObjects.ValueType) Value(com.hazelcast.query.SampleObjects.Value) ArrayList(java.util.ArrayList) 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 7 with Value

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

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

the class QueryBasicTest method issue393Fail.

@Test(timeout = 1000 * 60)
public void issue393Fail() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Value> map = instance.getMap("default");
    map.addIndex("qwe", true);
    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.SampleObjects.Value) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with Value

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

the class QueryBasicTest method issue393SqlIn.

@Test(timeout = 1000 * 60)
public void issue393SqlIn() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Value> map = instance.getMap("default");
    map.addIndex("name", true);
    for (int i = 0; i < 4; i++) {
        Value v = new Value("name" + i);
        map.put("" + i, v);
    }
    Predicate predicate = new SqlPredicate("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<String>();
    for (Value configObject : values) {
        names.add(configObject.getName());
    }
    String[] array = names.toArray(new String[names.size()]);
    Arrays.sort(array);
    assertArrayEquals(names.toString(), expectedValues, array);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Value(com.hazelcast.query.SampleObjects.Value) ArrayList(java.util.ArrayList) 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 10 with Value

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

the class PredicatesTest method testAndPredicate_whenFirstIndexAwarePredicateIsNotIndexed.

@Test
public void testAndPredicate_whenFirstIndexAwarePredicateIsNotIndexed() throws Exception {
    final HazelcastInstance instance = createHazelcastInstance();
    final IMap<Object, Object> map = instance.getMap("map");
    map.addIndex("name", false);
    String name = randomString();
    map.put("key", new Value(name));
    final ShouldExecuteOncePredicate<?, ?> indexAwareNotIndexedPredicate = new ShouldExecuteOncePredicate<Object, Object>();
    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.SampleObjects.Value) EntryObject(com.hazelcast.query.EntryObject) Matchers.anyString(org.mockito.Matchers.anyString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Value (com.hazelcast.query.SampleObjects.Value)21 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 Test (org.junit.Test)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)16 QuickTest (com.hazelcast.test.annotation.QuickTest)16 SqlPredicate (com.hazelcast.query.SqlPredicate)13 Predicate (com.hazelcast.query.Predicate)9 ArrayList (java.util.ArrayList)7 PredicateBuilder (com.hazelcast.query.PredicateBuilder)6 ValueType (com.hazelcast.query.SampleObjects.ValueType)6 Config (com.hazelcast.config.Config)2 MapIndexConfig (com.hazelcast.config.MapIndexConfig)2 MapConfig (com.hazelcast.config.MapConfig)1 EntryObject (com.hazelcast.query.EntryObject)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1 Future (java.util.concurrent.Future)1 Matchers.anyString (org.mockito.Matchers.anyString)1