use of io.pravega.segmentstore.storage.chunklayer.ChunkStorageException in project pravega by pravega.
the class HDFSChunkStorageMockTest method testGetUsedException.
@Test
public void testGetUsedException() throws Exception {
val mockFs = spy(FileSystem.get(new Configuration()));
HDFSChunkStorage storage = new MockHDFSChunkStorage(storageConfig, executorService(), mockFs);
storage.initialize();
doThrow(new IOException("Intentional")).when(mockFs).getUsed();
AssertExtensions.assertFutureThrows("should throw ChunkStorageFull exception", storage.getUsedSpace(), ex -> ex instanceof ChunkStorageException);
}
use of io.pravega.segmentstore.storage.chunklayer.ChunkStorageException in project pravega by pravega.
the class S3ChunkStorage method convertException.
private ChunkStorageException convertException(String chunkName, String message, Exception e) {
ChunkStorageException retValue = null;
if (e instanceof ChunkStorageException) {
return (ChunkStorageException) e;
}
if (e instanceof S3Exception) {
S3Exception s3Exception = (S3Exception) e;
String errorCode = Strings.nullToEmpty(s3Exception.awsErrorDetails().errorCode());
if (errorCode.equals(NO_SUCH_KEY)) {
retValue = new ChunkNotFoundException(chunkName, message, e);
}
if (errorCode.equals(PRECONDITION_FAILED)) {
retValue = new ChunkAlreadyExistsException(chunkName, message, e);
}
if (errorCode.equals(INVALID_RANGE) || errorCode.equals(INVALID_ARGUMENT) || errorCode.equals(METHOD_NOT_ALLOWED) || s3Exception.awsErrorDetails().sdkHttpResponse().statusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
throw new IllegalArgumentException(chunkName, e);
}
if (errorCode.equals(ACCESS_DENIED)) {
retValue = new ChunkStorageException(chunkName, String.format("Access denied for chunk %s - %s.", chunkName, message), e);
}
}
if (retValue == null) {
retValue = new ChunkStorageException(chunkName, message, e);
}
return retValue;
}
use of io.pravega.segmentstore.storage.chunklayer.ChunkStorageException in project pravega by pravega.
the class S3ChunkStorage method doCreateWithContent.
@Override
protected ChunkHandle doCreateWithContent(String chunkName, int length, InputStream data) throws ChunkStorageException {
try {
val objectPath = getObjectPath(chunkName);
Map<String, String> metadata = new HashMap<>();
metadata.put("Content-Type", "application/octet-stream");
metadata.put("Content-Length", Integer.toString(length));
val request = PutObjectRequest.builder().bucket(this.config.getBucket()).key(objectPath).metadata(metadata).build();
client.putObject(request, RequestBody.fromInputStream(data, length));
return ChunkHandle.writeHandle(chunkName);
} catch (Exception e) {
throw convertException(chunkName, "doCreateWithContent", e);
}
}
use of io.pravega.segmentstore.storage.chunklayer.ChunkStorageException in project pravega by pravega.
the class FileSystemChunkStorageMockTest method testWithNonRegularFile.
@Test
public void testWithNonRegularFile() throws Exception {
String chunkName = "test";
FileChannel channel = mock(FileChannel.class);
fixChannelMock(channel);
FileSystemWrapper fileSystemWrapper = mock(FileSystemWrapper.class);
when(fileSystemWrapper.exists(any())).thenReturn(true);
when(fileSystemWrapper.isRegularFile(any())).thenReturn(false);
@Cleanup FileSystemChunkStorage testStorage = new FileSystemChunkStorage(storageConfig, fileSystemWrapper, executorService());
AssertExtensions.assertFutureThrows(" openRead should throw ChunkStorageException.", testStorage.openRead(chunkName), ex -> ex instanceof ChunkStorageException && ex.getMessage().contains("chunk is not a regular file"));
AssertExtensions.assertFutureThrows(" openRead should throw ChunkStorageException.", testStorage.openWrite(chunkName), ex -> ex instanceof ChunkStorageException && ex.getMessage().contains("chunk is not a regular file"));
}
use of io.pravega.segmentstore.storage.chunklayer.ChunkStorageException in project pravega by pravega.
the class FileSystemChunkStorageMockTest method testGetUsageException.
@Test
public void testGetUsageException() {
val fs = spy(new FileSystemWrapper(CACHE_SIZE, CACHE_SIZE, CACHE_EXP, CACHE_EXP));
doThrow(new RuntimeException("Intentional")).when(fs).getUsedSpace(any());
FileSystemChunkStorage storage = new FileSystemChunkStorage(storageConfig, fs, executorService());
AssertExtensions.assertFutureThrows("should throw ChunkStorageException exception", storage.getUsedSpace(), ex -> ex instanceof ChunkStorageException);
}
Aggregations