Search in sources :

Example 51 with Predicate

use of com.hazelcast.query.Predicate 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)

Example 52 with Predicate

use of com.hazelcast.query.Predicate 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 53 with Predicate

use of com.hazelcast.query.Predicate 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 54 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class NotPredicateTest method negate_thenReturnInnerPredicate.

@Test
public void negate_thenReturnInnerPredicate() {
    Predicate inner = mock(Predicate.class);
    NotPredicate notPredicate = new NotPredicate(inner);
    Predicate negate = notPredicate.negate();
    assertThat(negate, sameInstance(inner));
}
Also used : TruePredicate(com.hazelcast.query.TruePredicate) FalsePredicate(com.hazelcast.query.impl.FalsePredicate) PredicateTestUtils.createMockVisitablePredicate(com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 55 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class OrPredicateTest method negate_whenContainsNonNegatablePredicate_thenReturnAndPredicateWithNotInside.

@Test
public void negate_whenContainsNonNegatablePredicate_thenReturnAndPredicateWithNotInside() {
    // ~(foo or bar)  -->  (~foo and ~bar)
    // this is testing the case where the inner predicate does NOT implement {@link Negatable}
    Predicate nonNegatable = mock(Predicate.class);
    OrPredicate or = (OrPredicate) or(nonNegatable);
    AndPredicate result = (AndPredicate) or.negate();
    Predicate[] inners = result.predicates;
    assertThat(inners, arrayWithSize(1));
    NotPredicate notPredicate = (NotPredicate) inners[0];
    assertThat(nonNegatable, sameInstance(notPredicate.predicate));
}
Also used : PredicateTestUtils.createMockNegatablePredicate(com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockNegatablePredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Predicate (com.hazelcast.query.Predicate)160 Test (org.junit.Test)125 QuickTest (com.hazelcast.test.annotation.QuickTest)124 ParallelTest (com.hazelcast.test.annotation.ParallelTest)107 TruePredicate (com.hazelcast.query.TruePredicate)41 SqlPredicate (com.hazelcast.query.SqlPredicate)33 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)23 PredicateBuilder (com.hazelcast.query.PredicateBuilder)19 EntryListener (com.hazelcast.core.EntryListener)16 MapListener (com.hazelcast.map.listener.MapListener)16 EntryObject (com.hazelcast.query.EntryObject)14 IndexAwarePredicate (com.hazelcast.query.IndexAwarePredicate)12 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)10 Value (com.hazelcast.query.SampleObjects.Value)9 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)9 ArrayList (java.util.ArrayList)9 EntryEvent (com.hazelcast.core.EntryEvent)8 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)8 ValueType (com.hazelcast.query.SampleObjects.ValueType)7