use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.
the class QueryCacheTest method testQueryCacheCleared_afterCalling_IMap_clear.
@Test
public void testQueryCacheCleared_afterCalling_IMap_clear() {
String cacheName = randomString();
final QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
populateMap(map, 1000);
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 SampleableConcurrentHashMapTest method applyIfAbsentTest.
@Test
public void applyIfAbsentTest() throws Throwable {
final SampleableConcurrentHashMap<String, String> map = new SampleableConcurrentHashMap<String, String>(10);
assertEquals(map.applyIfAbsent("key", new IFunction<String, String>() {
@Override
public String apply(String input) {
return "value";
}
}), "value");
final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
final int COUNT = 10;
final CountDownLatch latch = new CountDownLatch(COUNT);
for (int i = 0; i < COUNT; i++) new Thread(new Runnable() {
@Override
public void run() {
try {
assertEquals(map.applyIfAbsent("key", new IFunction<String, String>() {
@Override
public String apply(String input) {
return "value1";
}
}), "value");
} catch (Throwable e) {
error.set(e);
} finally {
latch.countDown();
}
}
}).start();
latch.await(20, TimeUnit.SECONDS);
if (error.get() != null) {
throw error.get();
}
map.clear();
map.applyIfAbsent("key", new IFunction<String, String>() {
@Override
public String apply(String input) {
return null;
}
});
assertEquals(map.size(), 0);
}
use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.
the class AlterAndGetOperation method run.
@Override
public void run() throws Exception {
NodeEngine nodeEngine = getNodeEngine();
IFunction f = nodeEngine.toObject(function);
AtomicReferenceContainer atomicReferenceContainer = getReferenceContainer();
Data originalData = atomicReferenceContainer.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;
atomicReferenceContainer.set(backup);
}
response = output;
}
use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.
the class QueryCacheTest method testQueryCacheCleared_afterCalling_IMap_evictAll.
@Test
public void testQueryCacheCleared_afterCalling_IMap_evictAll() {
String cacheName = randomString();
QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
populateMap(map, 1000);
IFunction evictAll = new IFunction() {
@Override
public Object apply(Object ignored) {
map.evictAll();
return null;
}
};
assertQueryCacheSizeEventually(0, evictAll, queryCache);
}
use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.
the class ClientQueryCacheTest method testQueryCacheCleared_afterCalling_IMap_evictAll.
@Test
public void testQueryCacheCleared_afterCalling_IMap_evictAll() {
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 evictAll = new IFunction() {
@Override
public Object apply(Object ignored) {
map.evictAll();
return null;
}
};
assertQueryCacheSizeEventually(0, evictAll, queryCache);
}
Aggregations