Search in sources :

Example 6 with Predicate

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

the class MapExecuteWithPredicateMessageTask method createOperationFactory.

@Override
protected OperationFactory createOperationFactory() {
    MapOperationProvider operationProvider = getOperationProvider(parameters.name);
    EntryProcessor entryProcessor = serializationService.toObject(parameters.entryProcessor);
    Predicate predicate = serializationService.toObject(parameters.predicate);
    return operationProvider.createPartitionWideEntryWithPredicateOperationFactory(parameters.name, entryProcessor, predicate);
}
Also used : EntryProcessor(com.hazelcast.map.EntryProcessor) MapOperationProvider(com.hazelcast.map.impl.operation.MapOperationProvider) Predicate(com.hazelcast.query.Predicate)

Example 7 with Predicate

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

the class ClientPagingPredicateTest method mapPagingPredicateEmployeeObjectWithOrderedIndex.

private void mapPagingPredicateEmployeeObjectWithOrderedIndex(int maxEmployee) {
    final IMap<Integer, Employee> map = makeEmployeeMap(maxEmployee);
    map.addIndex("id", true);
    Predicate pred = Predicates.lessThan("id", 2);
    PagingPredicate<Integer, Employee> predicate = new PagingPredicate<Integer, Employee>(pred, 2);
    Collection<Employee> values;
    values = map.values(predicate);
    System.out.println(values);
    assertEquals(2, values.size());
    predicate.nextPage();
    values = map.values(predicate);
    System.out.println(values);
    assertEquals(0, values.size());
}
Also used : PagingPredicate(com.hazelcast.query.PagingPredicate) PagingPredicate(com.hazelcast.query.PagingPredicate) Predicate(com.hazelcast.query.Predicate)

Example 8 with Predicate

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

the class EntryProcessorBouncingNodesTest method testEntryProcessorWhileTwoNodesAreBouncing.

private void testEntryProcessorWhileTwoNodesAreBouncing(boolean withPredicate, boolean withIndex) {
    CountDownLatch startLatch = new CountDownLatch(1);
    AtomicBoolean isRunning = new AtomicBoolean(true);
    // start up three instances
    HazelcastInstance instance = newInstance(withIndex);
    HazelcastInstance instance2 = newInstance(withIndex);
    HazelcastInstance instance3 = newInstance(withIndex);
    assertClusterSizeEventually(3, instance);
    final IMap<Integer, ListHolder> map = instance.getMap(MAP_NAME);
    final ListHolder expected = new ListHolder();
    // initialize the list synchronously to ensure the map is correctly initialized
    InitMapProcessor initProcessor = new InitMapProcessor();
    for (int i = 0; i < ENTRIES; ++i) {
        map.executeOnKey(i, initProcessor);
    }
    assertEquals(ENTRIES, map.size());
    // spin up the thread that stops/starts the instance2 and instance3, always keeping one instance running
    Runnable runnable = new TwoNodesRestartingRunnable(startLatch, isRunning, withPredicate, instance2, instance3);
    Thread bounceThread = new Thread(runnable);
    bounceThread.start();
    // now, with nodes joining and leaving the cluster concurrently, start adding numbers to the lists
    int iteration = 0;
    while (iteration < ITERATIONS) {
        if (iteration == 30) {
            // let the bounce threads start bouncing
            startLatch.countDown();
        }
        IncrementProcessor processor = new IncrementProcessor(iteration);
        expected.add(iteration);
        for (int i = 0; i < ENTRIES; ++i) {
            if (withPredicate) {
                EntryObject eo = new PredicateBuilder().getEntryObject();
                Predicate keyPredicate = eo.key().equal(i);
                map.executeOnEntries(processor, keyPredicate);
            } else {
                map.executeOnKey(i, processor);
            }
        }
        // give processing time to catch up
        ++iteration;
    }
    // signal the bounce threads that we're done
    isRunning.set(false);
    // wait for the instance bounces to complete
    assertJoinable(bounceThread);
    final CountDownLatch latch = new CountDownLatch(ENTRIES);
    for (int i = 0; i < ENTRIES; ++i) {
        final int id = i;
        new Thread(new Runnable() {

            @Override
            public void run() {
                assertTrueEventually(new AssertTask() {

                    @Override
                    public void run() throws Exception {
                        assertTrue(expected.size() <= map.get(id).size());
                    }
                });
                latch.countDown();
            }
        }).start();
    }
    assertOpenEventually(latch);
    for (int index = 0; index < ENTRIES; ++index) {
        ListHolder holder = map.get(index);
        assertEquals("The ListHolder should contain ITERATIONS entries", ITERATIONS, holder.size());
        for (int i = 0; i < ITERATIONS; i++) {
            assertEquals(i, holder.get(i));
        }
    }
}
Also used : EntryObject(com.hazelcast.query.EntryObject) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) Predicate(com.hazelcast.query.Predicate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) PredicateBuilder(com.hazelcast.query.PredicateBuilder) AssertTask(com.hazelcast.test.AssertTask)

Example 9 with Predicate

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

the class EntryProcessorTest method issue9798_indexNotUpdatedWithObjectFormat_onEntries.

@Test
public void issue9798_indexNotUpdatedWithObjectFormat_onEntries() throws Exception {
    IMap<Long, MyData> testMap = setupImapForEntryProcessorWithIndex();
    testMap.set(1L, new MyData(10));
    testMap.set(2L, new MyData(20));
    testMap.executeOnEntries(new MyProcessor());
    Predicate betweenPredicate = Predicates.between("lastValue", 0, 10);
    Collection<MyData> values = testMap.values(betweenPredicate);
    assertEquals(0, values.size());
    assertEquals(11, testMap.get(1L).getLastValue());
    assertEquals(21, testMap.get(2L).getLastValue());
}
Also used : Predicate(com.hazelcast.query.Predicate) IndexAwarePredicate(com.hazelcast.query.IndexAwarePredicate) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with Predicate

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

the class PredicateTestUtils method createMockVisitablePredicate.

static Predicate createMockVisitablePredicate() {
    VisitablePredicate visitablePredicate = mock(VisitablePredicate.class, withSettings().extraInterfaces(Predicate.class));
    when(visitablePredicate.accept((Visitor) anyObject(), (Indexes) anyObject())).thenReturn((Predicate) visitablePredicate);
    return (Predicate) visitablePredicate;
}
Also used : VisitablePredicate(com.hazelcast.query.VisitablePredicate) Predicate(com.hazelcast.query.Predicate) VisitablePredicate(com.hazelcast.query.VisitablePredicate)

Aggregations

Predicate (com.hazelcast.query.Predicate)248 Test (org.junit.Test)165 QuickTest (com.hazelcast.test.annotation.QuickTest)159 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)105 HazelcastInstance (com.hazelcast.core.HazelcastInstance)38 MapListener (com.hazelcast.map.listener.MapListener)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)17 EntryListener (com.hazelcast.core.EntryListener)16 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)15 ArrayList (java.util.ArrayList)15 EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)14 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)14 Value (com.hazelcast.query.SampleTestObjects.Value)10 SqlPredicate (com.hazelcast.query.SqlPredicate)10 Config (com.hazelcast.config.Config)9 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)9 EntryEvent (com.hazelcast.core.EntryEvent)8 Data (com.hazelcast.internal.serialization.Data)8 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)8 Indexes (com.hazelcast.query.impl.Indexes)8