use of org.infinispan.CacheSet in project infinispan by infinispan.
the class BaseStreamTest method testLongFlatMapObjConsumerForEach.
public void testLongFlatMapObjConsumerForEach() {
Cache<Long, String> cache = getCache(0);
String cacheName = cache.getName();
int range = 10;
// First populate the cache with a bunch of values
LongStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
CacheSet<Map.Entry<Long, String>> entrySet = cache.entrySet();
int offset = populateNextForEachStructure(new AtomicLong());
try {
createStream(entrySet).distributedBatchSize(5).mapToLong(toLong).flatMap(i -> LongStream.of(i, 2)).forEach((c, e) -> {
assertEquals(cacheName, c.getName());
AtomicLong atomic = getForEachObject(offset);
atomic.addAndGet(e);
});
AtomicLong atomic = getForEachObject(offset);
assertEquals((range - 1) * (range / 2) + 2 * range, atomic.get());
} finally {
clearForEachObject(offset);
}
}
use of org.infinispan.CacheSet in project infinispan by infinispan.
the class BaseStreamTest method testDoubleFlatMapObjConsumerForEach.
public void testDoubleFlatMapObjConsumerForEach() {
Cache<Double, String> cache = getCache(0);
String cacheName = cache.getName();
int range = 10;
// First populate the cache with a bunch of values
DoubleStream.iterate(0.0, d -> d + .5).limit(10).boxed().forEach(i -> cache.put(i, i + "-value"));
CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet();
int offset = populateNextForEachStructure(new DoubleSummaryStatistics());
try {
createStream(entrySet).distributedBatchSize(5).mapToDouble(toDouble).flatMap(e -> DoubleStream.of(e, 2.25)).forEach((c, e) -> {
assertEquals(cacheName, c.getName());
DoubleSummaryStatistics stats = getForEachObject(offset);
synchronized (stats) {
stats.accept(e);
}
});
DoubleSummaryStatistics stats = getForEachObject(offset);
assertEquals(2.25, stats.getAverage());
assertEquals(0.0, stats.getMin());
assertEquals(4.5, stats.getMax());
assertEquals(20, stats.getCount());
assertEquals(45.0, stats.getSum());
} finally {
clearForEachObject(offset);
}
}
use of org.infinispan.CacheSet in project infinispan by infinispan.
the class BaseStreamTest method testIntFlatMapForEach.
public void testIntFlatMapForEach() {
Cache<Integer, String> cache = getCache(0);
int range = 10;
// First populate the cache with a bunch of values
IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
int offset = populateNextForEachStructure(new AtomicInteger());
try {
createStream(entrySet).distributedBatchSize(5).mapToInt(toInt).flatMap(i -> IntStream.of(i, 2)).forEach(e -> {
AtomicInteger atomic = getForEachObject(offset);
atomic.addAndGet(e);
});
AtomicInteger atomic = getForEachObject(offset);
assertEquals((range - 1) * (range / 2) + 2 * range, atomic.get());
} finally {
clearForEachObject(offset);
}
}
use of org.infinispan.CacheSet in project infinispan by infinispan.
the class BaseStreamTest method testIntFlatMapObjConsumerForEach.
public void testIntFlatMapObjConsumerForEach() {
Cache<Integer, String> cache = getCache(0);
String cacheName = cache.getName();
int range = 10;
// First populate the cache with a bunch of values
IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
int offset = populateNextForEachStructure(new AtomicInteger());
try {
createStream(entrySet).distributedBatchSize(5).mapToInt(toInt).flatMap(i -> IntStream.of(i, 2)).forEach((c, e) -> {
assertEquals(cacheName, c.getName());
AtomicInteger atomic = getForEachObject(offset);
atomic.addAndGet(e);
});
AtomicInteger atomic = getForEachObject(offset);
assertEquals((range - 1) * (range / 2) + 2 * range, atomic.get());
} finally {
clearForEachObject(offset);
}
}
use of org.infinispan.CacheSet in project infinispan by infinispan.
the class BaseStreamTest method testObjSortedCollector.
public void testObjSortedCollector() {
Cache<Integer, String> cache = getCache(0);
int range = 10;
// First populate the cache with a bunch of values
IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
List<Map.Entry<Integer, String>> list = createStream(entrySet).sorted((e1, e2) -> Integer.compare(e1.getKey(), e2.getKey())).collect(Collectors::<Map.Entry<Integer, String>>toList);
assertEquals(cache.size(), list.size());
AtomicInteger i = new AtomicInteger();
list.forEach(e -> {
assertEquals(i.getAndIncrement(), e.getKey().intValue());
assertEquals(cache.get(e.getKey()), e.getValue());
});
}
Aggregations