Modified: hadoop/common/branches/branch-trunk-win/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeFile.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-trunk-win/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeFile.java?rev=1407217&r1=1407216&r2=1407217&view=diff ============================================================================== --- hadoop/common/branches/branch-trunk-win/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeFile.java (original) +++ hadoop/common/branches/branch-trunk-win/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeFile.java Thu Nov 8 19:09:46 2012 @@ -18,13 +18,17 @@ package org.apache.hadoop.hdfs.server.namenode; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.FileNotFoundException; +import java.io.IOException; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.PermissionStatus; import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo; - import org.junit.Test; public class TestINodeFile { @@ -199,4 +203,116 @@ public class TestINodeFile { return iNodes; } + + /** + * Test for the static {@link INodeFile#valueOf(INode, String)} + * and {@link INodeFileUnderConstruction#valueOf(INode, String)} methods. + * @throws IOException + */ + @Test + public void testValueOf () throws IOException { + final String path = "/testValueOf"; + final PermissionStatus perm = new PermissionStatus( + userName, null, FsPermission.getDefault()); + final short replication = 3; + + {//cast from null + final INode from = null; + + //cast to INodeFile, should fail + try { + INodeFile.valueOf(from, path); + fail(); + } catch(FileNotFoundException fnfe) { + assertTrue(fnfe.getMessage().contains("File does not exist")); + } + + //cast to INodeFileUnderConstruction, should fail + try { + INodeFileUnderConstruction.valueOf(from, path); + fail(); + } catch(FileNotFoundException fnfe) { + assertTrue(fnfe.getMessage().contains("File does not exist")); + } + + //cast to INodeDirectory, should fail + try { + INodeDirectory.valueOf(from, path); + fail(); + } catch(IOException ioe) { + assertTrue(ioe.getMessage().contains("Directory does not exist")); + } + } + + {//cast from INodeFile + final INode from = new INodeFile( + perm, null, replication, 0L, 0L, preferredBlockSize); + + //cast to INodeFile, should success + final INodeFile f = INodeFile.valueOf(from, path); + assertTrue(f == from); + + //cast to INodeFileUnderConstruction, should fail + try { + INodeFileUnderConstruction.valueOf(from, path); + fail(); + } catch(IOException ioe) { + assertTrue(ioe.getMessage().contains("File is not under construction")); + } + + //cast to INodeDirectory, should fail + try { + INodeDirectory.valueOf(from, path); + fail(); + } catch(IOException ioe) { + assertTrue(ioe.getMessage().contains("Path is not a directory")); + } + } + + {//cast from INodeFileUnderConstruction + final INode from = new INodeFileUnderConstruction( + perm, replication, 0L, 0L, "client", "machine", null); + + //cast to INodeFile, should success + final INodeFile f = INodeFile.valueOf(from, path); + assertTrue(f == from); + + //cast to INodeFileUnderConstruction, should success + final INodeFileUnderConstruction u = INodeFileUnderConstruction.valueOf( + from, path); + assertTrue(u == from); + + //cast to INodeDirectory, should fail + try { + INodeDirectory.valueOf(from, path); + fail(); + } catch(IOException ioe) { + assertTrue(ioe.getMessage().contains("Path is not a directory")); + } + } + + {//cast from INodeDirectory + final INode from = new INodeDirectory(perm, 0L); + + //cast to INodeFile, should fail + try { + INodeFile.valueOf(from, path); + fail(); + } catch(FileNotFoundException fnfe) { + assertTrue(fnfe.getMessage().contains("Path is not a file")); + } + + //cast to INodeFileUnderConstruction, should fail + try { + INodeFileUnderConstruction.valueOf(from, path); + fail(); + } catch(FileNotFoundException fnfe) { + assertTrue(fnfe.getMessage().contains("Path is not a file")); + } + + //cast to INodeDirectory, should success + final INodeDirectory d = INodeDirectory.valueOf(from, path); + assertTrue(d == from); + } + } }
Modified: hadoop/common/branches/branch-trunk-win/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-trunk-win/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java?rev=1407217&r1=1407216&r2=1407217&view=diff ============================================================================== --- hadoop/common/branches/branch-trunk-win/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java (original) +++ hadoop/common/branches/branch-trunk-win/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java Thu Nov 8 19:09:46 2012 @@ -205,6 +205,12 @@ public class TestNameNodeMetrics { final Path file = getTestPath("testCorruptBlock"); createFile(file, 100, (short)2); + // Disable the heartbeats, so that no corrupted replica + // can be fixed + for (DataNode dn : cluster.getDataNodes()) { + DataNodeTestUtils.setHeartbeatsDisabledForTests(dn, true); + } + // Corrupt first replica of the block LocatedBlock block = NameNodeAdapter.getBlockLocations( cluster.getNameNode(), file.toString(), 0, 1).get(0); @@ -215,12 +221,23 @@ public class TestNameNodeMetrics { } finally { cluster.getNamesystem().writeUnlock(); } - Thread.sleep(1000); // Wait for block to be marked corrupt + BlockManagerTestUtil.getComputedDatanodeWork(bm); + BlockManagerTestUtil.updateState(bm); MetricsRecordBuilder rb = getMetrics(NS_METRICS); assertGauge("CorruptBlocks", 1L, rb); assertGauge("PendingReplicationBlocks", 1L, rb); assertGauge("ScheduledReplicationBlocks", 1L, rb); + fs.delete(file, true); + // During the file deletion, both BlockManager#corruptReplicas and + // BlockManager#pendingReplications will be updated, i.e., the records + // for the blocks of the deleted file will be removed from both + // corruptReplicas and pendingReplications. The corresponding + // metrics (CorruptBlocks and PendingReplicationBlocks) will only be updated + // when BlockManager#computeDatanodeWork is run where the + // BlockManager#udpateState is called. And in + // BlockManager#computeDatanodeWork the metric ScheduledReplicationBlocks + // will also be updated. rb = waitForDnMetricValue(NS_METRICS, "CorruptBlocks", 0L); assertGauge("PendingReplicationBlocks", 0L, rb); assertGauge("ScheduledReplicationBlocks", 0L, rb); Modified: hadoop/common/branches/branch-trunk-win/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-trunk-win/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml?rev=1407217&r1=1407216&r2=1407217&view=diff ============================================================================== --- hadoop/common/branches/branch-trunk-win/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml (original) +++ hadoop/common/branches/branch-trunk-win/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml Thu Nov 8 19:09:46 2012 @@ -15797,7 +15797,7 @@ <comparators> <comparator> <type>RegexpComparator</type> - <expected-output>Configured Capacity: [0-9]+ \([0-9]+\.[0-9]+ [BKMGT]+\)</expected-output> + <expected-output>Configured Capacity: [0-9]+ \([0-9\.]+ [BKMGT]+\)</expected-output> </comparator> <comparator> <type>RegexpComparator</type> @@ -15915,7 +15915,7 @@ <comparators> <comparator> <type>RegexpComparator</type> - <expected-output>Configured Capacity: [0-9]+ \([0-9]+\.[0-9]+ [BKMGT]+\)</expected-output> + <expected-output>Configured Capacity: [0-9]+ \([0-9\.]+ [BKMGT]+\)</expected-output> </comparator> <comparator> <type>RegexpComparator</type>
