Search in sources :

Example 1 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class QueryIndexingTest method setUp.

@Before
public void setUp() {
    employees = newEmployees(count);
    nodeFactory = createHazelcastInstanceFactory(2);
    Config config = newConfig();
    h1 = nodeFactory.newHazelcastInstance(config);
    h2 = nodeFactory.newHazelcastInstance(config);
    EntryObject entryObject = Predicates.newPredicateBuilder().getEntryObject();
    predicate = entryObject.get("name").equal(null).and(entryObject.get("city").isNull());
    assertClusterSizeEventually(2, h1);
}
Also used : EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Config(com.hazelcast.config.Config) Before(org.junit.Before)

Example 2 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class QueryIndexTest method testResultsReturned_whenCustomAttributeIndexed.

@Test
public void testResultsReturned_whenCustomAttributeIndexed() {
    HazelcastInstance h1 = createTestHazelcastInstance();
    IMap<String, CustomObject> imap = h1.getMap("objects");
    imap.addIndex(IndexType.SORTED, "attribute");
    for (int i = 0; i < 10; i++) {
        CustomAttribute attr = new CustomAttribute(i, 200);
        CustomObject object = new CustomObject("o" + i, randomUUID(), attr);
        imap.put(object.getName(), object);
    }
    EntryObject entry = Predicates.newPredicateBuilder().getEntryObject();
    Predicate predicate = entry.get("attribute").greaterEqual(new CustomAttribute(5, 200));
    Collection<CustomObject> values = imap.values(predicate);
    assertEquals(5, values.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class EntryProcessorBouncingNodesTest method testEntryProcessorWhileTwoNodesAreBouncing.

@Test
public void testEntryProcessorWhileTwoNodesAreBouncing() {
    // now, with nodes joining and leaving the cluster concurrently, start adding numbers to the lists
    final ListHolder expected = new ListHolder();
    int iteration = 0;
    HazelcastInstance steadyMember = bounceMemberRule.getSteadyMember();
    final IMap<Integer, ListHolder> map = steadyMember.getMap(MAP_NAME);
    while (iteration < ITERATIONS) {
        IncrementProcessor processor = new IncrementProcessor(iteration);
        expected.add(iteration);
        for (int i = 0; i < ENTRIES; ++i) {
            if (withPredicate) {
                EntryObject eo = Predicates.newPredicateBuilder().getEntryObject();
                Predicate keyPredicate = eo.key().equal(i);
                map.executeOnEntries(processor, keyPredicate);
            } else {
                map.executeOnKey(i, processor);
            }
        }
        ++iteration;
    }
    for (int i = 0; i < ENTRIES; i++) {
        final int index = i;
        assertTrueEventually(() -> {
            ListHolder holder = map.get(index);
            String errorText = String.format("Each ListHolder should contain %d entries.\nInvalid list holder content:\n%s\n", ITERATIONS, holder.toString());
            assertEquals(errorText, ITERATIONS, holder.size());
            for (int it = 0; it < ITERATIONS; it++) {
                assertEquals(it, holder.get(it));
            }
        });
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 4 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class NestedPredicateWithExtractorTest method singleAttributeQuery_predicates.

@Test
public void singleAttributeQuery_predicates() {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    EntryObject e = Predicates.newPredicateBuilder().getEntryObject();
    Predicate predicate = e.get("name").equal("body1");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body1", values.toArray(new Body[0])[0].getName());
    assertEquals(2, bodyExtractorExecutions);
    assertEquals(0, limbExtractorExecutions);
}
Also used : EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class NestedPredicateTest method singleAttributeQuery_predicates.

@Test
public void singleAttributeQuery_predicates() {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    EntryObject e = Predicates.newPredicateBuilder().getEntryObject();
    Predicate predicate = e.get("name").equal("body1");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body1", values.toArray(new Body[0])[0].getName());
}
Also used : EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)24 Test (org.junit.Test)18 QuickTest (com.hazelcast.test.annotation.QuickTest)16 Predicate (com.hazelcast.query.Predicate)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 Employee (com.hazelcast.query.SampleTestObjects.Employee)7 Config (com.hazelcast.config.Config)6 PredicateBuilder (com.hazelcast.query.PredicateBuilder)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 MapConfig (com.hazelcast.config.MapConfig)4 EvictionConfig (com.hazelcast.config.EvictionConfig)2 IndexConfig (com.hazelcast.config.IndexConfig)2 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 NearCacheConfig (com.hazelcast.config.NearCacheConfig)2 IMap (com.hazelcast.map.IMap)2 Collection (java.util.Collection)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)1 EntryAdapter (com.hazelcast.core.EntryAdapter)1 EntryView (com.hazelcast.core.EntryView)1