use of io.pravega.segmentstore.server.MetadataBuilder in project pravega by pravega.
the class StreamSegmentContainerMetadataTests method testTruncationMarkers.
/**
* Tests the Truncation Marker functionality (truncation points is tested separately).
*/
@Test
public void testTruncationMarkers() {
final long maxSeqNo = 1000;
final int markerFrequency = 13;
Function<Long, LogAddress> getFrameAddress = seqNo -> new TestLogAddress(Integer.MAX_VALUE + seqNo * seqNo);
final UpdateableContainerMetadata m = new MetadataBuilder(CONTAINER_ID).build();
// Record some truncation markers, starting a few steps after initial.
for (long seqNo = markerFrequency; seqNo <= maxSeqNo; seqNo += markerFrequency) {
m.recordTruncationMarker(seqNo, getFrameAddress.apply(seqNo));
}
// Verify them.
for (long seqNo = 0; seqNo < maxSeqNo + markerFrequency; seqNo++) {
LogAddress expectedTruncationMarker = null;
if (seqNo >= markerFrequency) {
long input = seqNo > maxSeqNo ? maxSeqNo : seqNo;
expectedTruncationMarker = getFrameAddress.apply(input - input % markerFrequency);
}
LogAddress truncationMarker = m.getClosestTruncationMarker(seqNo);
Assert.assertEquals("Unexpected truncation marker value for Op Sequence Number " + seqNo, expectedTruncationMarker, truncationMarker);
}
// Remove some truncation markers & verify again.
for (long seqNo = 0; seqNo < maxSeqNo + markerFrequency; seqNo++) {
m.removeTruncationMarkers(seqNo);
// Check that the removal actually made sense (it should return -1 now).
LogAddress truncationMarker = m.getClosestTruncationMarker(seqNo);
Assert.assertNull("Unexpected truncation marker value after removal for Op Sequence Number " + seqNo, truncationMarker);
// Check that the next higher up still works.
long input = seqNo + markerFrequency;
input = input > maxSeqNo ? maxSeqNo : input;
LogAddress expectedTruncationMarker;
if (seqNo > maxSeqNo - markerFrequency) {
// We have already removed all possible truncation markers, so expect the result to be -1.
expectedTruncationMarker = null;
} else {
expectedTruncationMarker = getFrameAddress.apply(input - input % markerFrequency);
}
truncationMarker = m.getClosestTruncationMarker(input);
Assert.assertEquals("Unexpected truncation marker value for Op Sequence Number " + input + " after removing marker at Sequence Number " + seqNo, expectedTruncationMarker, truncationMarker);
}
}
Aggregations