Skip to content

Commit

Permalink
Delegate getfileblocklocations with path (#99)
Browse files Browse the repository at this point in the history
* delegate getfileblocklocations with path

* doc comment

* checkstyle

* whitespace

* checkstyle

* checkstyle
  • Loading branch information
robert3005 authored and ellisjoe committed Nov 24, 2017
1 parent 9ba05fe commit d7bf503
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}.
* <p>
* Additionally delegates (@link getFileBlockLocations(Path, long, long)} to the underlying filesystem.
* <p>
* Solves: https://issues.apache.org/jira/browse/HADOOP-13870
*/
public abstract class DelegatingFileSystem extends FilterFileSystem {
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -112,6 +116,18 @@ private void testCopyToLocal(ThrowingConsumer<Path> 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;
Expand Down

0 comments on commit d7bf503

Please sign in to comment.