Search in sources :

Example 1 with CollectCoordinationResponse

use of org.apache.flink.streaming.api.operators.collect.CollectCoordinationResponse 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);
}
Also used : CollectCoordinationRequest(org.apache.flink.streaming.api.operators.collect.CollectCoordinationRequest) CoordinationResponse(org.apache.flink.runtime.operators.coordination.CoordinationResponse) CollectCoordinationResponse(org.apache.flink.streaming.api.operators.collect.CollectCoordinationResponse) CollectCoordinationResponse(org.apache.flink.streaming.api.operators.collect.CollectCoordinationResponse)

Example 2 with CollectCoordinationResponse

use of org.apache.flink.streaming.api.operators.collect.CollectCoordinationResponse in project flink by apache.

the class CollectTestUtils method assertAccumulatorResult.

public static <T> void assertAccumulatorResult(Tuple2<Long, CollectCoordinationResponse> accResults, long expectedOffset, String expectedVersion, long expectedLastCheckpointedOffset, List<T> expectedResults, TypeSerializer<T> serializer) throws Exception {
    long offset = accResults.f0;
    CollectCoordinationResponse response = accResults.f1;
    List<T> actualResults = response.getResults(serializer);
    Assert.assertEquals(expectedOffset, offset);
    Assert.assertEquals(expectedVersion, response.getVersion());
    Assert.assertEquals(expectedLastCheckpointedOffset, response.getLastCheckpointedOffset());
    assertResultsEqual(expectedResults, actualResults);
}
Also used : CollectCoordinationResponse(org.apache.flink.streaming.api.operators.collect.CollectCoordinationResponse)

Aggregations

CollectCoordinationResponse (org.apache.flink.streaming.api.operators.collect.CollectCoordinationResponse)2 CoordinationResponse (org.apache.flink.runtime.operators.coordination.CoordinationResponse)1 CollectCoordinationRequest (org.apache.flink.streaming.api.operators.collect.CollectCoordinationRequest)1