@Test public void testFileSystemApis() throws IOException { OuterPathInfo outerPathInfo = generateOuterFileAndGetInfo(1000); Path inlinePath = FileSystemTestUtils.getPhantomFile(outerPathInfo.outerPath, outerPathInfo.startOffset, outerPathInfo.length); InLineFileSystem inlineFileSystem = (InLineFileSystem) inlinePath.getFileSystem(conf); final FSDataInputStream fsDataInputStream = inlineFileSystem.open(inlinePath); byte[] actualBytes = new byte[outerPathInfo.expectedBytes.length]; assertEquals(0, fsDataInputStream.getPos()); fsDataInputStream.readFully(0, actualBytes); assertArrayEquals(outerPathInfo.expectedBytes, actualBytes); int[] validPositions = {1, 100, 290, 520, 990, 999, 1000}; for (int pos : validPositions) { fsDataInputStream.seek(pos); } int[] invalidPositions = {1001, 1100, 10000}; for (int pos : invalidPositions) { assertThrows(IOException.class, () -> { fsDataInputStream.seek(pos); }, "Should have thrown IOException"); } actualBytes = new byte[100]; fsDataInputStream.read(0, actualBytes, 10, 10); verifyArrayEquality(outerPathInfo.expectedBytes, 0, 10, actualBytes, 10, 10); actualBytes = new byte[310]; fsDataInputStream.read(25, actualBytes, 100, 210); verifyArrayEquality(outerPathInfo.expectedBytes, 25, 210, actualBytes, 100, 210); assertThrows(IOException.class, () -> { fsDataInputStream.read(0, new byte[1100], 0, 1101); }, "Should have thrown IOException"); assertThrows(IOException.class, () -> { fsDataInputStream.read(0, new byte[10], 991, 10); }, "Should have thrown IOException"); actualBytes = new byte[100]; fsDataInputStream.readFully(0, actualBytes, 10, 20); verifyArrayEquality(outerPathInfo.expectedBytes, 0, 10, actualBytes, 10, 10); actualBytes = new byte[310]; fsDataInputStream.readFully(25, actualBytes, 100, 210); verifyArrayEquality(outerPathInfo.expectedBytes, 25, 210, actualBytes, 100, 210); assertThrows(IOException.class, () -> { fsDataInputStream.readFully(0, new byte[1100], 0, 1101); }, "Should have thrown IOException"); assertThrows(IOException.class, () -> { fsDataInputStream.readFully(0, new byte[100], 910, 100); }, "Should have thrown IOException"); actualBytes = new byte[100]; fsDataInputStream.readFully(0, actualBytes); verifyArrayEquality(outerPathInfo.expectedBytes, 0, 100, actualBytes, 0, 100); actualBytes = new byte[310]; fsDataInputStream.readFully(25, actualBytes); verifyArrayEquality(outerPathInfo.expectedBytes, 25, 210, actualBytes, 0, 210); assertThrows(IOException.class, () -> { fsDataInputStream.readFully(0, new byte[1100]); }, "Should have thrown IOException"); ByteBuffer actualByteBuffer = ByteBuffer.allocate(100); assertThrows(UnsupportedOperationException.class, () -> { fsDataInputStream.read(actualByteBuffer); }, "Should have thrown"); assertEquals(outerPathInfo.outerPath.getFileSystem(conf).open(outerPathInfo.outerPath).getFileDescriptor(), fsDataInputStream.getFileDescriptor()); assertThrows(UnsupportedOperationException.class, () -> { fsDataInputStream.setReadahead(10L); }, "Should have thrown exception"); assertThrows(UnsupportedOperationException.class, () -> { fsDataInputStream.setDropBehind(true); }, "Should have thrown exception"); fsDataInputStream.close(); }
@Override public FSDataInputStream open(Path inlinePath, int bufferSize) throws IOException { Path outerPath = InLineFSUtils.getOuterfilePathFromInlinePath(inlinePath); FileSystem outerFs = outerPath.getFileSystem(conf); FSDataInputStream outerStream = outerFs.open(outerPath, bufferSize); return new InLineFsDataInputStream(InLineFSUtils.startOffset(inlinePath), outerStream, InLineFSUtils.length(inlinePath)); }
InLineFileSystem extends FileSystem { @Override public FSDataInputStream open(Path inlinePath, int bufferSize) throws IOException { Path outerPath = InLineFSUtils.getOuterfilePathFromInlinePath(inlinePath); FileSystem outerFs = outerPath.getFileSystem(conf); FSDataInputStream outerStream = outerFs.open(outerPath, bufferSize); return new InLineFsDataInputStream(InLineFSUtils.startOffset(inlinePath), outerStream, InLineFSUtils.length(inlinePath)); } }
InLineFileSystem extends FileSystem { @Override public FSDataInputStream open(Path inlinePath, int bufferSize) throws IOException { Path outerPath = InLineFSUtils.getOuterfilePathFromInlinePath(inlinePath); FileSystem outerFs = outerPath.getFileSystem(conf); FSDataInputStream outerStream = outerFs.open(outerPath, bufferSize); return new InLineFsDataInputStream(InLineFSUtils.startOffset(inlinePath), outerStream, InLineFSUtils.length(inlinePath)); }  }
InLineFileSystem extends FileSystem { @Override public FSDataInputStream open(Path inlinePath, int bufferSize) throws IOException { Path outerPath = InLineFSUtils.getOuterfilePathFromInlinePath(inlinePath); FileSystem outerFs = outerPath.getFileSystem(conf); FSDataInputStream outerStream = outerFs.open(outerPath, bufferSize); return new InLineFsDataInputStream(InLineFSUtils.startOffset(inlinePath), outerStream, InLineFSUtils.length(inlinePath)); }  @Override void initialize(URI name, Configuration conf); @Override URI getUri(); String getScheme(); @Override FSDataInputStream open(Path inlinePath, int bufferSize); @Override boolean exists(Path f); @Override FileStatus getFileStatus(Path inlinePath); @Override FSDataOutputStream create(Path path, FsPermission fsPermission, boolean b, int i, short i1, long l,
                                   Progressable progressable); @Override FSDataOutputStream append(Path path, int i, Progressable progressable); @Override boolean rename(Path path, Path path1); @Override boolean delete(Path path, boolean b); @Override FileStatus[] listStatus(Path inlinePath); @Override void setWorkingDirectory(Path path); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path path, FsPermission fsPermission); }
InLineFileSystem extends FileSystem { @Override public FSDataInputStream open(Path inlinePath, int bufferSize) throws IOException { Path outerPath = InLineFSUtils.getOuterfilePathFromInlinePath(inlinePath); FileSystem outerFs = outerPath.getFileSystem(conf); FSDataInputStream outerStream = outerFs.open(outerPath, bufferSize); return new InLineFsDataInputStream(InLineFSUtils.startOffset(inlinePath), outerStream, InLineFSUtils.length(inlinePath)); }  @Override void initialize(URI name, Configuration conf); @Override URI getUri(); String getScheme(); @Override FSDataInputStream open(Path inlinePath, int bufferSize); @Override boolean exists(Path f); @Override FileStatus getFileStatus(Path inlinePath); @Override FSDataOutputStream create(Path path, FsPermission fsPermission, boolean b, int i, short i1, long l,
                                   Progressable progressable); @Override FSDataOutputStream append(Path path, int i, Progressable progressable); @Override boolean rename(Path path, Path path1); @Override boolean delete(Path path, boolean b); @Override FileStatus[] listStatus(Path inlinePath); @Override void setWorkingDirectory(Path path); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path path, FsPermission fsPermission); static final String SCHEME; }