use of org.infinispan.commons.util.IntSets in project infinispan by infinispan.
the class SimpleClusterPublisherManagerTest method insert.
private Map<Integer, String> insert(Cache<Integer, String> cache) {
int amount = 12;
Map<Integer, String> values = new HashMap<>(amount);
Map<Integer, IntSet> keysBySegment = log.isTraceEnabled() ? new HashMap<>() : null;
KeyPartitioner kp = TestingUtil.extractComponent(cache, KeyPartitioner.class);
IntStream.range(0, amount).forEach(i -> {
values.put(i, "value-" + i);
if (keysBySegment != null) {
int segment = kp.getSegment(i);
IntSet keys = keysBySegment.computeIfAbsent(segment, IntSets::mutableEmptySet);
keys.set(i);
}
});
if (keysBySegment != null) {
log.tracef("Keys by segment are: " + keysBySegment);
}
cache.putAll(values);
return values;
}
use of org.infinispan.commons.util.IntSets in project infinispan by infinispan.
the class BaseStreamTest method testObjFlatMapIterator.
public void testObjFlatMapIterator() {
Cache<Integer, String> cache = getCache(0);
int range = 10;
Map<Integer, IntSet> keysBySegment = log.isTraceEnabled() ? new TreeMap<>() : null;
KeyPartitioner kp = TestingUtil.extractComponent(cache, KeyPartitioner.class);
// First populate the cache with a bunch of values
IntStream.range(0, range).boxed().forEach(i -> {
if (keysBySegment != null) {
int segment = kp.getSegment(i);
IntSet keys = keysBySegment.computeIfAbsent(segment, IntSets::mutableEmptySet);
keys.set(i);
}
cache.put(i, i + "-value" + i);
});
if (keysBySegment != null) {
log.tracef("Keys by segment are: " + keysBySegment);
}
CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
StringJoiner stringJoiner = new StringJoiner(" ");
// Rxjava requets 128 by default for many operations - thus we have a number larger than that
int explosionCount = 293;
for (int i = 0; i < explosionCount; ++i) {
stringJoiner.add("special-" + String.valueOf(i));
}
String specialString = stringJoiner.toString();
Iterator<String> iterator = createStream(entrySet).distributedBatchSize(1).flatMap(e -> {
if (e.getKey() == 2) {
// Make sure to test an empty stream as well
return Stream.empty();
}
if (e.getKey() == 5) {
// Make sure we also test a very large resulting stream without the key in it
return Arrays.stream(specialString.split(" "));
}
return Arrays.stream(e.getValue().split("a"));
}).iterator();
List<String> list = new ArrayList<>(range * 2);
iterator.forEachRemaining(list::add);
if (keysBySegment != null) {
log.tracef("Returned values are: %s", list);
}
assertEquals((range - 2) * 2 + explosionCount, list.size());
}
Aggregations