use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.
the class ClientQueryCacheTest method testQueryCacheCleared_afterCalling_IMap_clear.
@Test
public void testQueryCacheCleared_afterCalling_IMap_clear() {
String cacheName = randomString();
final IMap<Integer, Integer> map = getMap();
QueryCache<Integer, Integer> queryCache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
for (int i = 0; i < 1000; i++) {
map.put(i, i);
}
IFunction clear = new IFunction() {
@Override
public Object apply(Object ignored) {
map.clear();
return null;
}
};
assertQueryCacheSizeEventually(0, clear, queryCache);
}
use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.
the class AlterOperation method run.
@Override
public void run() throws Exception {
NodeEngine nodeEngine = getNodeEngine();
IFunction f = nodeEngine.toObject(function);
AtomicReferenceContainer reference = getReferenceContainer();
Data originalData = reference.get();
Object input = nodeEngine.toObject(originalData);
//noinspection unchecked
Object output = f.apply(input);
Data serializedOutput = nodeEngine.toData(output);
shouldBackup = !isEquals(originalData, serializedOutput);
if (shouldBackup) {
backup = serializedOutput;
reference.set(backup);
}
}
use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.
the class ApplyOperation method run.
@Override
public void run() throws Exception {
NodeEngine nodeEngine = getNodeEngine();
IFunction f = nodeEngine.toObject(function);
AtomicReferenceContainer atomicReferenceContainer = getReferenceContainer();
Object input = nodeEngine.toObject(atomicReferenceContainer.get());
//noinspection unchecked
Object output = f.apply(input);
returnValue = nodeEngine.toData(output);
}
use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.
the class GetAndAlterOperation method run.
@Override
public void run() throws Exception {
NodeEngine nodeEngine = getNodeEngine();
IFunction f = nodeEngine.toObject(function);
AtomicReferenceContainer atomicReferenceContainer = getReferenceContainer();
response = atomicReferenceContainer.get();
Object input = nodeEngine.toObject(atomicReferenceContainer.get());
//noinspection unchecked
Object output = f.apply(input);
Data serializedOutput = nodeEngine.toData(output);
shouldBackup = !isEquals(response, serializedOutput);
if (shouldBackup) {
atomicReferenceContainer.set(serializedOutput);
backup = serializedOutput;
}
}
use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.
the class ReadManyOperationTest method whenFilterProvidedAndNoItemsAvailable.
@Test
public void whenFilterProvidedAndNoItemsAvailable() throws Exception {
long startSequence = ringbuffer.tailSequence() + 1;
IFunction<String, Boolean> filter = new IFunction<String, Boolean>() {
@Override
public Boolean apply(String input) {
return input.startsWith("good");
}
};
ReadManyOperation op = new ReadManyOperation(ringbuffer.getName(), startSequence, 3, 3, filter);
op.setNodeEngine(nodeEngine);
assertTrue(op.shouldWait());
ReadResultSetImpl response = getReadResultSet(op);
assertEquals(startSequence, op.sequence);
assertTrue(getReadResultSet(op).isEmpty());
ringbuffer.add("bad1");
assertTrue(op.shouldWait());
assertEquals(startSequence + 1, op.sequence);
assertEquals(1, response.readCount());
assertEquals(0, response.size());
ringbuffer.add("good1");
assertTrue(op.shouldWait());
assertEquals(startSequence + 2, op.sequence);
assertEquals(asList("good1"), response);
assertEquals(2, response.readCount());
ringbuffer.add("bad2");
assertTrue(op.shouldWait());
assertEquals(startSequence + 3, op.sequence);
assertEquals(asList("good1"), response);
assertEquals(3, response.readCount());
ringbuffer.add("good2");
assertTrue(op.shouldWait());
assertEquals(startSequence + 4, op.sequence);
assertEquals(asList("good1", "good2"), response);
assertEquals(4, response.readCount());
ringbuffer.add("bad3");
assertTrue(op.shouldWait());
assertEquals(startSequence + 5, op.sequence);
assertEquals(asList("good1", "good2"), response);
assertEquals(5, response.readCount());
ringbuffer.add("good3");
assertFalse(op.shouldWait());
assertEquals(startSequence + 6, op.sequence);
assertEquals(asList("good1", "good2", "good3"), response);
assertEquals(6, response.readCount());
}
Aggregations