Skip to content

Commit

Permalink
Add an unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
hfutatzhanghb committed Jan 3, 2024
1 parent 30a9d13 commit b5e7375
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,8 @@ public PipelineAck.ECN getECN() {
double load = ManagementFactory.getOperatingSystemMXBean()
.getSystemLoadAverage();
double threshold = NUM_CORES * congestionRatio;
if (load > threshold) {

if (load > threshold || DataNodeFaultInjector.get().mockCongestedForTest()) {
metrics.incrCongestedCount();
}
return load > threshold ? PipelineAck.ECN.CONGESTED :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,8 @@ public void markSlow(String dnAddr, int[] replies) {}
* Just delay delete replica a while.
*/
public void delayDeleteReplica() {}

public boolean mockCongestedForTest() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.StorageType;
import org.apache.hadoop.hdfs.MiniDFSNNTopology;
import org.apache.hadoop.hdfs.protocol.datatransfer.PipelineAck;
import org.apache.hadoop.net.unix.DomainSocket;
import org.apache.hadoop.net.unix.TemporarySocketDirectory;
import org.apache.hadoop.util.Lists;
import org.junit.Assert;
import org.junit.Assume;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -816,4 +818,30 @@ public Boolean get() {
}, 100, 10000);
}
}

@Test
public void testCongestedCount() throws Exception {
Configuration conf = new Configuration();
conf.setBoolean(DFSConfigKeys.DFS_PIPELINE_ECN_ENABLED, true);
MiniDFSCluster cluster = null;
DataNodeFaultInjector old = null;
try {
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build();
old = DataNodeFaultInjector.get();
DataNodeFaultInjector.set(new DataNodeFaultInjector(){
@Override
public boolean mockCongestedForTest() {
return true;
}
});
PipelineAck.ECN ecn = cluster.getDataNodes().get(0).getECN();
MetricsRecordBuilder dnMetrics = getMetrics(cluster.getDataNodes().get(0).getMetrics().name());
Assert.assertEquals(1L, getLongCounter("CongestedCount", dnMetrics));
} finally {
if (cluster != null) {
DataNodeFaultInjector.set(old);
cluster.shutdown();
}
}
}
}

0 comments on commit b5e7375

Please sign in to comment.