use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method readTest3.
/**
* Tests {@link FileInStream#read(byte[], int, int)}.
*/
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_STREAMING_READER_CHUNK_SIZE_BYTES, "64KB" })
public void readTest3() throws Exception {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFilePOptions op : getOptionSet()) {
String filename = mTestPath + "/file_" + k + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
byte[] ret = new byte[k / 2];
Assert.assertEquals(k / 2, is.read(ret, 0, k / 2));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k / 2, ret));
is.close();
is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
ret = new byte[k];
Assert.assertEquals(k, is.read(ret, 0, k));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
}
}
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method before.
@Before
public void before() throws Exception {
mFileSystem = mLocalAlluxioClusterResource.get().getClient();
mWriteBoth = CreateFilePOptions.newBuilder().setMode(Mode.createFullAccess().toProto()).setBlockSizeBytes(BLOCK_SIZE).setWriteType(WritePType.CACHE_THROUGH).setRecursive(true).build();
mWriteAlluxio = CreateFilePOptions.newBuilder().setMode(Mode.createFullAccess().toProto()).setBlockSizeBytes(BLOCK_SIZE).setWriteType(WritePType.MUST_CACHE).setRecursive(true).build();
mWriteUnderStore = CreateFilePOptions.newBuilder().setMode(Mode.createFullAccess().toProto()).setBlockSizeBytes(BLOCK_SIZE).setWriteType(WritePType.THROUGH).setRecursive(true).build();
mTestPath = PathUtils.uniqPath();
// Create files of varying size and write type to later read from
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFilePOptions op : getOptionSet()) {
AlluxioURI path = new AlluxioURI(mTestPath + "/file_" + k + "_" + op.hashCode());
FileSystemTestUtils.createByteFile(mFileSystem, path, op, k);
}
}
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class FileOutStreamIntegrationTest method writeSpecifyLocal.
/**
* Tests writing to a file and specify the location to be localhost.
*/
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_BLOCK_WRITE_LOCATION_POLICY, "alluxio.client.block.policy.LocalFirstPolicy" })
public void writeSpecifyLocal() throws Exception {
AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
final int length = 2;
CreateFilePOptions op = CreateFilePOptions.newBuilder().setWriteType(mWriteType.toProto()).setRecursive(true).build();
try (FileOutStream os = mFileSystem.createFile(filePath, op)) {
os.write((byte) 0);
os.write((byte) 1);
}
if (mWriteType.getAlluxioStorageType().isStore()) {
checkFileInAlluxio(filePath, length);
}
if (mWriteType.getUnderStorageType().isSyncPersist()) {
checkFileInUnderStorage(filePath, length);
}
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class FileOutStreamIntegrationTest method writeTwoByteArrays.
/**
* Tests {@link FileOutStream#write(byte[], int, int)}.
*/
@Test
public void writeTwoByteArrays() throws Exception {
String uniqPath = PathUtils.uniqPath();
for (int len = MIN_LEN; len <= MAX_LEN; len += DELTA) {
CreateFilePOptions op = CreateFilePOptions.newBuilder().setWriteType(mWriteType.toProto()).setRecursive(true).build();
AlluxioURI filePath = new AlluxioURI(PathUtils.concatPath(uniqPath, "file_" + len + "_" + mWriteType));
writeTwoIncreasingByteArraysToFile(filePath, len, op);
if (mWriteType.getAlluxioStorageType().isStore()) {
checkFileInAlluxio(filePath, len);
}
if (mWriteType.getUnderStorageType().isSyncPersist()) {
checkFileInUnderStorage(filePath, len);
}
}
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class LocalBlockInStreamIntegrationTest method readTest3.
/**
* Tests {@link alluxio.client.block.LocalBlockInStream#read(byte[], int, int)}.
*/
@Test
public void readTest3() throws Exception {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFilePOptions op : getOptionSet()) {
AlluxioURI uri = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
FileInStream is = sFileSystem.openFile(uri, sReadNoCache);
byte[] ret = new byte[k / 2];
Assert.assertEquals(k / 2, is.read(ret, 0, k / 2));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k / 2, ret));
is.close();
is = sFileSystem.openFile(uri, sReadCachePromote);
ret = new byte[k];
Assert.assertEquals(k, is.read(ret, 0, k));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
Assert.assertTrue(sFileSystem.getStatus(uri).getInAlluxioPercentage() == 100);
}
}
}
Aggregations