Search in sources :

Example 11 with OpenFileOptions

use of alluxio.client.file.options.OpenFileOptions in project alluxio by Alluxio.

the class TieredStoreIntegrationTest method deleteWhileRead.

/**
   * Tests that deletes go through despite failing initially due to concurrent read.
   */
@Test
public void deleteWhileRead() throws Exception {
    HeartbeatScheduler.await(HeartbeatContext.WORKER_BLOCK_SYNC, 10, TimeUnit.SECONDS);
    AlluxioURI file = new AlluxioURI("/test1");
    FileSystemTestUtils.createByteFile(mFileSystem, file, WriteType.MUST_CACHE, MEM_CAPACITY_BYTES);
    HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
    Assert.assertEquals(100, mFileSystem.getStatus(file).getInMemoryPercentage());
    // Open the file
    OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.CACHE);
    FileInStream in = mFileSystem.openFile(file, options);
    Assert.assertEquals(0, in.read());
    // Delete the file
    mFileSystem.delete(file);
    HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
    // After the delete, the master should no longer serve the file
    Assert.assertFalse(mFileSystem.exists(file));
    // However, the previous read should still be able to read it as the data still exists
    byte[] res = new byte[MEM_CAPACITY_BYTES];
    Assert.assertEquals(MEM_CAPACITY_BYTES - 1, in.read(res, 1, MEM_CAPACITY_BYTES - 1));
    res[0] = 0;
    Assert.assertTrue(BufferUtils.equalIncreasingByteArray(MEM_CAPACITY_BYTES, res));
    in.close();
    HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
    // After the file is closed, the master's delete should go through and new files can be created
    AlluxioURI newFile = new AlluxioURI("/test2");
    FileSystemTestUtils.createByteFile(mFileSystem, newFile, WriteType.MUST_CACHE, MEM_CAPACITY_BYTES);
    HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
    Assert.assertEquals(100, mFileSystem.getStatus(newFile).getInMemoryPercentage());
}
Also used : FileInStream(alluxio.client.file.FileInStream) OpenFileOptions(alluxio.client.file.options.OpenFileOptions) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 12 with OpenFileOptions

use of alluxio.client.file.options.OpenFileOptions in project alluxio by Alluxio.

the class BaseFileSystemTest method openFile.

/**
   * Tests for the {@link BaseFileSystem#openFile(AlluxioURI, OpenFileOptions)} method to
   * complete successfully.
   */
@Test
public void openFile() throws Exception {
    AlluxioURI file = new AlluxioURI("/file");
    URIStatus status = new URIStatus(new FileInfo());
    Mockito.when(mFileSystemMasterClient.getStatus(file)).thenReturn(status);
    OpenFileOptions openOptions = OpenFileOptions.defaults();
    mFileSystem.openFile(file, openOptions);
    Mockito.verify(mFileSystemMasterClient).getStatus(file);
}
Also used : FileInfo(alluxio.wire.FileInfo) OpenFileOptions(alluxio.client.file.options.OpenFileOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

OpenFileOptions (alluxio.client.file.options.OpenFileOptions)12 FileInStream (alluxio.client.file.FileInStream)9 URIStatus (alluxio.client.file.URIStatus)5 AlluxioURI (alluxio.AlluxioURI)4 Closer (com.google.common.io.Closer)4 IOException (java.io.IOException)3 Test (org.junit.Test)3 FileSystem (alluxio.client.file.FileSystem)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 FileOutStream (alluxio.client.file.FileOutStream)1 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)1 AlluxioException (alluxio.exception.AlluxioException)1 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 FileBlockInfo (alluxio.wire.FileBlockInfo)1 FileInfo (alluxio.wire.FileInfo)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 ServletOutputStream (javax.servlet.ServletOutputStream)1