Search in sources :

Example 26 with FileOutStream

use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.

the class FileOutStreamAsyncWriteIntegrationTest method asyncWrite.

@Test
public void asyncWrite() throws Exception {
    AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
    final int length = 2;
    FileOutStream os = mFileSystem.createFile(filePath, CreateFileOptions.defaults().setWriteType(WriteType.ASYNC_THROUGH));
    os.write((byte) 0);
    os.write((byte) 1);
    os.close();
    CommonUtils.sleepMs(1);
    // check the file is completed but not persisted
    URIStatus status = mFileSystem.getStatus(filePath);
    Assert.assertEquals(PersistenceState.TO_BE_PERSISTED.toString(), status.getPersistenceState());
    Assert.assertTrue(status.isCompleted());
    IntegrationTestUtils.waitForPersist(mLocalAlluxioClusterResource, filePath);
    status = mFileSystem.getStatus(filePath);
    Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
    checkFileInAlluxio(filePath, length);
    checkFileInUnderStorage(filePath, length);
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 27 with FileOutStream

use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.

the class FileOutStreamIntegrationTest method longWrite.

/**
   * Tests writing to a file for longer than HEARTBEAT_INTERVAL_MS to make sure the sessionId
   * doesn't change. Tracks [ALLUXIO-171].
   */
@Test
public void longWrite() throws Exception {
    AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
    final int length = 2;
    try (FileOutStream os = mFileSystem.createFile(filePath, CreateFileOptions.defaults().setWriteType(mWriteType))) {
        os.write((byte) 0);
        Thread.sleep(Configuration.getInt(PropertyKey.USER_HEARTBEAT_INTERVAL_MS) * 2);
        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) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 28 with FileOutStream

use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.

the class FileOutStreamIntegrationTest method outOfOrderWrite.

/**
   * Tests if out-of-order writes are possible. Writes could be out-of-order when the following are
   * both true: - a "large" write (over half the internal buffer size) follows a smaller write. -
   * the "large" write does not cause the internal buffer to overflow.
   */
@Test
public void outOfOrderWrite() throws Exception {
    AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
    // A length greater than 0.5 * BUFFER_BYTES and less than BUFFER_BYTES.
    int length = (BUFFER_BYTES * 3) / 4;
    try (FileOutStream os = mFileSystem.createFile(filePath, CreateFileOptions.defaults().setWriteType(mWriteType))) {
        // Write something small, so it is written into the buffer, and not directly to the file.
        os.write((byte) 0);
        // Write a large amount of data (larger than BUFFER_BYTES/2, but will not overflow the buffer.
        os.write(BufferUtils.getIncreasingByteArray(1, length));
    }
    if (mWriteType.getAlluxioStorageType().isStore()) {
        checkFileInAlluxio(filePath, length + 1);
    }
    if (mWriteType.getUnderStorageType().isSyncPersist()) {
        checkFileInUnderStorage(filePath, length + 1);
    }
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 29 with FileOutStream

use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.

the class JournalIntegrationTest method addBlock.

/**
   * Tests adding a block.
   */
@Test
public void addBlock() throws Exception {
    AlluxioURI uri = new AlluxioURI("/xyz");
    CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(64);
    FileOutStream os = mFileSystem.createFile(uri, options);
    for (int k = 0; k < 1000; k++) {
        os.write(k);
    }
    os.close();
    URIStatus status = mFileSystem.getStatus(uri);
    mLocalAlluxioCluster.stopFS();
    addBlockTestUtil(status);
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileOutStream(alluxio.client.file.FileOutStream) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 30 with FileOutStream

use of alluxio.client.file.FileOutStream in project alluxio by Alluxio.

the class StreamCache method invalidate.

/**
   * @param key the key for the stream to invalidate
   * @return the invalidated stream or null if the cache contains no stream for the given key
   */
public Closeable invalidate(Integer key) {
    FileInStream is = mInStreamCache.getIfPresent(key);
    if (is != null) {
        mInStreamCache.invalidate(key);
        return is;
    }
    FileOutStream os = mOutStreamCache.getIfPresent(key);
    if (os != null) {
        mOutStreamCache.invalidate(key);
        return os;
    }
    return null;
}
Also used : FileInStream(alluxio.client.file.FileInStream) 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