use of io.pravega.segmentstore.server.UpdateableContainerMetadata in project pravega by pravega.
the class OperationMetadataUpdaterTests method testCommitRollbackAlternate.
/**
* Tests a mixed scenario where we commit one UpdateTransaction and then rollback the next one, one after another.
* testRollback() verifies a bunch of rollbacks and then commits in sequence; this test alternates one with the other.
*/
@Test
public void testCommitRollbackAlternate() throws Exception {
Predicate<Integer> shouldFail = index -> index % 2 == 1;
val referenceMetadata = createBlankMetadata();
val metadata = createBlankMetadata();
val updater = new OperationMetadataUpdater(metadata);
val lastSegmentId = new AtomicLong(-1);
val lastSegmentTxnId = new AtomicLong(-1);
for (int i = 0; i < TRANSACTION_COUNT; i++) {
// Check to see if this UpdateTransaction is going to end up being rolled back. If so, we should not update
// the reference metadata at all.
UpdateableContainerMetadata txnReferenceMetadata = shouldFail.test(i) ? null : referenceMetadata;
populateUpdateTransaction(updater, txnReferenceMetadata, lastSegmentId, lastSegmentTxnId);
if (shouldFail.test(i)) {
updater.rollback(0);
ContainerMetadataUpdateTransactionTests.assertMetadataSame("After rollback " + i, referenceMetadata, metadata);
} else {
updater.commitAll();
ContainerMetadataUpdateTransactionTests.assertMetadataSame("After commit " + i, referenceMetadata, metadata);
}
}
}
use of io.pravega.segmentstore.server.UpdateableContainerMetadata in project pravega by pravega.
the class StreamSegmentContainerMetadataTests method testEpoch.
/**
* Tests Epoch-related operations.
*/
@Test
public void testEpoch() {
final int epoch = 10;
final UpdateableContainerMetadata m = new MetadataBuilder(CONTAINER_ID).build();
AssertExtensions.assertThrows("setContainerEpoch allowed updating the sequence number in non-recovery mode.", () -> m.setContainerEpoch(Integer.MAX_VALUE), ex -> ex instanceof IllegalStateException);
// In recovery mode: setContainerEpoch should work.
m.enterRecoveryMode();
m.setContainerEpoch(epoch);
Assert.assertEquals("Unexpected value from getContainerEpoch.", epoch, m.getContainerEpoch());
AssertExtensions.assertThrows("setContainerEpoch allowed updating the epoch after the initial set.", () -> m.setContainerEpoch(11), ex -> ex instanceof IllegalStateException);
Assert.assertEquals("Unexpected value from getContainerEpoch after rejected update.", epoch, m.getContainerEpoch());
m.exitRecoveryMode();
Assert.assertEquals("Unexpected value from getContainerEpoch after exit from recovery mode.", epoch, m.getContainerEpoch());
}
use of io.pravega.segmentstore.server.UpdateableContainerMetadata in project pravega by pravega.
the class StreamSegmentContainerMetadataTests method testValidTruncationPoints.
/**
* Tests the ability to set and retrieve truncation points (truncation markers is tested separately).
*/
@Test
public void testValidTruncationPoints() {
final UpdateableContainerMetadata m = new MetadataBuilder(CONTAINER_ID).build();
for (int i = 0; i < 100; i += 2) {
m.setValidTruncationPoint(i);
}
for (int i = 0; i < 100; i++) {
boolean expectedValid = i % 2 == 0;
Assert.assertEquals("Unexpected result from isValidTruncationPoint.", expectedValid, m.isValidTruncationPoint(i));
}
}
use of io.pravega.segmentstore.server.UpdateableContainerMetadata 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