Skip to content

Commit

Permalink
the ut of the pr
Browse files Browse the repository at this point in the history
  • Loading branch information
singer-bin committed Mar 17, 2022
1 parent 30c4323 commit 25d5a67
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public void run() {
}

public void refreshSpaceUsedKlass(Configuration conf) throws IOException {
((CachingGetSpaceUsed)dfsUsage).close();
this.dfsUsage = new FSCachingGetSpaceUsed.Builder().setBpid(bpid)
.setVolume(volume)
.setPath(bpDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

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

import org.apache.hadoop.fs.CachingGetSpaceUsed;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_GETSPACEUSED_CLASSNAME;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCKREPORT_INITIAL_DELAY_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY;
Expand Down Expand Up @@ -76,6 +78,7 @@ public class TestDataNodeReconfiguration {
private final int NUM_NAME_NODE = 1;
private final int NUM_DATA_NODE = 10;
private MiniDFSCluster cluster;
private static long counter = 0;

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

MiniDFSNNTopology nnTopology = MiniDFSNNTopology
.simpleFederatedTopology(numNameNodes);
Expand Down Expand Up @@ -673,4 +677,32 @@ public void testSlowDiskParameters() throws ReconfigurationException, IOExceptio
dn.getDiskMetrics().getSlowDiskDetector().getLowThresholdMs());
}
}

private static class DummyDU extends CachingGetSpaceUsed {
public DummyDU(Builder builder) throws IOException {
super(builder.setInterval(1000));
}

@Override
protected void refresh() {
counter++;
}
}

@Test
public void testDfsUsageParameters() throws IOException, ReconfigurationException, InterruptedException {
final DataNode[] dns = createDNsForTest(1);
final DataNode dataNode = dns[0];

long lastCounter = counter;

Thread.sleep(5000);
assertTrue(counter > lastCounter);

dataNode.reconfigurePropertyImpl(FS_GETSPACEUSED_CLASSNAME, null);

lastCounter = counter;
Thread.sleep(5000);
assertEquals(lastCounter, counter);
}
}

0 comments on commit 25d5a67

Please sign in to comment.