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);
}
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);
}
}
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);
}
}
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);
}
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;
}
Aggregations