Search in sources :

Example 16 with FileOutStream

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);
    }
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) LocalFirstPolicy(alluxio.client.file.policy.LocalFirstPolicy) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 17 with FileOutStream

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());
    }
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException)

Example 18 with FileOutStream

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);
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileOutStream(alluxio.client.file.FileOutStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with FileOutStream

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);
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileOutStream(alluxio.client.file.FileOutStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 20 with FileOutStream

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();
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileOutStream(alluxio.client.file.FileOutStream)

Aggregations

FileOutStream (alluxio.client.file.FileOutStream)39 AlluxioURI (alluxio.AlluxioURI)28 Test (org.junit.Test)25 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)11 FileInStream (alluxio.client.file.FileInStream)9 URIStatus (alluxio.client.file.URIStatus)9 AlluxioException (alluxio.exception.AlluxioException)5 IOException (java.io.IOException)5 FileSystem (alluxio.client.file.FileSystem)4 ByteBuffer (java.nio.ByteBuffer)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 LocalFirstPolicy (alluxio.client.file.policy.LocalFirstPolicy)2 LineageFileSystem (alluxio.client.lineage.LineageFileSystem)2 LineageMasterClient (alluxio.client.lineage.LineageMasterClient)2 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)2 Closer (com.google.common.io.Closer)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ExpectedException (org.junit.rules.ExpectedException)2 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)1