diff --git a/hadoop-crypto/src/main/java/com/palantir/crypto2/hadoop/DelegatingFileSystem.java b/hadoop-crypto/src/main/java/com/palantir/crypto2/hadoop/DelegatingFileSystem.java index 89663b77f..0473f0351 100644 --- a/hadoop-crypto/src/main/java/com/palantir/crypto2/hadoop/DelegatingFileSystem.java +++ b/hadoop-crypto/src/main/java/com/palantir/crypto2/hadoop/DelegatingFileSystem.java @@ -18,6 +18,7 @@ import java.io.IOException; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.BlockLocation; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FilterFileSystem; @@ -27,6 +28,8 @@ * Equivalent to {@link FilterFileSystem} but invokes {@link #create} and {@link #open} on this class when calling * {@link #copyFromLocalFile} and {@link #copyToLocalFile}. *

+ * Additionally delegates (@link getFileBlockLocations(Path, long, long)} to the underlying filesystem. + *

* Solves: https://issues.apache.org/jira/browse/HADOOP-13870 */ public abstract class DelegatingFileSystem extends FilterFileSystem { @@ -81,4 +84,9 @@ public void copyToLocalFile(boolean delSrc, Path src, Path dst, boolean useRawLo : getLocal(conf); FileUtil.copy(this, src, local, dst, delSrc, conf); } + + @Override + public BlockLocation[] getFileBlockLocations(Path path, long start, long len) throws IOException { + return fs.getFileBlockLocations(path, start, len); + } } diff --git a/hadoop-crypto/src/test/java/com/palantir/crypto2/hadoop/DelegatingFileSystemTest.java b/hadoop-crypto/src/test/java/com/palantir/crypto2/hadoop/DelegatingFileSystemTest.java index a6a3af729..a487d76d8 100644 --- a/hadoop-crypto/src/test/java/com/palantir/crypto2/hadoop/DelegatingFileSystemTest.java +++ b/hadoop-crypto/src/test/java/com/palantir/crypto2/hadoop/DelegatingFileSystemTest.java @@ -17,6 +17,9 @@ package com.palantir.crypto2.hadoop; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.anyLong; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.google.common.io.Files; @@ -27,6 +30,7 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.BlockLocation; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSInputStream; @@ -112,6 +116,18 @@ private void testCopyToLocal(ThrowingConsumer copyToLocal) throws IOExcept assertThat(Files.toByteArray(localFile)).isEqualTo(bytes); } + @Test + public void testGetFileBlockLocations() throws IOException { + Path path = new Path("test-path"); + BlockLocation location = new BlockLocation( + new String[] {"some-host:50010"}, new String[] {"some-host"}, 0L, 0L); + when(delegate.getFileBlockLocations(eq(path), anyLong(), anyLong())) + .thenReturn(new BlockLocation[]{location}); + + assertThat(delegatingFs.getFileBlockLocations(path, 0L, 0L)).containsExactly(location); + verify(delegate).getFileBlockLocations(path, 0L, 0L); + } + private static final class ByteArrayFsInputStream extends FSInputStream { private final ByteArrayInputStream in;