use of alluxio.client.file.options.OutStreamOptions in project alluxio by Alluxio.
the class BaseFileSystem method createFile.
@Override
public FileOutStream createFile(AlluxioURI path, CreateFileOptions options) throws FileAlreadyExistsException, InvalidPathException, IOException, AlluxioException {
FileSystemMasterClient masterClient = mFileSystemContext.acquireMasterClient();
URIStatus status;
try {
masterClient.createFile(path, options);
status = masterClient.getStatus(path);
LOG.debug("Created file " + path.getPath());
} finally {
mFileSystemContext.releaseMasterClient(masterClient);
}
OutStreamOptions outStreamOptions = options.toOutStreamOptions();
outStreamOptions.setUfsPath(status.getUfsPath());
return new FileOutStream(mFileSystemContext, path, outStreamOptions);
}
use of alluxio.client.file.options.OutStreamOptions in project alluxio by Alluxio.
the class AlluxioBlockStoreTest method getOutStreamMissingLocationPolicy.
@Test
public void getOutStreamMissingLocationPolicy() throws IOException {
OutStreamOptions options = OutStreamOptions.defaults().setBlockSizeBytes(BLOCK_LENGTH).setWriteType(WriteType.MUST_CACHE).setLocationPolicy(null);
try {
mBlockStore.getOutStream(BLOCK_ID, BLOCK_LENGTH, options);
Assert.fail("missing location policy should fail");
} catch (NullPointerException e) {
Assert.assertEquals(PreconditionMessage.FILE_WRITE_LOCATION_POLICY_UNSPECIFIED.toString(), e.getMessage());
}
}
use of alluxio.client.file.options.OutStreamOptions in project alluxio by Alluxio.
the class AlluxioBlockStoreTest method getOutStreamRemote.
@Test
public void getOutStreamRemote() throws Exception {
OutStreamOptions options = OutStreamOptions.defaults().setBlockSizeBytes(BLOCK_LENGTH).setLocationPolicy(new MockFileWriteLocationPolicy(Lists.newArrayList(WORKER_NET_ADDRESS_REMOTE))).setWriteType(WriteType.MUST_CACHE);
OutputStream stream = mBlockStore.getOutStream(BLOCK_ID, BLOCK_LENGTH, options);
if (Configuration.getBoolean(PropertyKey.USER_PACKET_STREAMING_ENABLED)) {
Assert.assertEquals(alluxio.client.block.stream.BlockOutStream.class, stream.getClass());
} else {
Assert.assertEquals(RemoteBlockOutStream.class, stream.getClass());
}
}
use of alluxio.client.file.options.OutStreamOptions in project alluxio by Alluxio.
the class FileOutStreamTest method getBytesWrittenWithDifferentUnderStorageType.
/**
* Tests that the number of bytes written is correct when the stream is created with different
* under storage types.
*/
@Test
public void getBytesWrittenWithDifferentUnderStorageType() throws IOException {
for (WriteType type : WriteType.values()) {
OutStreamOptions options = OutStreamOptions.defaults().setBlockSizeBytes(BLOCK_LENGTH).setWriteType(type).setUfsPath(FILE_NAME.getPath());
mTestStream = createTestStream(FILE_NAME, options);
mTestStream.write(BufferUtils.getIncreasingByteArray((int) BLOCK_LENGTH));
mTestStream.flush();
Assert.assertEquals(BLOCK_LENGTH, mTestStream.getBytesWritten());
}
}
use of alluxio.client.file.options.OutStreamOptions in project alluxio by Alluxio.
the class FileOutStreamTest method cancelWithoutDelegation.
/**
* Tests that {@link FileOutStream#cancel()} will cancel and close the underlying out streams, and
* delete from the under file system when the delegation flag is not set. Also makes sure that
* cancel() doesn't persist or complete the file.
*/
@Test
public void cancelWithoutDelegation() throws Exception {
Configuration.set(PropertyKey.USER_UFS_DELEGATION_ENABLED, false);
OutStreamOptions options = OutStreamOptions.defaults().setBlockSizeBytes(BLOCK_LENGTH).setWriteType(WriteType.CACHE_THROUGH).setUfsPath(FILE_NAME.getPath());
mTestStream = createTestStream(FILE_NAME, options);
mTestStream.write(BufferUtils.getIncreasingByteArray((int) (BLOCK_LENGTH * 1.5)));
mTestStream.cancel();
for (long streamIndex = 0; streamIndex < 2; streamIndex++) {
Assert.assertTrue(mAlluxioOutStreamMap.get(streamIndex).isClosed());
Assert.assertTrue(mAlluxioOutStreamMap.get(streamIndex).isCanceled());
}
// Don't persist or complete the file if the stream was canceled
verify(mFileSystemMasterClient, times(0)).completeFile(FILE_NAME, CompleteFileOptions.defaults());
verify(mUnderFileSystem).deleteFile(anyString());
}
Aggregations