HDFS-17353. Fix failing RBF module tests. (#6491) Contributed by Alexander Bogdanov
Reviewed-by: Inigo Goiri <inigoiri@apache.org> Signed-off-by: Shilun Fan <slfan1989@apache.org>
This commit is contained in:
parent
6464507cd1
commit
20d8596af2
@ -137,6 +137,7 @@
|
|||||||
import org.apache.hadoop.test.LambdaTestUtils;
|
import org.apache.hadoop.test.LambdaTestUtils;
|
||||||
import org.codehaus.jettison.json.JSONException;
|
import org.codehaus.jettison.json.JSONException;
|
||||||
import org.codehaus.jettison.json.JSONObject;
|
import org.codehaus.jettison.json.JSONObject;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
@ -265,6 +266,12 @@ public static void globalSetUp() throws Exception {
|
|||||||
.getDatanodeManager().setHeartbeatExpireInterval(3000);
|
.getDatanodeManager().setHeartbeatExpireInterval(3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void cleanup() {
|
||||||
|
// clear client context
|
||||||
|
CallerContext.setCurrent(null);
|
||||||
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void tearDown() {
|
public static void tearDown() {
|
||||||
cluster.shutdown();
|
cluster.shutdown();
|
||||||
@ -2088,10 +2095,10 @@ public void testMkdirsWithCallerContext() throws IOException {
|
|||||||
|
|
||||||
// The audit log should contains "callerContext=clientIp:...,clientContext"
|
// The audit log should contains "callerContext=clientIp:...,clientContext"
|
||||||
final String logOutput = auditlog.getOutput();
|
final String logOutput = auditlog.getOutput();
|
||||||
assertTrue(logOutput.contains("callerContext=clientIp:"));
|
assertTrue(logOutput.contains("clientIp:"));
|
||||||
assertTrue(logOutput.contains(",clientContext"));
|
assertTrue(logOutput.contains("clientContext"));
|
||||||
assertTrue(logOutput.contains(",clientId"));
|
assertTrue(logOutput.contains("clientId"));
|
||||||
assertTrue(logOutput.contains(",clientCallId"));
|
assertTrue(logOutput.contains("clientCallId"));
|
||||||
assertTrue(verifyFileExists(routerFS, dirPath));
|
assertTrue(verifyFileExists(routerFS, dirPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2103,7 +2110,6 @@ public void testRealUserPropagationInCallerContext()
|
|||||||
|
|
||||||
// Current callerContext is null
|
// Current callerContext is null
|
||||||
assertNull(CallerContext.getCurrent());
|
assertNull(CallerContext.getCurrent());
|
||||||
|
|
||||||
UserGroupInformation loginUser = UserGroupInformation.getLoginUser();
|
UserGroupInformation loginUser = UserGroupInformation.getLoginUser();
|
||||||
UserGroupInformation realUser = UserGroupInformation
|
UserGroupInformation realUser = UserGroupInformation
|
||||||
.createUserForTesting("testRealUser", new String[]{"group"});
|
.createUserForTesting("testRealUser", new String[]{"group"});
|
||||||
|
@ -33,9 +33,13 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -474,21 +478,59 @@ public void testCallerContextWithMultiDestinations() throws IOException {
|
|||||||
routerFs.getFileStatus(dirPath);
|
routerFs.getFileStatus(dirPath);
|
||||||
|
|
||||||
String auditFlag = "src=" + dirPath.toString();
|
String auditFlag = "src=" + dirPath.toString();
|
||||||
String clientIpInfo = "clientIp:"
|
Set<String> clientIpInfos = getClientIpInfos();
|
||||||
+ InetAddress.getLocalHost().getHostAddress();
|
|
||||||
for (String line : auditLog.getOutput().split("\n")) {
|
for (String line : auditLog.getOutput().split("\n")) {
|
||||||
if (line.contains(auditFlag)) {
|
if (line.contains(auditFlag)) {
|
||||||
// assert origin caller context exist in audit log
|
// assert origin caller context exist in audit log
|
||||||
String callerContext = line.substring(line.indexOf("callerContext="));
|
String callerContext = line.substring(line.indexOf("callerContext="));
|
||||||
assertTrue(callerContext.contains("clientContext"));
|
assertTrue(String.format("%s doesn't contain 'clientContext'", callerContext),
|
||||||
|
callerContext.contains("clientContext"));
|
||||||
// assert client ip info exist in caller context
|
// assert client ip info exist in caller context
|
||||||
assertTrue(callerContext.contains(clientIpInfo));
|
checkCallerContextContainsClientIp(clientIpInfos, callerContext);
|
||||||
// assert client ip info appears only once in caller context
|
|
||||||
assertEquals(callerContext.indexOf(clientIpInfo),
|
|
||||||
callerContext.lastIndexOf(clientIpInfo));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// clear client context
|
}
|
||||||
CallerContext.setCurrent(null);
|
|
||||||
|
/**
|
||||||
|
* Check that one of the IP from all local network interfaces is contained
|
||||||
|
* only once in callerContext.
|
||||||
|
*
|
||||||
|
* @param clientIpInfos IP information extracted from all local network interfaces.
|
||||||
|
* @param callerContext current caller context.
|
||||||
|
*/
|
||||||
|
private static void checkCallerContextContainsClientIp(Set<String> clientIpInfos,
|
||||||
|
String callerContext) {
|
||||||
|
String clientIpInfo = null;
|
||||||
|
for (String curClientIpInfo : clientIpInfos) {
|
||||||
|
if (callerContext.contains(curClientIpInfo)) {
|
||||||
|
clientIpInfo = curClientIpInfo;
|
||||||
|
// assert client ip info appears only once in caller context
|
||||||
|
assertEquals(String.format("%s contains %s more than once", callerContext, clientIpInfo),
|
||||||
|
callerContext.indexOf(clientIpInfo), callerContext.lastIndexOf(clientIpInfo));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertNotNull(clientIpInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A local machine where we run tests may have more than 1 network interface,
|
||||||
|
* extracting all IP information from them.
|
||||||
|
*
|
||||||
|
* @return A set of 'clientIp:IP' where IP is taken from all local network interfaces.
|
||||||
|
* @throws SocketException
|
||||||
|
*/
|
||||||
|
private static Set<String> getClientIpInfos() throws SocketException {
|
||||||
|
Set<String> clientIpInfos = new HashSet<>();
|
||||||
|
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||||
|
while (networkInterfaces.hasMoreElements()) {
|
||||||
|
NetworkInterface networkInterface = networkInterfaces.nextElement();
|
||||||
|
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
|
||||||
|
while (inetAddresses.hasMoreElements()) {
|
||||||
|
InetAddress inetAddress = inetAddresses.nextElement();
|
||||||
|
clientIpInfos.add("clientIp:" + inetAddress.getHostAddress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return clientIpInfos;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user