use of org.apache.hadoop.fs.BlockLocation in project ignite by apache.
the class IgniteHadoopFileSystemAbstractSelfTest method testGetFileBlockLocations.
/** @throws Exception If failed. */
public void testGetFileBlockLocations() throws Exception {
Path igfsHome = new Path(PRIMARY_URI);
Path file = new Path(igfsHome, "someFile");
try (OutputStream out = new BufferedOutputStream(fs.create(file, true, 1024 * 1024))) {
byte[] data = new byte[128 * 1024];
for (int i = 0; i < 100; i++) out.write(data);
out.flush();
}
try (FSDataInputStream in = fs.open(file, 1024 * 1024)) {
byte[] data = new byte[128 * 1024];
int read;
do {
read = in.read(data);
} while (read > 0);
}
FileStatus status = fs.getFileStatus(file);
int grpLen = 128 * 512 * 1024;
int grpCnt = (int) ((status.getLen() + grpLen - 1) / grpLen);
BlockLocation[] locations = fs.getFileBlockLocations(status, 0, status.getLen());
assertEquals(grpCnt, locations.length);
}
use of org.apache.hadoop.fs.BlockLocation in project ignite by apache.
the class HadoopIgfs20FileSystemAbstractSelfTest method testGetFileBlockLocations.
/** @throws Exception If failed. */
public void testGetFileBlockLocations() throws Exception {
Path igfsHome = new Path(primaryFsUri);
Path file = new Path(igfsHome, "someFile");
try (OutputStream out = new BufferedOutputStream(fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault())))) {
byte[] data = new byte[128 * 1024];
for (int i = 0; i < 100; i++) out.write(data);
out.flush();
}
try (FSDataInputStream in = fs.open(file, 1024 * 1024)) {
byte[] data = new byte[128 * 1024];
int read;
do {
read = in.read(data);
} while (read > 0);
}
FileStatus status = fs.getFileStatus(file);
int grpLen = 128 * 512 * 1024;
int grpCnt = (int) ((status.getLen() + grpLen - 1) / grpLen);
BlockLocation[] locations = fs.getFileBlockLocations(file, 0, status.getLen());
assertEquals(grpCnt, locations.length);
}
Aggregations