Search in sources :

Example 1 with UpdateDistanceToTailSerializer

use of io.pravega.client.stream.impl.ReaderGroupState.UpdateDistanceToTail.UpdateDistanceToTailSerializer in project pravega by pravega.

the class SerializationTest method testUpdateDistanceToTail.

@Test
@SuppressWarnings("unchecked")
public void testUpdateDistanceToTail() throws Exception {
    UpdateDistanceToTailSerializer serializer = new UpdateDistanceToTail.UpdateDistanceToTailSerializer();
    UpdateDistanceToTail update = new UpdateDistanceToTail(createString(), r.nextLong(), createSegmentRangeMap());
    UpdateDistanceToTail deserialized = serializer.deserialize(serializer.serialize(update));
    assertEquals(deserialized, update);
    UpdateDistanceToTailSerializer oldSerializer = new UpdateDistanceToTailSerializer() {

        @Override
        protected void declareVersions() {
            version(0).revision(0, this::write00, this::read00);
        }
    };
    UpdateDistanceToTail oldStyleUpdate = serializer.deserialize(oldSerializer.serialize(update));
    assertEquals(update.getReaderId(), oldStyleUpdate.getReaderId());
    assertEquals(update.getDistanceToTail(), oldStyleUpdate.getDistanceToTail());
    assertEquals(null, oldStyleUpdate.getLastReadPositions());
    // Change the state to reflect the update
    val segmentToOffsets = ImmutableMap.of(new SegmentWithRange(new Segment("scope", "stream", 0), 0.0, 1.0), 0L);
    ReaderGroupState state = new ReaderGroupState("_RGTest", mock(Revision.class), mock(ReaderGroupConfig.class), segmentToOffsets, mock(Map.class), false);
    // ensure no exceptions are thrown.
    oldStyleUpdate.update(state);
}
Also used : UpdateDistanceToTailSerializer(io.pravega.client.stream.impl.ReaderGroupState.UpdateDistanceToTail.UpdateDistanceToTailSerializer) lombok.val(lombok.val) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) Revision(io.pravega.client.state.Revision) UpdateDistanceToTail(io.pravega.client.stream.impl.ReaderGroupState.UpdateDistanceToTail) CompactReaderGroupState(io.pravega.client.stream.impl.ReaderGroupState.CompactReaderGroupState) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ByteArraySegment(io.pravega.common.util.ByteArraySegment) AcquireSegment(io.pravega.client.stream.impl.ReaderGroupState.AcquireSegment) ReleaseSegment(io.pravega.client.stream.impl.ReaderGroupState.ReleaseSegment) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Segment (io.pravega.client.segment.impl.Segment)1 Revision (io.pravega.client.state.Revision)1 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)1 AcquireSegment (io.pravega.client.stream.impl.ReaderGroupState.AcquireSegment)1 CompactReaderGroupState (io.pravega.client.stream.impl.ReaderGroupState.CompactReaderGroupState)1 ReleaseSegment (io.pravega.client.stream.impl.ReaderGroupState.ReleaseSegment)1 UpdateDistanceToTail (io.pravega.client.stream.impl.ReaderGroupState.UpdateDistanceToTail)1 UpdateDistanceToTailSerializer (io.pravega.client.stream.impl.ReaderGroupState.UpdateDistanceToTail.UpdateDistanceToTailSerializer)1 ByteArraySegment (io.pravega.common.util.ByteArraySegment)1 Map (java.util.Map)1 lombok.val (lombok.val)1 Test (org.junit.Test)1