/** Test {@link tachyon.client.block.BufferedBlockInStream#read()}. */ @Test public void readTest1() throws IOException, TachyonException { String uniqPath = PathUtils.uniqPath(); for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) { for (CreateFileOptions op : getOptionSet()) { TachyonURI path = new TachyonURI(uniqPath + "/file_" + k + "_" + op.hashCode()); FileSystemTestUtils.createByteFile(sFileSystem, path, op, k); for (int i = 0; i < 2; i++) { FileInStream is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op)); byte[] ret = new byte[k]; int value = is.read(); int cnt = 0; while (value != -1) { Assert.assertTrue(value >= 0); Assert.assertTrue(value < 256); ret[cnt++] = (byte) value; value = is.read(); } Assert.assertEquals(cnt, k); Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret)); is.close(); } } } }
/** Test {@link tachyon.client.block.BufferedBlockInStream#read(byte[])}. */ @Test public void readTest2() throws IOException, TachyonException { for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) { for (CreateFileOptions op : getOptionSet()) { TachyonURI path = new TachyonURI(sTestPath + "/file_" + k + "_" + op.hashCode()); FileInStream is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op)); byte[] ret = new byte[k]; Assert.assertEquals(k, is.read(ret)); Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret)); is.close(); is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op)); ret = new byte[k]; Assert.assertEquals(k, is.read(ret)); Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret)); is.close(); } } }
/** Test {@link tachyon.client.block.BufferedBlockInStream#skip(long)}. */ @Test public void skipTest() throws IOException, TachyonException { for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) { for (CreateFileOptions op : getOptionSet()) { TachyonURI path = new TachyonURI(sTestPath + "/file_" + k + "_" + op.hashCode()); FileInStream is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op)); Assert.assertEquals(k / 2, is.skip(k / 2)); Assert.assertEquals(k / 2, is.read()); is.close(); is = sFileSystem.openFile(path, FileSystemTestUtils.toOpenFileOptions(op)); int t = k / 3; Assert.assertEquals(t, is.skip(t)); Assert.assertEquals(t, is.read()); Assert.assertEquals(t, is.skip(t)); Assert.assertEquals(2 * t + 1, is.read()); is.close(); } } }
@BeforeClass public static final void beforeClass() throws Exception { sFileSystem = sLocalTachyonClusterResource.get().getClient(); sTachyonConf = sLocalTachyonClusterResource.get().getMasterTachyonConf(); sWriteBoth = StreamOptionUtils.getCreateFileOptionsCacheThrough(sTachyonConf); sWriteTachyon = StreamOptionUtils.getCreateFileOptionsMustCache(sTachyonConf); sWriteUnderStore = StreamOptionUtils.getCreateFileOptionsThrough(sTachyonConf); sTestPath = 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 (CreateFileOptions op : getOptionSet()) { TachyonURI path = new TachyonURI(sTestPath + "/file_" + k + "_" + op.hashCode()); FileSystemTestUtils.createByteFile(sFileSystem, path, op, k); } } }