Search in sources :

Example 6 with OutStreamOptions

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

the class BaseFileSystem method createFile.

@Override
public FileOutStream createFile(AlluxioURI path, CreateFileOptions options) throws FileAlreadyExistsException, InvalidPathException, IOException, AlluxioException {
    FileSystemMasterClient masterClient = mFileSystemContext.acquireMasterClient();
    URIStatus status;
    try {
        masterClient.createFile(path, options);
        status = masterClient.getStatus(path);
        LOG.debug("Created file " + path.getPath());
    } finally {
        mFileSystemContext.releaseMasterClient(masterClient);
    }
    OutStreamOptions outStreamOptions = options.toOutStreamOptions();
    outStreamOptions.setUfsPath(status.getUfsPath());
    return new FileOutStream(mFileSystemContext, path, outStreamOptions);
}
Also used : OutStreamOptions(alluxio.client.file.options.OutStreamOptions)

Example 7 with OutStreamOptions

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

the class AlluxioBlockStoreTest method getOutStreamMissingLocationPolicy.

@Test
public void getOutStreamMissingLocationPolicy() throws IOException {
    OutStreamOptions options = OutStreamOptions.defaults().setBlockSizeBytes(BLOCK_LENGTH).setWriteType(WriteType.MUST_CACHE).setLocationPolicy(null);
    try {
        mBlockStore.getOutStream(BLOCK_ID, BLOCK_LENGTH, options);
        Assert.fail("missing location policy should fail");
    } catch (NullPointerException e) {
        Assert.assertEquals(PreconditionMessage.FILE_WRITE_LOCATION_POLICY_UNSPECIFIED.toString(), e.getMessage());
    }
}
Also used : OutStreamOptions(alluxio.client.file.options.OutStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with OutStreamOptions

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

the class AlluxioBlockStoreTest method getOutStreamRemote.

@Test
public void getOutStreamRemote() throws Exception {
    OutStreamOptions options = OutStreamOptions.defaults().setBlockSizeBytes(BLOCK_LENGTH).setLocationPolicy(new MockFileWriteLocationPolicy(Lists.newArrayList(WORKER_NET_ADDRESS_REMOTE))).setWriteType(WriteType.MUST_CACHE);
    OutputStream stream = mBlockStore.getOutStream(BLOCK_ID, BLOCK_LENGTH, options);
    if (Configuration.getBoolean(PropertyKey.USER_PACKET_STREAMING_ENABLED)) {
        Assert.assertEquals(alluxio.client.block.stream.BlockOutStream.class, stream.getClass());
    } else {
        Assert.assertEquals(RemoteBlockOutStream.class, stream.getClass());
    }
}
Also used : OutStreamOptions(alluxio.client.file.options.OutStreamOptions) OutputStream(java.io.OutputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with OutStreamOptions

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

the class FileOutStreamTest method getBytesWrittenWithDifferentUnderStorageType.

/**
   * Tests that the number of bytes written is correct when the stream is created with different
   * under storage types.
   */
@Test
public void getBytesWrittenWithDifferentUnderStorageType() throws IOException {
    for (WriteType type : WriteType.values()) {
        OutStreamOptions options = OutStreamOptions.defaults().setBlockSizeBytes(BLOCK_LENGTH).setWriteType(type).setUfsPath(FILE_NAME.getPath());
        mTestStream = createTestStream(FILE_NAME, options);
        mTestStream.write(BufferUtils.getIncreasingByteArray((int) BLOCK_LENGTH));
        mTestStream.flush();
        Assert.assertEquals(BLOCK_LENGTH, mTestStream.getBytesWritten());
    }
}
Also used : OutStreamOptions(alluxio.client.file.options.OutStreamOptions) WriteType(alluxio.client.WriteType) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with OutStreamOptions

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

the class FileOutStreamTest method cancelWithoutDelegation.

/**
   * Tests that {@link FileOutStream#cancel()} will cancel and close the underlying out streams, and
   * delete from the under file system when the delegation flag is not set. Also makes sure that
   * cancel() doesn't persist or complete the file.
   */
@Test
public void cancelWithoutDelegation() throws Exception {
    Configuration.set(PropertyKey.USER_UFS_DELEGATION_ENABLED, false);
    OutStreamOptions options = OutStreamOptions.defaults().setBlockSizeBytes(BLOCK_LENGTH).setWriteType(WriteType.CACHE_THROUGH).setUfsPath(FILE_NAME.getPath());
    mTestStream = createTestStream(FILE_NAME, options);
    mTestStream.write(BufferUtils.getIncreasingByteArray((int) (BLOCK_LENGTH * 1.5)));
    mTestStream.cancel();
    for (long streamIndex = 0; streamIndex < 2; streamIndex++) {
        Assert.assertTrue(mAlluxioOutStreamMap.get(streamIndex).isClosed());
        Assert.assertTrue(mAlluxioOutStreamMap.get(streamIndex).isCanceled());
    }
    // Don't persist or complete the file if the stream was canceled
    verify(mFileSystemMasterClient, times(0)).completeFile(FILE_NAME, CompleteFileOptions.defaults());
    verify(mUnderFileSystem).deleteFile(anyString());
}
Also used : OutStreamOptions(alluxio.client.file.options.OutStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

OutStreamOptions (alluxio.client.file.options.OutStreamOptions)10 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 BufferedBlockOutStream (alluxio.client.block.BufferedBlockOutStream)2 TestBufferedBlockOutStream (alluxio.client.block.TestBufferedBlockOutStream)2 WorkerNetAddress (alluxio.wire.WorkerNetAddress)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 AlluxioURI (alluxio.AlluxioURI)1 WriteType (alluxio.client.WriteType)1 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)1 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)1 CompleteFileOptions (alluxio.client.file.options.CompleteFileOptions)1 CreateUfsFileOptions (alluxio.client.file.options.CreateUfsFileOptions)1 FileWriteLocationPolicy (alluxio.client.file.policy.FileWriteLocationPolicy)1 CreateOptions (alluxio.underfs.options.CreateOptions)1 FileInfo (alluxio.wire.FileInfo)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1