use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class FileOutStreamIntegrationTest method writeSpecifyLocal.
/**
* Tests writing to a file and specify the location to be localhost.
*/
@Test
public void writeSpecifyLocal() throws Exception {
AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
final int length = 2;
try (FileOutStream os = mFileSystem.createFile(filePath, CreateFileOptions.defaults().setWriteType(mWriteType).setLocationPolicy(new LocalFirstPolicy()))) {
os.write((byte) 0);
os.write((byte) 1);
}
if (mWriteType.getAlluxioStorageType().isStore()) {
checkFileInAlluxio(filePath, length);
}
if (mWriteType.getUnderStorageType().isSyncPersist()) {
checkFileInUnderStorage(filePath, length);
}
}
use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class FileSystemTestUtils method createByteFile.
/**
* Creates a simple file with {@code len} bytes.
*
* @param fs a {@link FileSystem} handler
* @param fileURI URI of the file
* @param options client options to create the file with
* @param len file size
* @throws IOException if {@code path} is invalid (e.g., illegal URI)
*/
public static void createByteFile(FileSystem fs, AlluxioURI fileURI, CreateFileOptions options, int len) throws IOException {
try (FileOutStream os = fs.createFile(fileURI, options)) {
byte[] arr = new byte[len];
for (int k = 0; k < len; k++) {
arr[k] = (byte) k;
}
os.write(arr);
} catch (AlluxioException e) {
throw new IOException(e.getMessage());
}
}
use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class LineageFileSystemTest method getDummyOutStream.
/**
* Tests that a {@link DummyFileOutputStream} is returned.
*/
@Test
public void getDummyOutStream() throws Exception {
AlluxioURI path = new AlluxioURI("test");
Mockito.when(mLineageMasterClient.reinitializeFile("test", TEST_BLOCK_SIZE, 0, TtlAction.DELETE)).thenReturn(-1L);
CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(TEST_BLOCK_SIZE).setTtl(0);
FileOutStream outStream = mAlluxioLineageFileSystem.createFile(path, options);
Assert.assertTrue(outStream instanceof DummyFileOutputStream);
// verify client is released
Mockito.verify(mLineageContext).releaseMasterClient(mLineageMasterClient);
}
use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class LineageFileSystemTest method getLineageOutStream.
/**
* Tests that a {@link LineageFileOutStream} is returned.
*/
@Test
public void getLineageOutStream() throws Exception {
AlluxioURI path = new AlluxioURI("test");
Mockito.when(mLineageMasterClient.reinitializeFile("test", TEST_BLOCK_SIZE, 0, TtlAction.FREE)).thenReturn(1L);
CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(TEST_BLOCK_SIZE).setTtl(0).setTtlAction(alluxio.wire.TtlAction.FREE);
FileOutStream outStream = mAlluxioLineageFileSystem.createFile(path, options);
Assert.assertTrue(outStream instanceof LineageFileOutStream);
// verify client is released
Mockito.verify(mLineageContext).releaseMasterClient(mLineageMasterClient);
}
use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class PinIntegrationTest method createEmptyFile.
private void createEmptyFile(AlluxioURI fileURI) throws IOException, AlluxioException {
CreateFileOptions options = CreateFileOptions.defaults().setWriteType(WriteType.MUST_CACHE);
FileOutStream os = mFileSystem.createFile(fileURI, options);
os.close();
}
Aggregations