Search in sources :

Example 1 with Value

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

the class QueryBasicTest method issue393.

@Test(timeout = 1000 * 60)
public void issue393() {
    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 PredicateBuilder().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<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) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Value(com.hazelcast.query.SampleObjects.Value) ArrayList(java.util.ArrayList) 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 2 with Value

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

the class QueryIndexTest method testInnerIndex.

@Test(timeout = 1000 * 60)
public void testInnerIndex() {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<String, SampleObjects.Value> map = instance.getMap("default");
    map.addIndex("name", false);
    map.addIndex("type.typeName", false);
    for (int i = 0; i < 10; i++) {
        Value v = new Value("name" + i, i < 5 ? null : new ValueType("type" + i), i);
        map.put("" + i, v);
    }
    Predicate predicate = new PredicateBuilder().getEntryObject().get("type.typeName").in("type8", "type6");
    Collection<SampleObjects.Value> values = map.values(predicate);
    assertEquals(2, values.size());
    List<String> typeNames = new ArrayList<String>();
    for (Value configObject : values) {
        typeNames.add(configObject.getType().getTypeName());
    }
    String[] array = typeNames.toArray(new String[typeNames.size()]);
    Arrays.sort(array);
    assertArrayEquals(typeNames.toString(), new String[] { "type6", "type8" }, array);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleObjects.ValueType) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Value(com.hazelcast.query.SampleObjects.Value) ArrayList(java.util.ArrayList) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with Value

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

the class QueryIndexTest method testInnerIndexSql.

@Test(timeout = 1000 * 60)
public void testInnerIndexSql() {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<String, SampleObjects.Value> map = instance.getMap("default");
    map.addIndex("name", false);
    map.addIndex("type.typeName", 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("type.typeName='type1'");
    Collection<SampleObjects.Value> values = map.values(predicate);
    assertEquals(1, values.size());
    List<String> typeNames = new ArrayList<String>();
    for (Value configObject : values) {
        typeNames.add(configObject.getType().getTypeName());
    }
    assertArrayEquals(typeNames.toString(), new String[] { "type1" }, typeNames.toArray(new String[typeNames.size()]));
}
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) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with Value

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

the class QueryBasicTest method testInPredicateWithEmptyArray.

@Test(timeout = 1000 * 60)
public void testInPredicateWithEmptyArray() {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    Config cfg = getConfig();
    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 = new PredicateBuilder().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.SampleObjects.ValueType) PredicateBuilder(com.hazelcast.query.PredicateBuilder) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) Value(com.hazelcast.query.SampleObjects.Value) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) 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 5 with Value

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

the class QueryBasicTest method issue393SqlEq.

@Test(timeout = 1000 * 60)
public void issue393SqlEq() {
    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='name0'");
    Collection<Value> values = map.values(predicate);
    String[] expectedValues = new String[] { "name0" };
    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)

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