/** Tests that seeking around a file cached locally works. */ @Test public void seekAroundLocalBlock() throws IOException, TachyonException { String uniqPath = PathUtils.uniqPath(); // The number of bytes per remote block read should be set to 100 in the before function TachyonFile f = TachyonFSTestUtils.createByteFile(mTfs, uniqPath, 200, mWriteTachyon); FileInStream is = mTfs.getInStream(f, mReadNoCache); Assert.assertEquals(0, is.read()); is.seek(199); Assert.assertEquals(199, is.read()); is.seek(99); Assert.assertEquals(99, is.read()); is.close(); }
/** * Test <code>void seek(long pos)</code>. * * @throws IOException * @throws TachyonException */ @Test public void seekTest() throws IOException, TachyonException { String uniqPath = PathUtils.uniqPath(); for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) { TachyonFile f = TachyonFSTestUtils.createByteFile(mTfs, uniqPath + "/file_" + k, k, mWriteUnderStore); FileInStream is = mTfs.getInStream(f, mReadNoCache); Assert.assertEquals(0, is.read()); is.seek(k / 3); Assert.assertEquals(k / 3, is.read()); is.seek(k / 2); Assert.assertEquals(k / 2, is.read()); is.seek(k / 4); Assert.assertEquals(k / 4, is.read()); is.close(); } }
/** * Test <code>void seek(long pos)</code>. Validate the expected exception for seeking a position * that is past block size. * * @throws IOException * @throws TachyonException */ @Test public void seekExceptionTest2() throws IOException, TachyonException { mThrown.expect(IllegalArgumentException.class); mThrown.expectMessage("Seek position is past EOF: 1, fileSize = 0"); String uniqPath = PathUtils.uniqPath(); for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) { TachyonFile f = TachyonFSTestUtils.createByteFile(mTfs, uniqPath + "/file_" + k, k, mWriteUnderStore); FileInStream is = mTfs.getInStream(f, mReadNoCache); try { is.seek(k + 1); } finally { is.close(); } } }