use of io.pravega.client.stream.Checkpoint in project pravega by pravega.
the class ReaderCheckpointTest method readerCheckpointTest.
@Test
public void readerCheckpointTest() {
@Cleanup ReaderGroupManager readerGroupManager = ReaderGroupManager.withScope(SCOPE, controllerURI);
ReaderGroup readerGroup = readerGroupManager.createReaderGroup(READER_GROUP_NAME, ReaderGroupConfig.builder().stream(io.pravega.client.stream.Stream.of(SCOPE, STREAM)).build());
int startInclusive = 1;
int endExclusive = 100;
log.info("Write events with range [{},{})", startInclusive, endExclusive);
writeEvents(IntStream.range(startInclusive, endExclusive).boxed().collect(Collectors.toList()));
readEventsAndVerify(startInclusive, endExclusive);
// initiate checkpoint100
Checkpoint checkPoint100 = createCheckPointAndVerify(readerGroup, "batch100");
// write and read events 100 to 200
startInclusive = 100;
endExclusive = 200;
log.info("Write events with range [{},{})", startInclusive, endExclusive);
writeEvents(IntStream.range(startInclusive, endExclusive).boxed().collect(Collectors.toList()));
readEventsAndVerify(startInclusive, endExclusive);
// reset to check point 100
readerGroup.resetReaderGroup(ReaderGroupConfig.builder().startFromCheckpoint(checkPoint100).build());
readEventsAndVerify(100, endExclusive);
// initiate checkpoint200
Checkpoint checkPoint200 = createCheckPointAndVerify(readerGroup, "batch200");
// write and read events 200 to 300
startInclusive = 200;
endExclusive = 300;
log.info("Write events with range [{},{})", startInclusive, endExclusive);
writeEvents(IntStream.range(startInclusive, endExclusive).boxed().collect(Collectors.toList()));
readEventsAndVerify(startInclusive, endExclusive);
// reset back to checkpoint 200
readerGroup.resetReaderGroup(ReaderGroupConfig.builder().startFromCheckpoint(checkPoint200).build());
readEventsAndVerify(200, endExclusive);
// reset back to checkpoint 100
readerGroup.resetReaderGroup(ReaderGroupConfig.builder().startFromCheckpoint(checkPoint100).build());
readEventsAndVerify(100, endExclusive);
// clean up
readerGroupManager.deleteReaderGroup(READER_GROUP_NAME);
}
use of io.pravega.client.stream.Checkpoint in project pravega by pravega.
the class ReaderCheckpointTest method createCheckPointAndVerify.
private Checkpoint createCheckPointAndVerify(final ReaderGroup readerGroup, final String checkPointName) {
log.info("Create and verify check point {}", checkPointName);
String readerId = "checkPointReader";
CompletableFuture<Checkpoint> checkpoint = null;
try (ClientFactory clientFactory = ClientFactory.withScope(SCOPE, controllerURI);
EventStreamReader<Integer> reader = clientFactory.createReader(readerId, READER_GROUP_NAME, new JavaSerializer<Integer>(), readerConfig)) {
// create checkpoint
checkpoint = readerGroup.initiateCheckpoint(checkPointName, executor);
// verify checkpoint event.
EventRead<Integer> event = reader.readNextEvent(READ_TIMEOUT);
assertTrue("Read for Checkpoint event", (event != null) && (event.isCheckpoint()));
assertEquals("CheckPoint Name", checkPointName, event.getCheckpointName());
} catch (ReinitializationRequiredException e) {
log.error("Exception while reading event using readerId: {}", readerId, e);
fail("Reinitialization Exception is not expected");
}
return checkpoint.join();
}
Aggregations