use of org.apache.flink.streaming.api.operators.collect.CollectCoordinationRequest in project flink by apache.
the class AbstractTestCoordinationRequestHandler method handleCoordinationRequest.
@Override
public CompletableFuture<CoordinationResponse> handleCoordinationRequest(CoordinationRequest request) {
if (closed) {
throw new RuntimeException("Handler closed");
}
Assert.assertTrue(request instanceof CollectCoordinationRequest);
CollectCoordinationRequest collectRequest = (CollectCoordinationRequest) request;
updateBufferedResults();
Assert.assertTrue(offset <= collectRequest.getOffset());
List<T> subList = Collections.emptyList();
if (collectRequest.getVersion().equals(version)) {
while (buffered.size() > 0 && collectRequest.getOffset() > offset) {
buffered.removeFirst();
offset++;
}
subList = new ArrayList<>();
Iterator<T> iterator = buffered.iterator();
for (int i = 0; i < BATCH_SIZE && iterator.hasNext(); i++) {
subList.add(iterator.next());
}
}
List<byte[]> nextBatch = CollectTestUtils.toBytesList(subList, serializer);
CoordinationResponse response;
if (random.nextBoolean()) {
// with 50% chance we return valid result
response = new CollectCoordinationResponse(version, checkpointedOffset, nextBatch);
} else {
// with 50% chance we return invalid result
response = new CollectCoordinationResponse(collectRequest.getVersion(), -1, Collections.emptyList());
}
return CompletableFuture.completedFuture(response);
}
Aggregations