Search in sources :

Example 51 with AttributeId

use of io.pravega.segmentstore.contracts.AttributeId in project pravega by pravega.

the class SegmentAttributeIteratorTests method testOutOfRange.

/**
 * Tests a scenario where the base iterators return data out of range.
 */
@Test
public void testOutOfRange() {
    val testData = createTestData(ITERATOR_COUNT, METADATA_COUNT);
    testData.baseIteratorAttributes.forEach(list -> {
        if (list.size() > 1) {
            val tmp = list.get(0);
            list.set(0, list.get(1));
            list.set(1, tmp);
        }
    });
    // We generate the iterators to include more data than we provide to the mixer.
    AttributeId fromId = testData.sortedAttributeIds.get(1);
    AttributeId toId = testData.sortedAttributeIds.get(testData.sortedAttributeIds.size() - 1);
    val iterator = new SegmentAttributeIterator(testData.getAttributeIterator(fromId, toId), testData.segmentMetadata, fromId, toId);
    AssertExtensions.assertSuppliedFutureThrows("getNext() did not throw when iterators returned data out of range.", () -> iterator.forEachRemaining(CompletableFuture::completedFuture, executorService()), ex -> ex instanceof IllegalArgumentException);
}
Also used : lombok.val(lombok.val) AttributeId(io.pravega.segmentstore.contracts.AttributeId) Test(org.junit.Test)

Example 52 with AttributeId

use of io.pravega.segmentstore.contracts.AttributeId in project pravega by pravega.

the class SegmentAttributeIteratorTests method testNotSorted.

/**
 * Tests a scenario where the base iterators returned attributes out of order.
 */
@Test
public void testNotSorted() {
    val testData = createTestData(ITERATOR_COUNT, METADATA_COUNT);
    testData.baseIteratorAttributes.forEach(list -> {
        if (list.size() > 1) {
            val tmp = list.get(0);
            list.set(0, list.get(1));
            list.set(1, tmp);
        }
    });
    AttributeId fromId = testData.sortedAttributeIds.get(0);
    AttributeId toId = testData.sortedAttributeIds.get(testData.sortedAttributeIds.size() - 1);
    val iterator = new SegmentAttributeIterator(testData.getAttributeIterator(fromId, toId), testData.segmentMetadata, fromId, toId);
    AssertExtensions.assertSuppliedFutureThrows("getNext() did not throw when iterators returned data out of order.", () -> iterator.forEachRemaining(CompletableFuture::completedFuture, executorService()), ex -> ex instanceof IllegalArgumentException);
}
Also used : lombok.val(lombok.val) AttributeId(io.pravega.segmentstore.contracts.AttributeId) Test(org.junit.Test)

Example 53 with AttributeId

use of io.pravega.segmentstore.contracts.AttributeId in project pravega by pravega.

the class ContainerMetadataUpdateTransactionTests method testUpdateAttributesImmutable.

/**
 * Tests the ability of the ContainerMetadataUpdateTransaction to reject UpdateAttributeOperations that attempt to
 * modify immutable Attributes
 */
@Test
public void testUpdateAttributesImmutable() {
    final AttributeId immutableAttribute = Attributes.ATTRIBUTE_SEGMENT_TYPE;
    Assert.assertTrue(Attributes.isUnmodifiable(immutableAttribute));
    UpdateableContainerMetadata metadata = createMetadata();
    val txn = createUpdateTransaction(metadata);
    val coreUpdate = new UpdateAttributesOperation(SEGMENT_ID, AttributeUpdateCollection.from(new AttributeUpdate(immutableAttribute, AttributeUpdateType.Replace, 1L)));
    AssertExtensions.assertThrows("Immutable attribute update succeeded.", () -> txn.preProcessOperation(coreUpdate), ex -> ex instanceof MetadataUpdateException);
}
Also used : lombok.val(lombok.val) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) DynamicAttributeUpdate(io.pravega.segmentstore.contracts.DynamicAttributeUpdate) UpdateAttributesOperation(io.pravega.segmentstore.server.logs.operations.UpdateAttributesOperation) AttributeId(io.pravega.segmentstore.contracts.AttributeId) UpdateableContainerMetadata(io.pravega.segmentstore.server.UpdateableContainerMetadata) Test(org.junit.Test)

Example 54 with AttributeId

use of io.pravega.segmentstore.contracts.AttributeId in project pravega by pravega.

the class ContainerMetadataUpdateTransactionTests method testWithAttributes.

private void testWithAttributes(Function<AttributeUpdateCollection, Operation> createOperation) throws Exception {
    final AttributeId attributeNoUpdate = AttributeId.randomUUID();
    final AttributeId attributeAccumulate = AttributeId.randomUUID();
    final AttributeId attributeReplace = AttributeId.randomUUID();
    final AttributeId attributeReplaceIfGreater = AttributeId.randomUUID();
    final AttributeId attributeReplaceIfEquals = AttributeId.randomUUID();
    UpdateableContainerMetadata metadata = createMetadata();
    val txn = createUpdateTransaction(metadata);
    // Update #1.
    AttributeUpdateCollection attributeUpdates = new AttributeUpdateCollection();
    // Initial add, so it's ok.
    attributeUpdates.add(new AttributeUpdate(attributeNoUpdate, AttributeUpdateType.None, 1));
    attributeUpdates.add(new AttributeUpdate(attributeAccumulate, AttributeUpdateType.Accumulate, 1));
    attributeUpdates.add(new AttributeUpdate(attributeReplace, AttributeUpdateType.Replace, 1));
    attributeUpdates.add(new AttributeUpdate(attributeReplaceIfGreater, AttributeUpdateType.ReplaceIfGreater, 1));
    // Need to initialize to something.
    attributeUpdates.add(new AttributeUpdate(attributeReplaceIfEquals, AttributeUpdateType.Replace, 1));
    val expectedValues = attributeUpdates.stream().collect(Collectors.toMap(AttributeUpdate::getAttributeId, AttributeUpdate::getValue));
    expectedValues.put(Attributes.ATTRIBUTE_SEGMENT_TYPE, DEFAULT_TYPE.getValue());
    Operation op = createOperation.apply(attributeUpdates);
    txn.preProcessOperation(op);
    txn.acceptOperation(op);
    // Verify that the AttributeUpdates still have the same values (there was nothing there prior) and that the updater
    // has internalized the attribute updates.
    verifyAttributeUpdates("after acceptOperation (1)", txn, attributeUpdates, expectedValues);
    // Update #2: update all attributes that can be updated.
    attributeUpdates.clear();
    // 1 + 1 = 2
    attributeUpdates.add(new AttributeUpdate(attributeAccumulate, AttributeUpdateType.Accumulate, 1));
    attributeUpdates.add(new AttributeUpdate(attributeReplace, AttributeUpdateType.Replace, 2));
    attributeUpdates.add(new AttributeUpdate(attributeReplaceIfGreater, AttributeUpdateType.ReplaceIfGreater, 2));
    attributeUpdates.add(new AttributeUpdate(attributeReplaceIfEquals, AttributeUpdateType.ReplaceIfEquals, 2, 1));
    expectedValues.put(attributeAccumulate, 2L);
    expectedValues.put(attributeReplace, 2L);
    expectedValues.put(attributeReplaceIfGreater, 2L);
    expectedValues.put(attributeReplaceIfEquals, 2L);
    op = createOperation.apply(attributeUpdates);
    txn.preProcessOperation(op);
    txn.acceptOperation(op);
    // This is still in the transaction, so we need to add it for comparison sake.
    attributeUpdates.add(new AttributeUpdate(attributeNoUpdate, AttributeUpdateType.None, 1));
    verifyAttributeUpdates("after acceptOperation (2)", txn, attributeUpdates, expectedValues);
    // Update #3: after commit, verify that attributes are committed when they need to.
    val previousAcceptedValues = new HashMap<>(expectedValues);
    txn.commit(metadata);
    attributeUpdates.clear();
    // 2 + 1 = 3
    attributeUpdates.add(new AttributeUpdate(attributeAccumulate, AttributeUpdateType.Accumulate, 1));
    attributeUpdates.add(new AttributeUpdate(attributeReplace, AttributeUpdateType.Replace, 3));
    attributeUpdates.add(new AttributeUpdate(attributeReplaceIfGreater, AttributeUpdateType.ReplaceIfGreater, 3));
    attributeUpdates.add(new AttributeUpdate(attributeReplaceIfEquals, AttributeUpdateType.ReplaceIfEquals, 3, 2));
    expectedValues.put(attributeAccumulate, 3L);
    expectedValues.put(attributeReplace, 3L);
    expectedValues.put(attributeReplaceIfGreater, 3L);
    expectedValues.put(attributeReplaceIfEquals, 3L);
    op = createOperation.apply(attributeUpdates);
    txn.preProcessOperation(op);
    txn.acceptOperation(op);
    SegmentMetadataComparer.assertSameAttributes("Unexpected attributes in segment metadata after commit+acceptOperation, but prior to second commit.", previousAcceptedValues, metadata.getStreamSegmentMetadata(SEGMENT_ID));
    verifyAttributeUpdates("after commit+acceptOperation", txn, attributeUpdates, expectedValues);
    // Final step: commit Append #3, and verify final segment metadata.
    txn.commit(metadata);
    SegmentMetadataComparer.assertSameAttributes("Unexpected attributes in segment metadata after final commit.", expectedValues, metadata.getStreamSegmentMetadata(SEGMENT_ID));
}
Also used : lombok.val(lombok.val) AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) DynamicAttributeUpdate(io.pravega.segmentstore.contracts.DynamicAttributeUpdate) HashMap(java.util.HashMap) AttributeId(io.pravega.segmentstore.contracts.AttributeId) UpdateableContainerMetadata(io.pravega.segmentstore.server.UpdateableContainerMetadata) StorageMetadataCheckpointOperation(io.pravega.segmentstore.server.logs.operations.StorageMetadataCheckpointOperation) MergeSegmentOperation(io.pravega.segmentstore.server.logs.operations.MergeSegmentOperation) Operation(io.pravega.segmentstore.server.logs.operations.Operation) StreamSegmentTruncateOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentTruncateOperation) StreamSegmentMapOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentMapOperation) UpdateAttributesOperation(io.pravega.segmentstore.server.logs.operations.UpdateAttributesOperation) MetadataCheckpointOperation(io.pravega.segmentstore.server.logs.operations.MetadataCheckpointOperation) StorageOperation(io.pravega.segmentstore.server.logs.operations.StorageOperation) StreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation) DeleteSegmentOperation(io.pravega.segmentstore.server.logs.operations.DeleteSegmentOperation) StreamSegmentSealOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentSealOperation)

Aggregations

AttributeId (io.pravega.segmentstore.contracts.AttributeId)54 lombok.val (lombok.val)43 HashMap (java.util.HashMap)38 Test (org.junit.Test)37 CompletableFuture (java.util.concurrent.CompletableFuture)31 AttributeUpdate (io.pravega.segmentstore.contracts.AttributeUpdate)30 Map (java.util.Map)30 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)28 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)28 ArrayList (java.util.ArrayList)28 Collections (java.util.Collections)28 Attributes (io.pravega.segmentstore.contracts.Attributes)27 Collectors (java.util.stream.Collectors)27 Cleanup (lombok.Cleanup)26 ByteArraySegment (io.pravega.common.util.ByteArraySegment)25 AttributeUpdateCollection (io.pravega.segmentstore.contracts.AttributeUpdateCollection)25 StreamSegmentSealedException (io.pravega.segmentstore.contracts.StreamSegmentSealedException)25 UpdateableContainerMetadata (io.pravega.segmentstore.server.UpdateableContainerMetadata)25 Collection (java.util.Collection)25 AtomicLong (java.util.concurrent.atomic.AtomicLong)25