Search in sources :

Example 1 with StreamSegmentMetadata

use of io.pravega.segmentstore.server.containers.StreamSegmentMetadata in project pravega by pravega.

the class ContainerMetadataUpdateTransaction method createSegmentMetadata.

/**
 * Creates a new UpdateableSegmentMetadata for the given Segment and registers it.
 */
private UpdateableSegmentMetadata createSegmentMetadata(String segmentName, long segmentId, long parentId) {
    UpdateableSegmentMetadata metadata;
    if (parentId == ContainerMetadata.NO_STREAM_SEGMENT_ID) {
        metadata = new StreamSegmentMetadata(segmentName, segmentId, this.containerId);
    } else {
        metadata = new StreamSegmentMetadata(segmentName, segmentId, parentId, this.containerId);
    }
    this.newSegments.put(metadata.getId(), metadata);
    this.newSegmentNames.put(metadata.getName(), metadata.getId());
    return metadata;
}
Also used : UpdateableSegmentMetadata(io.pravega.segmentstore.server.UpdateableSegmentMetadata) StreamSegmentMetadata(io.pravega.segmentstore.server.containers.StreamSegmentMetadata)

Example 2 with StreamSegmentMetadata

use of io.pravega.segmentstore.server.containers.StreamSegmentMetadata in project pravega by pravega.

the class StorageReadManagerTests method testInvalidRequests.

/**
 * Tests the execute method with invalid Requests.
 * * StreamSegment does not exist
 * * Invalid read offset
 * * Too long of a read (offset+length is beyond the Segment's length)
 */
@Test
public void testInvalidRequests() {
    @Cleanup Storage storage = InMemoryStorageFactory.newStorage(executorService());
    storage.initialize(1);
    byte[] segmentData = populateSegment(storage);
    @Cleanup StorageReadManager reader = new StorageReadManager(SEGMENT_METADATA, storage, executorService());
    // Segment does not exist.
    AssertExtensions.assertThrows("Request was not failed when StreamSegment does not exist.", () -> {
        SegmentMetadata sm = new StreamSegmentMetadata("foo", 0, 0);
        @Cleanup StorageReadManager nonExistentReader = new StorageReadManager(sm, storage, executorService());
        sendRequest(nonExistentReader, 0, 1).join();
    }, ex -> ex instanceof StreamSegmentNotExistsException);
    // Invalid read offset.
    AssertExtensions.assertThrows("Request was not failed when bad offset was provided.", () -> sendRequest(reader, segmentData.length + 1, 1), ex -> ex instanceof ArrayIndexOutOfBoundsException);
    // Invalid read length.
    AssertExtensions.assertThrows("Request was not failed when bad offset + length was provided.", () -> sendRequest(reader, segmentData.length - 1, 2), ex -> ex instanceof ArrayIndexOutOfBoundsException);
}
Also used : SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) StreamSegmentMetadata(io.pravega.segmentstore.server.containers.StreamSegmentMetadata) Storage(io.pravega.segmentstore.storage.Storage) ReadOnlyStorage(io.pravega.segmentstore.storage.ReadOnlyStorage) InMemoryStorage(io.pravega.segmentstore.storage.mocks.InMemoryStorage) StreamSegmentMetadata(io.pravega.segmentstore.server.containers.StreamSegmentMetadata) Cleanup(lombok.Cleanup) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) Test(org.junit.Test)

Aggregations

StreamSegmentMetadata (io.pravega.segmentstore.server.containers.StreamSegmentMetadata)2 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)1 SegmentMetadata (io.pravega.segmentstore.server.SegmentMetadata)1 UpdateableSegmentMetadata (io.pravega.segmentstore.server.UpdateableSegmentMetadata)1 ReadOnlyStorage (io.pravega.segmentstore.storage.ReadOnlyStorage)1 Storage (io.pravega.segmentstore.storage.Storage)1 InMemoryStorage (io.pravega.segmentstore.storage.mocks.InMemoryStorage)1 Cleanup (lombok.Cleanup)1 Test (org.junit.Test)1