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);
}
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());
}
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));
}
}
}
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());
}
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;
}
Aggregations