use of com.hazelcast.query.EntryObject in project hazelcast by hazelcast.
the class MapLiteMemberTest method testMapValuesQuery.
public static void testMapValuesQuery(final IMap<Integer, Object> map) {
map.put(1, 2);
EntryObject entryObject = new PredicateBuilder().getEntryObject();
PredicateBuilder predicateBuilder = entryObject.key().equal(1);
Collection values = map.values(predicateBuilder);
assertEquals(1, values.size());
assertEquals(2, values.iterator().next());
}
use of com.hazelcast.query.EntryObject in project hazelcast by hazelcast.
the class NearCacheTest method testAfterExecuteOnEntriesNearCacheIsInvalidated.
@Test
public void testAfterExecuteOnEntriesNearCacheIsInvalidated() {
int mapSize = 10;
String mapName = randomMapName();
Config config = createNearCachedMapConfig(mapName);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Integer, Employee> map = instance.getMap(mapName);
for (int i = 0; i < mapSize; i++) {
map.put(i, new Employee(i, "", 0, true, 0D));
}
populateNearCache(map, mapSize);
EntryObject e = new PredicateBuilder().getEntryObject();
Predicate predicate = e.get("salary").equal(0);
map.executeOnEntries(new AbstractEntryProcessor<Integer, Employee>() {
@Override
public Object process(Map.Entry<Integer, Employee> entry) {
Employee employee = entry.getValue();
double currentSalary = employee.getSalary();
double newSalary = currentSalary + 10;
employee.setSalary(newSalary);
return newSalary;
}
}, predicate);
assertEquals(0, getNearCacheStats(map).getOwnedEntryCount());
}
use of com.hazelcast.query.EntryObject in project hazelcast by hazelcast.
the class MapTransactionRegressionTest method test_Issue1076.
@Test
public void test_Issue1076() {
Config config = getConfig();
final HazelcastInstance inst = createHazelcastInstance(config);
IMap map = inst.getMap("default");
EntryListener<String, Integer> l = new EntryAdapter<String, Integer>() {
};
EntryObject e = new PredicateBuilder().getEntryObject();
Predicate<String, Integer> p = e.equal(1);
map.addEntryListener(l, p, null, false);
for (Integer i = 0; i < 100; i++) {
TransactionContext context = inst.newTransactionContext();
context.beginTransaction();
TransactionalMap<String, Integer> txnMap = context.getMap("default");
txnMap.remove(i.toString());
context.commitTransaction();
}
assertEquals(0, map.size());
inst.shutdown();
}
use of com.hazelcast.query.EntryObject 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.EntryObject in project hazelcast by hazelcast.
the class EntryProcessorTest method testMapEntryProcessorWithPredicate.
@Test
public void testMapEntryProcessorWithPredicate() {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
Config cfg = getConfig();
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(cfg);
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(cfg);
try {
IMap<Integer, Employee> map = instance1.getMap(MAP_NAME);
int size = 10;
for (int i = 0; i < size; i++) {
map.put(i, new Employee(i, "", 0, false, 0D, SampleObjects.State.STATE1));
}
EntryProcessor entryProcessor = new ChangeStateEntryProcessor();
EntryObject entryObject = new PredicateBuilder().getEntryObject();
Predicate predicate = entryObject.get("id").lessThan(5);
Map<Integer, Object> res = map.executeOnEntries(entryProcessor, predicate);
for (int i = 0; i < 5; i++) {
assertEquals(SampleObjects.State.STATE2, map.get(i).getState());
}
for (int i = 5; i < size; i++) {
assertEquals(SampleObjects.State.STATE1, map.get(i).getState());
}
for (int i = 0; i < 5; i++) {
assertEquals(((Employee) res.get(i)).getState(), SampleObjects.State.STATE2);
}
} finally {
instance1.shutdown();
instance2.shutdown();
}
}
Aggregations