Skip to content

Commit

Permalink
use try-with-resources in testDataNodeDatasetLockMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
hfutatzhanghb committed Dec 19, 2024
1 parent 0bdb7fa commit 0d97be0
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -821,24 +821,19 @@ public Boolean get() {
@Test
public void testDataNodeDatasetLockMetrics() throws IOException {
Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
try {
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build()) {
FileSystem fs = cluster.getFileSystem();
// Create and read a 1 byte file
Path tmpfile = new Path("/tmp.txt");
DFSTestUtil.createFile(fs, tmpfile,
(long)1, (short)1, 1L);
(long)1, (short)1, 1L);
DFSTestUtil.readFile(fs, tmpfile);
List<DataNode> datanodes = cluster.getDataNodes();
assertEquals(datanodes.size(), 1);
DataNode datanode = datanodes.get(0);
MetricsRecordBuilder rb = getMetrics(datanode.getMetrics().name());
assertCounterGt("AcquireDatasetWriteLockNumOps", (long)1, rb);
assertCounterGt("AcquireDatasetReadLockNumOps", (long)1, rb);
} finally {
if (cluster != null) {
cluster.shutdown();
}
}
}
}

0 comments on commit 0d97be0

Please sign in to comment.