|  | 
| 25 | 25 | import static org.junit.Assert.*; | 
| 26 | 26 | 
 | 
| 27 | 27 | import java.io.Closeable; | 
|  | 28 | +import java.io.File; | 
| 28 | 29 | import java.io.FileNotFoundException; | 
| 29 | 30 | import java.io.IOException; | 
| 30 | 31 | import java.io.InputStream; | 
|  | 
| 38 | 39 | import net.jcip.annotations.NotThreadSafe; | 
| 39 | 40 | import org.apache.hadoop.fs.StorageType; | 
| 40 | 41 | import org.apache.hadoop.hdfs.MiniDFSNNTopology; | 
|  | 42 | +import org.apache.hadoop.net.unix.DomainSocket; | 
|  | 43 | +import org.apache.hadoop.net.unix.TemporarySocketDirectory; | 
| 41 | 44 | import org.apache.hadoop.util.Lists; | 
|  | 45 | +import org.junit.Assume; | 
| 42 | 46 | import org.slf4j.Logger; | 
| 43 | 47 | import org.slf4j.LoggerFactory; | 
| 44 | 48 | import org.apache.hadoop.conf.Configuration; | 
| @@ -654,4 +658,38 @@ public void testNNRpcMetricsWithFederationAndHA() throws IOException { | 
| 654 | 658 |     assertCounter("HeartbeatsForns1-nn1NumOps", 1L, rb); | 
| 655 | 659 |     assertCounter("HeartbeatsNumOps", 4L, rb); | 
| 656 | 660 |   } | 
|  | 661 | + | 
|  | 662 | +  @Test | 
|  | 663 | +  public void testNodeLocalMetrics() throws Exception { | 
|  | 664 | +    Assume.assumeTrue(null == DomainSocket.getLoadingFailureReason()); | 
|  | 665 | +    Configuration conf = new HdfsConfiguration(); | 
|  | 666 | +    conf.setBoolean(HdfsClientConfigKeys.Read.ShortCircuit.KEY, true); | 
|  | 667 | +    TemporarySocketDirectory sockDir = new TemporarySocketDirectory(); | 
|  | 668 | +    DomainSocket.disableBindPathValidation(); | 
|  | 669 | +    conf.set(DFSConfigKeys.DFS_DOMAIN_SOCKET_PATH_KEY, | 
|  | 670 | +        new File(sockDir.getDir(), | 
|  | 671 | +            "testNodeLocalMetrics._PORT.sock").getAbsolutePath()); | 
|  | 672 | +    MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); | 
|  | 673 | +    try { | 
|  | 674 | +      cluster.waitActive(); | 
|  | 675 | +      FileSystem fs = cluster.getFileSystem(); | 
|  | 676 | +      Path testFile = new Path("/testNodeLocalMetrics.txt"); | 
|  | 677 | +      DFSTestUtil.createFile(fs, testFile, 10L, (short)1, 1L); | 
|  | 678 | +      DFSTestUtil.readFile(fs, testFile); | 
|  | 679 | +      List<DataNode> datanodes = cluster.getDataNodes(); | 
|  | 680 | +      assertEquals(1, datanodes.size()); | 
|  | 681 | + | 
|  | 682 | +      DataNode datanode = datanodes.get(0); | 
|  | 683 | +      MetricsRecordBuilder rb = getMetrics(datanode.getMetrics().name()); | 
|  | 684 | + | 
|  | 685 | +      // Write related metrics | 
|  | 686 | +      assertCounter("WritesFromLocalClient", 1L, rb); | 
|  | 687 | +      // Read related metrics | 
|  | 688 | +      assertCounter("ReadsFromLocalClient", 1L, rb); | 
|  | 689 | +    } finally { | 
|  | 690 | +      if (cluster != null) { | 
|  | 691 | +        cluster.shutdown(); | 
|  | 692 | +      } | 
|  | 693 | +    } | 
|  | 694 | +  } | 
| 657 | 695 | } | 
0 commit comments