use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method seekExceptionTest2.
/**
* Tests {@link FileInStream#seek(long)}. Validate the expected exception for seeking a position
* that is past EOF.
*/
@Test
public void seekExceptionTest2() throws Exception {
mThrown.expect(IllegalArgumentException.class);
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);
try (FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op))) {
is.seek(k + 1);
}
}
}
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method seek.
/**
* Tests {@link FileInStream#seek(long)}.
*/
@Test
public void seek() 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));
is.seek(k / 3);
Assert.assertEquals(BufferUtils.intAsUnsignedByteValue(k / 3), is.read());
is.seek(k / 2);
Assert.assertEquals(BufferUtils.intAsUnsignedByteValue(k / 2), is.read());
is.seek(k / 4);
Assert.assertEquals(BufferUtils.intAsUnsignedByteValue(k / 4), is.read());
is.close();
}
}
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method positionedReadWithSmallThreshold.
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.USER_FILE_SEQUENTIAL_PREAD_THRESHOLD, "200KB" })
public void positionedReadWithSmallThreshold() throws Exception {
List<CreateFilePOptions> optionSet = new ArrayList<>(2);
optionSet.add(mWriteBoth);
optionSet.add(mWriteUnderStore);
for (CreateFilePOptions op : optionSet) {
String filename = mTestPath + "/file_" + MIN_LEN + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
try (FileInStream is = mFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op))) {
byte[] ret = new byte[DELTA - 1];
Assert.assertEquals(DELTA - 1, is.positionedRead(MIN_LEN - DELTA + 1, ret, 0, DELTA));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(MIN_LEN - DELTA + 1, DELTA - 1, ret));
}
}
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class FileInStreamRehydrationIntegrationTest method testRehydration.
@Test
public void testRehydration() throws Exception {
FileSystem fs = FileSystem.Factory.create(ServerConfiguration.global());
// Create a file with 10 blocks.
AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
CreateFilePOptions op = CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).setRecursive(true).build();
byte[] content = generateContent(BLOCK_BYTES * 10);
try (FileOutStream os = fs.createFile(filePath, op)) {
os.write(content);
}
// Validate file size and content.
validateAndCloseFileStream(mFileSystem.openFile(filePath), content);
// Grab the block master for emulating lost blocks.
MasterProcess masterProcess = Whitebox.getInternalState(mLocalAlluxioClusterResource.get().getLocalAlluxioMaster(), "mMasterProcess");
BlockMaster blockMaster = masterProcess.getMaster(BlockMaster.class);
// Remove blocks externally from block-master.
URIStatus status = fs.getStatus(filePath);
blockMaster.removeBlocks(status.getBlockIds(), true);
// Validate file size and content.
validateAndCloseFileStream(mFileSystem.openFile(filePath), content);
}
use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.
the class BufferedBlockInStreamIntegrationTest method readTest3.
/**
* Tests {@link alluxio.client.block.BufferedBlockInStream#read(byte[], int, int)}.
*/
@Test
public void readTest3() throws IOException, AlluxioException {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFilePOptions op : getOptionSet()) {
AlluxioURI path = new AlluxioURI(sTestPath + "/file_" + k + "_" + op.hashCode());
FileInStream is = sFileSystem.openFile(path, 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 = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op));
ret = new byte[k];
Assert.assertEquals(k, is.read(ret, 0, k));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
}
}
}
Aggregations