Search in sources :

Example 1 with FuseFileInfo

use of alluxio.jnifuse.struct.FuseFileInfo in project alluxio by Alluxio.

the class JNIFuseIntegrationTest method openReadWriteExisting.

/**
 * Tests opening file with O_RDWR on existing file for read-only workloads.
 */
@Test
public void openReadWriteExisting() throws Exception {
    String testFile = "/openReadWriteExisting";
    try (CloseableFuseFileInfo closeableFuseFileInfo = new CloseableFuseFileInfo()) {
        FuseFileInfo info = closeableFuseFileInfo.getFuseFileInfo();
        createTestFile(testFile, info, FILE_LEN);
        info.flags.set(OpenFlags.O_RDWR.intValue());
        Assert.assertEquals(0, mFuseFileSystem.open(testFile, info));
        try {
            ByteBuffer buffer = ByteBuffer.wrap(new byte[FILE_LEN]);
            Assert.assertEquals(FILE_LEN, mFuseFileSystem.read(testFile, buffer, FILE_LEN, 0, info));
            Assert.assertTrue(BufferUtils.equalIncreasingByteArray(FILE_LEN, buffer.array()));
            Assert.assertTrue(mFuseFileSystem.write(testFile, buffer, FILE_LEN, 0, info) < 0);
        } finally {
            Assert.assertEquals(0, mFuseFileSystem.release(testFile, info));
        }
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) FuseFileInfo(alluxio.jnifuse.struct.FuseFileInfo) Test(org.junit.Test)

Example 2 with FuseFileInfo

use of alluxio.jnifuse.struct.FuseFileInfo in project alluxio by Alluxio.

the class JNIFuseIntegrationTest method openWriteExistingWithTruncateZero.

/**
 * Tests opening a file with O_WRONLY and then truncating it to zero
 * length for writing.
 */
@Test
public void openWriteExistingWithTruncateZero() throws Exception {
    String testFile = "/openWriteExistingWithTruncateZero";
    try (CloseableFuseFileInfo closeableFuseFileInfo = new CloseableFuseFileInfo()) {
        FuseFileInfo info = closeableFuseFileInfo.getFuseFileInfo();
        createTestFile(testFile, info, FILE_LEN / 2);
        info.flags.set(OpenFlags.O_WRONLY.intValue());
        try {
            Assert.assertEquals(0, mFuseFileSystem.open(testFile, info));
            Assert.assertEquals(0, mFuseFileSystem.truncate(testFile, 0));
            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);
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) FuseFileInfo(alluxio.jnifuse.struct.FuseFileInfo) Test(org.junit.Test)

Example 3 with FuseFileInfo

use of alluxio.jnifuse.struct.FuseFileInfo in project alluxio by Alluxio.

the class JNIFuseIntegrationTest method openReadWriteNonExisting.

/**
 * Tests opening file with O_RDWR on non-existing file for write-only workloads.
 */
@Test
public void openReadWriteNonExisting() throws Exception {
    String testFile = "/openReadWriteNonExistingFile";
    try (CloseableFuseFileInfo closeableFuseFileInfo = new CloseableFuseFileInfo()) {
        FuseFileInfo info = closeableFuseFileInfo.getFuseFileInfo();
        info.flags.set(OpenFlags.O_RDWR.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);
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) FuseFileInfo(alluxio.jnifuse.struct.FuseFileInfo) Test(org.junit.Test)

Example 4 with FuseFileInfo

use of alluxio.jnifuse.struct.FuseFileInfo in project alluxio by Alluxio.

the class JNIFuseIntegrationTest method openWriteNonExisting.

/**
 * Tests opening a file with O_WRONLY flag on non-existing file.
 */
@Test
public void openWriteNonExisting() throws Exception {
    String testFile = "/openWriteNonExisting";
    try (CloseableFuseFileInfo closeableFuseFileInfo = new CloseableFuseFileInfo()) {
        FuseFileInfo info = closeableFuseFileInfo.getFuseFileInfo();
        info.flags.set(OpenFlags.O_WRONLY.intValue());
        Assert.assertEquals(0, mFuseFileSystem.open(testFile, info));
        ByteBuffer buffer = BufferUtils.getIncreasingByteBuffer(FILE_LEN);
        try {
            Assert.assertEquals(FILE_LEN, mFuseFileSystem.write(testFile, buffer, FILE_LEN, 0, info));
        } finally {
            Assert.assertEquals(0, mFuseFileSystem.release(testFile, info));
        }
        readAndValidateTestFile(testFile, info, FILE_LEN);
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) FuseFileInfo(alluxio.jnifuse.struct.FuseFileInfo) Test(org.junit.Test)

Example 5 with FuseFileInfo

use of alluxio.jnifuse.struct.FuseFileInfo in project alluxio by Alluxio.

the class JNIFuseIntegrationTest method openWriteExistingWithoutTruncFlag.

/**
 * Tests opening a file with O_WRONLY on existing file without O_TRUNC.
 */
@Test
public void openWriteExistingWithoutTruncFlag() throws Exception {
    String testFile = "/openWriteExistingWithoutTruncFlag";
    try (CloseableFuseFileInfo closeableFuseFileInfo = new CloseableFuseFileInfo()) {
        FuseFileInfo info = closeableFuseFileInfo.getFuseFileInfo();
        createTestFile(testFile, info, FILE_LEN);
        info.flags.set(OpenFlags.O_WRONLY.intValue());
        try {
            Assert.assertEquals(0, mFuseFileSystem.open(testFile, info));
            ByteBuffer buffer = BufferUtils.getIncreasingByteBuffer(FILE_LEN);
            // O_WRONLY without O_TRUNC cannot overwrite
            Assert.assertTrue(mFuseFileSystem.write(testFile, buffer, FILE_LEN, 0, info) < 0);
        } finally {
            mFuseFileSystem.release(testFile, info);
        }
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) FuseFileInfo(alluxio.jnifuse.struct.FuseFileInfo) Test(org.junit.Test)

Aggregations

FuseFileInfo (alluxio.jnifuse.struct.FuseFileInfo)9 Test (org.junit.Test)9 ByteBuffer (java.nio.ByteBuffer)8