use of io.pravega.segmentstore.server.logs.operations.StreamSegmentSealOperation in project pravega by pravega.
the class ContainerMetadataUpdateTransactionTests method testAcceptStreamSegmentSeal.
/**
* Tests the accept method with StreamSegmentSeal operations.
*/
@Test
public void testAcceptStreamSegmentSeal() throws Exception {
UpdateableContainerMetadata metadata = createMetadata();
// Set some attributes.
val segmentAttributes = createAttributes();
segmentAttributes.put(Attributes.CREATION_TIME, 1L);
UpdateableSegmentMetadata segmentMetadata = metadata.getStreamSegmentMetadata(SEGMENT_ID);
segmentMetadata.updateAttributes(segmentAttributes);
val txn = createUpdateTransaction(metadata);
StreamSegmentSealOperation sealOp = createSeal();
// When no pre-process has happened.
AssertExtensions.assertThrows("Unexpected behavior from acceptOperation() when no pre-processing was made.", () -> txn.acceptOperation(sealOp), ex -> ex instanceof MetadataUpdateException);
Assert.assertFalse("acceptOperation updated the transaction even if it threw an exception.", txn.getStreamSegmentMetadata(SEGMENT_ID).isSealed());
Assert.assertFalse("acceptOperation updated the metadata.", metadata.getStreamSegmentMetadata(SEGMENT_ID).isSealed());
// When all is good.
txn.preProcessOperation(sealOp);
txn.acceptOperation(sealOp);
Assert.assertTrue("acceptOperation did not update the transaction.", txn.getStreamSegmentMetadata(SEGMENT_ID).isSealed());
Assert.assertFalse("acceptOperation updated the metadata.", segmentMetadata.isSealed());
txn.commit(metadata);
// Check attributes.
DEFAULT_TYPE.intoAttributes(segmentAttributes);
SegmentMetadataComparer.assertSameAttributes("Unexpected set of attributes after commit.", segmentAttributes, segmentMetadata);
}
Aggregations