use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class StreamCacheTest method expiration.
@Test
public void expiration() throws Exception {
StreamCache streamCache = new StreamCache(0);
FileInStream is = Mockito.mock(FileInStream.class);
FileOutStream os = Mockito.mock(FileOutStream.class);
streamCache.put(is);
streamCache.put(os);
Mockito.verify(is).close();
Mockito.verify(os).close();
}
use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class BlockServiceHandlerIntegrationTest method lockBlock.
// Tests that lock block returns the correct path
@Test
public void lockBlock() throws Exception {
final int blockSize = (int) WORKER_CAPACITY_BYTES / 2;
CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(blockSize).setWriteType(WriteType.MUST_CACHE);
FileOutStream out = mFileSystem.createFile(new AlluxioURI("/testFile"), options);
URIStatus file = mFileSystem.getStatus(new AlluxioURI("/testFile"));
final long blockId = BlockId.createBlockId(BlockId.getContainerId(file.getFileId()), 0);
out.write(BufferUtils.getIncreasingByteArray(blockSize));
out.close();
String localPath = mBlockWorkerServiceHandler.lockBlock(blockId, SESSION_ID, new LockBlockTOptions()).getBlockPath();
// The local path should exist
Assert.assertNotNull(localPath);
UnderFileSystem ufs = UnderFileSystem.Factory.get(localPath);
byte[] data = new byte[blockSize];
InputStream in = ufs.open(localPath);
int bytesRead = in.read(data);
// The data in the local file should equal the data we wrote earlier
Assert.assertEquals(blockSize, bytesRead);
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(bytesRead, data));
mBlockWorkerServiceHandler.unlockBlock(blockId, SESSION_ID);
}
use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class CapacityUsageIntegrationTest method createAndWriteFile.
private void createAndWriteFile(AlluxioURI filePath, WriteType writeType, int len) throws IOException, AlluxioException {
ByteBuffer buf = ByteBuffer.allocate(len);
buf.order(ByteOrder.nativeOrder());
for (int k = 0; k < len; k++) {
buf.put((byte) k);
}
CreateFileOptions options = CreateFileOptions.defaults().setWriteType(writeType);
FileOutStream os = mFileSystem.createFile(filePath, options);
os.write(buf.array());
os.close();
}
use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class AbstractFileSystem method create.
/**
* Attempts to create a file. Overwrite will not succeed if the path exists and is a folder.
*
* @param path path to create
* @param permission permissions of the created file/folder
* @param overwrite overwrite if file exists
* @param bufferSize the size in bytes of the buffer to be used
* @param replication under filesystem replication factor
* @param blockSize block size in bytes
* @param progress queryable progress
* @return an {@link FSDataOutputStream} created at the indicated path of a file
* @throws IOException if overwrite is not specified and the path already exists or if the path is
* a folder
*/
@Override
public FSDataOutputStream create(Path path, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException {
LOG.debug("create({}, {}, {}, {}, {}, {}, {})", path, permission, overwrite, bufferSize, replication, blockSize, progress);
if (mStatistics != null) {
mStatistics.incrementWriteOps(1);
}
AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(blockSize).setMode(new Mode(permission.toShort()));
FileOutStream outStream;
try {
outStream = mFileSystem.createFile(uri, options);
} catch (AlluxioException e) {
//now we should consider the override parameter
try {
if (mFileSystem.exists(uri)) {
if (!overwrite) {
throw new IOException(ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(uri));
}
if (mFileSystem.getStatus(uri).isFolder()) {
throw new IOException(ExceptionMessage.FILE_CREATE_IS_DIRECTORY.getMessage(uri));
}
mFileSystem.delete(uri);
}
outStream = mFileSystem.createFile(uri, options);
} catch (AlluxioException e2) {
throw new IOException(e2);
}
}
return new FSDataOutputStream(outStream, mStatistics);
}
use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method write.
@Test
public void write() throws Exception {
FileOutStream fos = mock(FileOutStream.class);
AlluxioURI anyURI = any();
when(mFileSystem.createFile(anyURI)).thenReturn(fos);
// open a file
mFileInfo.flags.set(O_WRONLY.intValue());
mFuseFs.create("/foo/bar", 0, mFileInfo);
// prepare something to write into it
Runtime r = Runtime.getSystemRuntime();
Pointer ptr = r.getMemoryManager().allocateTemporary(4, true);
byte[] expected = { 42, -128, 1, 3 };
ptr.put(0, expected, 0, 4);
mFuseFs.write("/foo/bar", ptr, 4, 0, mFileInfo);
verify(fos).write(expected);
}
Aggregations