|
@@ -28,6 +28,7 @@ import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.hdfs.DFSTestUtil;
|
|
|
import org.apache.hadoop.hdfs.DistributedFileSystem;
|
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
|
+import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoContiguous;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.FSDirectory;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.INode;
|
|
@@ -38,10 +39,9 @@ import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
/**
|
|
|
- * This class tests the replication handling/calculation of snapshots. In
|
|
|
- * particular, {@link INodeFile#getFileReplication()} and
|
|
|
- * {@link INodeFile#getPreferredBlockReplication()} are tested to make sure
|
|
|
- * the number of replication is calculated correctly with/without snapshots.
|
|
|
+ * This class tests the replication handling/calculation of snapshots to make
|
|
|
+ * sure the number of replication is calculated correctly with/without
|
|
|
+ * snapshots.
|
|
|
*/
|
|
|
public class TestSnapshotReplication {
|
|
|
|
|
@@ -79,9 +79,7 @@ public class TestSnapshotReplication {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Check the replication of a given file. We test both
|
|
|
- * {@link INodeFile#getFileReplication()} and
|
|
|
- * {@link INodeFile#getPreferredBlockReplication()}.
|
|
|
+ * Check the replication of a given file.
|
|
|
*
|
|
|
* @param file The given file
|
|
|
* @param replication The expected replication number
|
|
@@ -98,8 +96,9 @@ public class TestSnapshotReplication {
|
|
|
// Check the correctness of getPreferredBlockReplication()
|
|
|
INode inode = fsdir.getINode(file1.toString());
|
|
|
assertTrue(inode instanceof INodeFile);
|
|
|
- assertEquals(blockReplication,
|
|
|
- ((INodeFile) inode).getPreferredBlockReplication());
|
|
|
+ for (BlockInfoContiguous b : inode.asFile().getBlocks()) {
|
|
|
+ assertEquals(blockReplication, b.getReplication());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -141,8 +140,9 @@ public class TestSnapshotReplication {
|
|
|
// First check the getPreferredBlockReplication for the INode of
|
|
|
// the currentFile
|
|
|
final INodeFile inodeOfCurrentFile = getINodeFile(currentFile);
|
|
|
- assertEquals(expectedBlockRep,
|
|
|
- inodeOfCurrentFile.getPreferredBlockReplication());
|
|
|
+ for (BlockInfoContiguous b : inodeOfCurrentFile.getBlocks()) {
|
|
|
+ assertEquals(expectedBlockRep, b.getReplication());
|
|
|
+ }
|
|
|
// Then check replication for every snapshot
|
|
|
for (Path ss : snapshotRepMap.keySet()) {
|
|
|
final INodesInPath iip = fsdir.getINodesInPath(ss.toString(), true);
|
|
@@ -150,7 +150,9 @@ public class TestSnapshotReplication {
|
|
|
// The replication number derived from the
|
|
|
// INodeFileWithLink#getPreferredBlockReplication should
|
|
|
// always == expectedBlockRep
|
|
|
- assertEquals(expectedBlockRep, ssInode.getPreferredBlockReplication());
|
|
|
+ for (BlockInfoContiguous b : ssInode.getBlocks()) {
|
|
|
+ assertEquals(expectedBlockRep, b.getReplication());
|
|
|
+ }
|
|
|
// Also check the number derived from INodeFile#getFileReplication
|
|
|
assertEquals(snapshotRepMap.get(ss).shortValue(),
|
|
|
ssInode.getFileReplication(iip.getPathSnapshotId()));
|
|
@@ -224,7 +226,9 @@ public class TestSnapshotReplication {
|
|
|
// The replication number derived from the
|
|
|
// INodeFileWithLink#getPreferredBlockReplication should
|
|
|
// always == expectedBlockRep
|
|
|
- assertEquals(REPLICATION, ssInode.getPreferredBlockReplication());
|
|
|
+ for (BlockInfoContiguous b : ssInode.getBlocks()) {
|
|
|
+ assertEquals(REPLICATION, b.getReplication());
|
|
|
+ }
|
|
|
// Also check the number derived from INodeFile#getFileReplication
|
|
|
assertEquals(snapshotRepMap.get(ss).shortValue(),
|
|
|
ssInode.getFileReplication());
|