Skip to content

Commit 25d5a67

Browse files
committed
the ut of the pr
1 parent 30c4323 commit 25d5a67

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ public void run() {
235235
}
236236

237237
public void refreshSpaceUsedKlass(Configuration conf) throws IOException {
238+
((CachingGetSpaceUsed)dfsUsage).close();
238239
this.dfsUsage = new FSCachingGetSpaceUsed.Builder().setBpid(bpid)
239240
.setVolume(volume)
240241
.setPath(bpDir)

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeReconfiguration.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package org.apache.hadoop.hdfs.server.datanode;
2020

21+
import org.apache.hadoop.fs.CachingGetSpaceUsed;
22+
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_GETSPACEUSED_CLASSNAME;
2123
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCKREPORT_INITIAL_DELAY_KEY;
2224
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_DEFAULT;
2325
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY;
@@ -76,6 +78,7 @@ public class TestDataNodeReconfiguration {
7678
private final int NUM_NAME_NODE = 1;
7779
private final int NUM_DATA_NODE = 10;
7880
private MiniDFSCluster cluster;
81+
private static long counter = 0;
7982

8083
@Before
8184
public void Setup() throws IOException {
@@ -99,6 +102,7 @@ private void startDFSCluster(int numNameNodes, int numDataNodes)
99102
throws IOException {
100103
Configuration conf = new Configuration();
101104
conf.setBoolean(DFS_DATANODE_PEER_STATS_ENABLED_KEY, true);
105+
conf.set(FS_GETSPACEUSED_CLASSNAME, DummyDU.class.getName());
102106

103107
MiniDFSNNTopology nnTopology = MiniDFSNNTopology
104108
.simpleFederatedTopology(numNameNodes);
@@ -673,4 +677,32 @@ public void testSlowDiskParameters() throws ReconfigurationException, IOExceptio
673677
dn.getDiskMetrics().getSlowDiskDetector().getLowThresholdMs());
674678
}
675679
}
680+
681+
private static class DummyDU extends CachingGetSpaceUsed {
682+
public DummyDU(Builder builder) throws IOException {
683+
super(builder.setInterval(1000));
684+
}
685+
686+
@Override
687+
protected void refresh() {
688+
counter++;
689+
}
690+
}
691+
692+
@Test
693+
public void testDfsUsageParameters() throws IOException, ReconfigurationException, InterruptedException {
694+
final DataNode[] dns = createDNsForTest(1);
695+
final DataNode dataNode = dns[0];
696+
697+
long lastCounter = counter;
698+
699+
Thread.sleep(5000);
700+
assertTrue(counter > lastCounter);
701+
702+
dataNode.reconfigurePropertyImpl(FS_GETSPACEUSED_CLASSNAME, null);
703+
704+
lastCounter = counter;
705+
Thread.sleep(5000);
706+
assertEquals(lastCounter, counter);
707+
}
676708
}

0 commit comments

Comments
 (0)