use of org.infinispan.reactive.publisher.impl.SegmentPublisherSupplier in project infinispan by infinispan.
the class DistributedStreamIteratorTest method waitUntilProcessingResults.
@Test
public void waitUntilProcessingResults() throws TimeoutException, InterruptedException, ExecutionException {
Cache<Object, String> cache0 = cache(0, CACHE_NAME);
Cache<Object, String> cache1 = cache(1, CACHE_NAME);
Map<Object, String> values = new HashMap<>();
for (int i = 0; i < 9; ++i) {
MagicKey key = new MagicKey(cache1);
cache1.put(key, key.toString());
values.put(key, key.toString());
}
CheckPoint checkPoint = new CheckPoint();
checkPoint.triggerForever(Mocks.AFTER_RELEASE);
ClusterPublisherManager<Object, String> spy = Mocks.replaceComponentWithSpy(cache0, ClusterPublisherManager.class);
doAnswer(invocation -> {
SegmentPublisherSupplier<?> result = (SegmentPublisherSupplier<?>) invocation.callRealMethod();
return Mocks.blockingPublisher(result, checkPoint);
}).when(spy).entryPublisher(any(), any(), any(), anyLong(), any(), anyInt(), any());
final BlockingQueue<Map.Entry<Object, String>> returnQueue = new LinkedBlockingQueue<>();
Future<Void> future = fork(() -> {
Iterator<Map.Entry<Object, String>> iter = cache0.entrySet().stream().iterator();
while (iter.hasNext()) {
Map.Entry<Object, String> entry = iter.next();
returnQueue.add(entry);
}
return null;
});
// Now wait for them to send back first results but don't let them process
checkPoint.awaitStrict(Mocks.BEFORE_INVOCATION, 10, TimeUnit.SECONDS);
// Now let them process the results
checkPoint.triggerForever(Mocks.BEFORE_RELEASE);
// Now kill the cache - we should recover and get appropriate values
killMember(1, CACHE_NAME);
future.get(10, TimeUnit.SECONDS);
KeyPartitioner keyPartitioner = TestingUtil.extractComponent(cache0, KeyPartitioner.class);
Map<Integer, Set<Map.Entry<Object, String>>> expected = generateEntriesPerSegment(keyPartitioner, values.entrySet());
Map<Integer, Set<Map.Entry<Object, String>>> answer = generateEntriesPerSegment(keyPartitioner, returnQueue);
for (Map.Entry<Integer, Set<Map.Entry<Object, String>>> entry : expected.entrySet()) {
Integer segment = entry.getKey();
Set<Map.Entry<Object, String>> answerForSegment = answer.get(segment);
if (answerForSegment != null) {
for (Map.Entry<Object, String> exp : entry.getValue()) {
if (!answerForSegment.contains(exp)) {
log.errorf("Segment %d, missing %s", segment, exp);
}
}
for (Map.Entry<Object, String> ans : answerForSegment) {
if (!entry.getValue().contains(ans)) {
log.errorf("Segment %d, extra %s", segment, ans);
}
}
assertEquals(entry.getValue().size(), answerForSegment.size());
}
assertEquals("Segment " + segment + " had a mismatch", entry.getValue(), answerForSegment);
}
}
Aggregations