Search in sources :

Example 6 with Checkpoint

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);
}
Also used : ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) Checkpoint(io.pravega.client.stream.Checkpoint) ReaderGroup(io.pravega.client.stream.ReaderGroup) Cleanup(lombok.Cleanup) Checkpoint(io.pravega.client.stream.Checkpoint) Test(org.junit.Test)

Example 7 with Checkpoint

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();
}
Also used : Checkpoint(io.pravega.client.stream.Checkpoint) ReinitializationRequiredException(io.pravega.client.stream.ReinitializationRequiredException) ClientFactory(io.pravega.client.ClientFactory)

Aggregations

Checkpoint (io.pravega.client.stream.Checkpoint)7 ReaderGroup (io.pravega.client.stream.ReaderGroup)5 Cleanup (lombok.Cleanup)5 Test (org.junit.Test)5 ClientFactory (io.pravega.client.ClientFactory)3 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)3 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)2 Segment (io.pravega.client.segment.impl.Segment)2 ReinitializationRequiredException (io.pravega.client.stream.ReinitializationRequiredException)2 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)2 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)2 MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)2 HashMap (java.util.HashMap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)1 SegmentMetadataClient (io.pravega.client.segment.impl.SegmentMetadataClient)1 SegmentMetadataClientFactory (io.pravega.client.segment.impl.SegmentMetadataClientFactory)1 SegmentMetadataClientFactoryImpl (io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl)1 StateSynchronizer (io.pravega.client.state.StateSynchronizer)1