本文整理汇总了Java中org.apache.hadoop.fs.BlockLocation.getNames方法的典型用法代码示例。如果您正苦于以下问题:Java BlockLocation.getNames方法的具体用法?Java BlockLocation.getNames怎么用?Java BlockLocation.getNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.fs.BlockLocation
的用法示例。
在下文中一共展示了BlockLocation.getNames方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFavoredNodesEndToEnd
import org.apache.hadoop.fs.BlockLocation; //导入方法依赖的package包/类
@Test(timeout=180000)
public void testFavoredNodesEndToEnd() throws Exception {
//create 10 files with random preferred nodes
for (int i = 0; i < NUM_FILES; i++) {
Random rand = new Random(System.currentTimeMillis() + i);
//pass a new created rand so as to get a uniform distribution each time
//without too much collisions (look at the do-while loop in getDatanodes)
InetSocketAddress datanode[] = getDatanodes(rand);
Path p = new Path("/filename"+i);
FSDataOutputStream out = dfs.create(p, FsPermission.getDefault(), true,
4096, (short)3, 4096L, null, datanode);
out.write(SOME_BYTES);
out.close();
BlockLocation[] locations = getBlockLocations(p);
//verify the files got created in the right nodes
for (BlockLocation loc : locations) {
String[] hosts = loc.getNames();
String[] hosts1 = getStringForInetSocketAddrs(datanode);
assertTrue(compareNodes(hosts, hosts1));
}
}
}
示例2: testFavoredNodesEndToEndForAppend
import org.apache.hadoop.fs.BlockLocation; //导入方法依赖的package包/类
@Test(timeout = 180000)
public void testFavoredNodesEndToEndForAppend() throws Exception {
// create 10 files with random preferred nodes
for (int i = 0; i < NUM_FILES; i++) {
Random rand = new Random(System.currentTimeMillis() + i);
// pass a new created rand so as to get a uniform distribution each time
// without too much collisions (look at the do-while loop in getDatanodes)
InetSocketAddress datanode[] = getDatanodes(rand);
Path p = new Path("/filename" + i);
// create and close the file.
dfs.create(p, FsPermission.getDefault(), true, 4096, (short) 3, 4096L,
null, null).close();
// re-open for append
FSDataOutputStream out = dfs.append(p, EnumSet.of(CreateFlag.APPEND),
4096, null, datanode);
out.write(SOME_BYTES);
out.close();
BlockLocation[] locations = getBlockLocations(p);
// verify the files got created in the right nodes
for (BlockLocation loc : locations) {
String[] hosts = loc.getNames();
String[] hosts1 = getStringForInetSocketAddrs(datanode);
assertTrue(compareNodes(hosts, hosts1));
}
}
}
示例3: assertLocationValid
import org.apache.hadoop.fs.BlockLocation; //导入方法依赖的package包/类
private void assertLocationValid(BlockLocation location) throws
IOException {
LOG.info(location);
String[] hosts = location.getHosts();
String[] names = location.getNames();
assertNotEqual("No hosts supplied for " + location, 0, hosts.length);
//for every host, there's a name.
assertEquals("Unequal names and hosts in " + location,
hosts.length, names.length);
assertEquals(SwiftProtocolConstants.BLOCK_LOCATION,
location.getNames()[0]);
assertEquals(SwiftProtocolConstants.TOPOLOGY_PATH,
location.getTopologyPaths()[0]);
}