use of io.pravega.client.stream.impl.ReaderGroupState.CompactReaderGroupState.CompactReaderGroupStateBuilder in project pravega by pravega.
the class SerializationTest method testReaderGroupInit.
@Test
public void testReaderGroupInit() throws Exception {
ReaderGroupInitSerializer initSerializer = new ReaderGroupInitSerializer();
ReaderGroupConfig config = ReaderGroupConfig.builder().disableAutomaticCheckpoints().groupRefreshTimeMillis(r.nextInt(1000)).stream(createSegment().getStream()).build();
verify(initSerializer, new ReaderGroupStateInit(config, createSegmentRangeMap(), createSegmentToLongMap(), false));
CompactReaderGroupStateBuilder builder = new CompactReaderGroupState.CompactReaderGroupStateBuilder();
builder.assignedSegments(createMap(this::createString, this::createSegmentRangeMap));
builder.checkpointState(new CheckpointState.CheckpointStateBuilder().checkpoints(createList(this::createString)).lastCheckpointPosition(createSegmentToLongMap()).checkpointPositions(createMap(this::createString, this::createSegmentToLongMap)).uncheckpointedHosts(createMap(this::createString, this::createStringList)).build());
builder.config(config);
builder.distanceToTail(createMap(this::createString, r::nextLong));
builder.endSegments(createSegmentToLongMap());
builder.unassignedSegments(createSegmentRangeMap());
builder.futureSegments(createMap(this::createSegmentWithRange, () -> new HashSet<>(createLongList())));
builder.lastReadPosition(createSegmentRangeMap());
verify(initSerializer, builder.build());
ReaderGroupStateInitSerializer newSerializer = new ReaderGroupStateInit.ReaderGroupStateInitSerializer();
ReaderGroupStateInitSerializer oldSerializer = new ReaderGroupStateInit.ReaderGroupStateInitSerializer() {
@Override
protected void declareVersions() {
version(0).revision(0, this::write00, this::read00);
}
};
ReaderGroupStateInit init = new ReaderGroupStateInit(config, createSegmentRangeMap(), createSegmentToLongMap(), false);
ReaderGroupStateInit oldFormat = newSerializer.deserialize(oldSerializer.serialize(init));
assertEquals(init.getStartingSegments().keySet().stream().map(s -> s.getSegment()).collect(Collectors.toSet()), oldFormat.getStartingSegments().keySet().stream().map(s -> s.getSegment()).collect(Collectors.toSet()));
assertEquals(init.getEndSegments(), oldFormat.getEndSegments());
assertEquals(init.getConfig(), oldFormat.getConfig());
}
Aggregations