Search in sources :

Example 46 with CreateFileOptions

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

Example 47 with CreateFileOptions

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

the class LineageMasterIntegrationTest method lineageCompleteAndAsyncPersist.

@Test
public void lineageCompleteAndAsyncPersist() throws Exception {
    try (LineageMasterClient lineageMasterClient = getLineageMasterClient()) {
        ArrayList<String> outFiles = new ArrayList<>();
        Collections.addAll(outFiles, OUT_FILE);
        lineageMasterClient.createLineage(new ArrayList<String>(), outFiles, mJob);
        CreateFileOptions options = CreateFileOptions.defaults().setWriteType(WriteType.MUST_CACHE).setBlockSizeBytes(BLOCK_SIZE_BYTES);
        LineageFileSystem fs = (LineageFileSystem) mLocalAlluxioClusterResource.get().getClient();
        FileOutStream outputStream = fs.createFile(new AlluxioURI(OUT_FILE), options);
        outputStream.write(1);
        outputStream.close();
        List<LineageInfo> infos = lineageMasterClient.getLineageInfoList();
        AlluxioURI uri = new AlluxioURI(infos.get(0).getOutputFiles().get(0));
        URIStatus status = getFileSystemMasterClient().getStatus(uri);
        Assert.assertNotEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
        Assert.assertTrue(status.isCompleted());
        IntegrationTestUtils.waitForPersist(mLocalAlluxioClusterResource, uri);
        // worker notifies the master
        status = getFileSystemMasterClient().getStatus(uri);
        Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) ArrayList(java.util.ArrayList) FileOutStream(alluxio.client.file.FileOutStream) LineageMasterClient(alluxio.client.lineage.LineageMasterClient) LineageFileSystem(alluxio.client.lineage.LineageFileSystem) URIStatus(alluxio.client.file.URIStatus) LineageInfo(alluxio.wire.LineageInfo) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 48 with CreateFileOptions

use of alluxio.client.file.options.CreateFileOptions 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 writeType {@link WriteType} used to create the file
   * @param len file size
   * @throws IOException if {@code path} is invalid (e.g., illegal URI)
   */
public static void createByteFile(FileSystem fs, AlluxioURI fileURI, WriteType writeType, int len) throws IOException {
    CreateFileOptions options = CreateFileOptions.defaults().setWriteType(writeType);
    createByteFile(fs, fileURI, options, len);
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions)

Example 49 with CreateFileOptions

use of alluxio.client.file.options.CreateFileOptions 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 fileName the name of the file to be created
   * @param writeType {@link WriteType} used to create the file
   * @param len file size
   * @param blockCapacityByte block size of the file
   * @throws IOException if {@code path} is invalid (e.g., illegal URI)
   */
public static void createByteFile(FileSystem fs, String fileName, WriteType writeType, int len, long blockCapacityByte) throws IOException {
    CreateFileOptions options = CreateFileOptions.defaults().setWriteType(writeType).setBlockSizeBytes(blockCapacityByte);
    createByteFile(fs, new AlluxioURI(fileName), options, len);
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) AlluxioURI(alluxio.AlluxioURI)

Example 50 with CreateFileOptions

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

the class LineageFileSystemTest method getNonLineageStream.

/**
   * Tests that a {@link FileOutStream} is returned.
   */
@Test
public void getNonLineageStream() throws Exception {
    AlluxioURI path = new AlluxioURI("test");
    Mockito.when(mLineageMasterClient.reinitializeFile("test", TEST_BLOCK_SIZE, 0, TtlAction.DELETE)).thenThrow(new LineageDoesNotExistException("lineage does not exist"));
    CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(TEST_BLOCK_SIZE).setTtl(0);
    FileOutStream outStream = mAlluxioLineageFileSystem.createFile(path, options);
    Assert.assertTrue(outStream != null);
    Assert.assertFalse(outStream instanceof LineageFileOutStream);
    Assert.assertFalse(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) LineageDoesNotExistException(alluxio.exception.LineageDoesNotExistException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

CreateFileOptions (alluxio.client.file.options.CreateFileOptions)57 AlluxioURI (alluxio.AlluxioURI)51 Test (org.junit.Test)45 FileInStream (alluxio.client.file.FileInStream)21 FileOutStream (alluxio.client.file.FileOutStream)16 URIStatus (alluxio.client.file.URIStatus)11 HashMap (java.util.HashMap)5 CreateDirectoryOptions (alluxio.client.file.options.CreateDirectoryOptions)4 BeforeClass (org.junit.BeforeClass)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 AlluxioException (alluxio.exception.AlluxioException)2 UnderFileSystem (alluxio.underfs.UnderFileSystem)2 IOException (java.io.IOException)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 DeleteOptions (alluxio.client.file.options.DeleteOptions)1 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)1 SetAttributeOptions (alluxio.client.file.options.SetAttributeOptions)1 LineageFileSystem (alluxio.client.lineage.LineageFileSystem)1 LineageMasterClient (alluxio.client.lineage.LineageMasterClient)1