cs.write(createEntry(obj1));
cs.write(createEntry(obj2));
cs.write(createEntry(obj3));
final ConcurrentHashMap map = new ConcurrentHashMap();
AdvancedCacheLoader.CacheLoaderTask taskWithValues = new AdvancedCacheLoader.CacheLoaderTask() {
@Override
public void processEntry(MarshalledEntry marshalledEntry, AdvancedCacheLoader.TaskContext taskContext) throws InterruptedException {
if (marshalledEntry.getKey() != null && marshalledEntry.getValue() != null) {
map.put(marshalledEntry.getKey(), marshalledEntry.getValue());
}
}
};
cs.process(null, taskWithValues, new ThreadPoolExecutor(1, 2, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(10)), true, false);
assertEquals(map.size(), 3);
assertEquals(map.remove(obj1.getKey()), obj1.getValue());
assertEquals(map.remove(obj2.getKey()), obj2.getValue());
assertEquals(map.remove(obj3.getKey()), obj3.getValue());
assertTrue(map.isEmpty());
final ConcurrentHashSet set = new ConcurrentHashSet();
AdvancedCacheLoader.CacheLoaderTask taskWithoutValues = new AdvancedCacheLoader.CacheLoaderTask() {
@Override
public void processEntry(MarshalledEntry marshalledEntry, AdvancedCacheLoader.TaskContext taskContext) throws InterruptedException {
if (marshalledEntry.getKey() != null) {
set.add(marshalledEntry.getKey());
}
}
};
cs.process(null, taskWithoutValues, new ThreadPoolExecutor(1, 2, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(10)), false, false);
assertEquals(set.size(), 3);
assertTrue(set.remove(obj1.getKey()));
assertTrue(set.remove(obj2.getKey()));
assertTrue(set.remove(obj3.getKey()));
assertTrue(map.isEmpty());
}