|
@@ -97,6 +97,7 @@ import org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus;
|
|
|
import org.apache.hadoop.hdfs.security.token.block.ExportedBlockKeys;
|
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
|
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil;
|
|
|
+import org.apache.hadoop.hdfs.server.datanode.DataNode;
|
|
|
import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster;
|
|
|
import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.NamenodeContext;
|
|
|
import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.RouterContext;
|
|
@@ -1867,4 +1868,51 @@ public class TestRouterRpc {
|
|
|
.contains("callerContext=clientContext,clientIp:"));
|
|
|
assertTrue(verifyFileExists(routerFS, dirPath));
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testSetBalancerBandwidth() throws Exception {
|
|
|
+ long defaultBandwidth =
|
|
|
+ DFSConfigKeys.DFS_DATANODE_BALANCE_BANDWIDTHPERSEC_DEFAULT;
|
|
|
+ long newBandwidth = defaultBandwidth * 2;
|
|
|
+ routerProtocol.setBalancerBandwidth(newBandwidth);
|
|
|
+ ArrayList<DataNode> datanodes = cluster.getCluster().getDataNodes();
|
|
|
+ GenericTestUtils.waitFor(() -> {
|
|
|
+ return datanodes.get(0).getBalancerBandwidth() == newBandwidth;
|
|
|
+ }, 100, 60 * 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testAddClientIpPortToCallerContext() throws IOException {
|
|
|
+ GenericTestUtils.LogCapturer auditLog =
|
|
|
+ GenericTestUtils.LogCapturer.captureLogs(FSNamesystem.auditLog);
|
|
|
+
|
|
|
+ // 1. ClientIp and ClientPort are not set on the client.
|
|
|
+ // Set client context.
|
|
|
+ CallerContext.setCurrent(
|
|
|
+ new CallerContext.Builder("clientContext").build());
|
|
|
+
|
|
|
+ // Create a directory via the router.
|
|
|
+ String dirPath = "/test";
|
|
|
+ routerProtocol.mkdirs(dirPath, new FsPermission("755"), false);
|
|
|
+
|
|
|
+ // The audit log should contains "clientIp:" and "clientPort:".
|
|
|
+ assertTrue(auditLog.getOutput().contains("clientIp:"));
|
|
|
+ assertTrue(auditLog.getOutput().contains("clientPort:"));
|
|
|
+ assertTrue(verifyFileExists(routerFS, dirPath));
|
|
|
+ auditLog.clearOutput();
|
|
|
+
|
|
|
+ // 2. ClientIp and ClientPort are set on the client.
|
|
|
+ // Reset client context.
|
|
|
+ CallerContext.setCurrent(
|
|
|
+ new CallerContext.Builder(
|
|
|
+ "clientContext,clientIp:1.1.1.1,clientPort:1234").build());
|
|
|
+
|
|
|
+ // Create a directory via the router.
|
|
|
+ routerProtocol.getFileInfo(dirPath);
|
|
|
+
|
|
|
+ // The audit log should contains the original clientIp and clientPort
|
|
|
+ // set by client.
|
|
|
+ assertTrue(auditLog.getOutput().contains("clientIp:1.1.1.1"));
|
|
|
+ assertTrue(auditLog.getOutput().contains("clientPort:1234"));
|
|
|
+ }
|
|
|
}
|