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;
}
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);
}
Aggregations