use of alluxio.jnifuse.struct.FuseFileInfo in project alluxio by Alluxio.
the class JNIFuseIntegrationTest method openReadWriteTruncateZeroExisting.
/**
* Tests opening file with O_RDWR flag on existing file for read-only workloads first,
* if truncate(0) is call, change to write-only workloads.
*/
@Test
public void openReadWriteTruncateZeroExisting() throws Exception {
String testFile = "/openReadWriteTruncateZeroExisting";
try (CloseableFuseFileInfo closeableFuseFileInfo = new CloseableFuseFileInfo()) {
FuseFileInfo info = closeableFuseFileInfo.getFuseFileInfo();
createTestFile(testFile, info, FILE_LEN / 2);
info.flags.set(OpenFlags.O_RDWR.intValue());
Assert.assertEquals(0, mFuseFileSystem.open(testFile, info));
try {
// read-only first
ByteBuffer buffer = ByteBuffer.wrap(new byte[FILE_LEN / 2]);
Assert.assertEquals(FILE_LEN / 2, mFuseFileSystem.read(testFile, buffer, FILE_LEN / 2, 0, info));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(FILE_LEN / 2, buffer.array()));
// delete existing file and transfer to write-only
Assert.assertEquals(0, mFuseFileSystem.truncate(testFile, 0));
buffer = BufferUtils.getIncreasingByteBuffer(FILE_LEN);
Assert.assertEquals(FILE_LEN, mFuseFileSystem.write(testFile, buffer, FILE_LEN, 0, info));
buffer.clear();
// read will error out after write-only
Assert.assertTrue(mFuseFileSystem.read(testFile, buffer, FILE_LEN, 0, info) < 0);
} finally {
Assert.assertEquals(0, mFuseFileSystem.release(testFile, info));
}
readAndValidateTestFile(testFile, info, FILE_LEN);
}
}
use of alluxio.jnifuse.struct.FuseFileInfo in project alluxio by Alluxio.
the class JNIFuseIntegrationTest method openWriteExistingWithTruncFlag.
/**
* Tests opening a file with O_WRONLY and O_TRUNC flags to overwrite existing file.
*/
@Test
public void openWriteExistingWithTruncFlag() throws Exception {
String testFile = "/openWriteExistingWithTruncFlag";
try (CloseableFuseFileInfo closeableFuseFileInfo = new CloseableFuseFileInfo()) {
FuseFileInfo info = closeableFuseFileInfo.getFuseFileInfo();
createTestFile(testFile, info, FILE_LEN / 2);
info.flags.set(OpenFlags.O_WRONLY.intValue() | OpenFlags.O_TRUNC.intValue());
try {
Assert.assertEquals(0, mFuseFileSystem.open(testFile, info));
ByteBuffer buffer = BufferUtils.getIncreasingByteBuffer(FILE_LEN);
Assert.assertEquals(FILE_LEN, mFuseFileSystem.write(testFile, buffer, FILE_LEN, 0, info));
} finally {
mFuseFileSystem.release(testFile, info);
}
readAndValidateTestFile(testFile, info, FILE_LEN);
}
}
use of alluxio.jnifuse.struct.FuseFileInfo in project alluxio by Alluxio.
the class JNIFuseIntegrationTest method createWriteOpenRead.
/**
* Tests creating a file for writing
* and opening a file for O_RDONLY read-only open flag.
*/
@Test
public void createWriteOpenRead() throws Exception {
String testFile = "/createWriteOpenReadTestFile";
try (CloseableFuseFileInfo info = new CloseableFuseFileInfo()) {
FuseFileInfo fuseFileInfo = info.getFuseFileInfo();
// cannot open non-existing file for read
fuseFileInfo.flags.set(OpenFlags.O_RDONLY.intValue());
Assert.assertNotEquals(0, mFuseFileSystem.open(testFile, fuseFileInfo));
// open existing file for read
createTestFile(testFile, fuseFileInfo, FILE_LEN);
readAndValidateTestFile(testFile, fuseFileInfo, FILE_LEN);
}
}
use of alluxio.jnifuse.struct.FuseFileInfo in project alluxio by Alluxio.
the class JNIFuseIntegrationTest method openReadWriteTruncExisting.
/**
* Tests opening file with O_RDWR and O_TRUNC flags on existing file
* for write-only workloads.
*/
@Test
public void openReadWriteTruncExisting() throws Exception {
String testFile = "/openReadWriteTruncExisting";
try (CloseableFuseFileInfo closeableFuseFileInfo = new CloseableFuseFileInfo()) {
FuseFileInfo info = closeableFuseFileInfo.getFuseFileInfo();
createTestFile(testFile, info, FILE_LEN / 2);
info.flags.set(OpenFlags.O_RDWR.intValue() | OpenFlags.O_TRUNC.intValue());
Assert.assertEquals(0, mFuseFileSystem.open(testFile, info));
try {
ByteBuffer buffer = BufferUtils.getIncreasingByteBuffer(FILE_LEN);
Assert.assertEquals(FILE_LEN, mFuseFileSystem.write(testFile, buffer, FILE_LEN, 0, info));
buffer.clear();
Assert.assertTrue(mFuseFileSystem.read(testFile, buffer, FILE_LEN, 0, info) < 0);
} finally {
Assert.assertEquals(0, mFuseFileSystem.release(testFile, info));
}
readAndValidateTestFile(testFile, info, FILE_LEN);
}
}
Aggregations