MAPREDUCE-7387. Fix TestJHSSecurity#testDelegationToken AssertionError due to HDFS-16563 (#4428). Contributed by fanshilun.

Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
slfan1989 2022-06-19 23:44:04 -07:00 committed by GitHub
parent 477b67a335
commit 10fc865d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,7 +18,6 @@
package org.apache.hadoop.mapreduce.security; package org.apache.hadoop.mapreduce.security;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
@ -26,6 +25,8 @@
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import org.apache.hadoop.security.token.SecretManager;
import org.apache.hadoop.test.LambdaTestUtils;
import org.junit.Assert; import org.junit.Assert;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -61,7 +62,7 @@ public class TestJHSSecurity {
LoggerFactory.getLogger(TestJHSSecurity.class); LoggerFactory.getLogger(TestJHSSecurity.class);
@Test @Test
public void testDelegationToken() throws IOException, InterruptedException { public void testDelegationToken() throws Exception {
org.apache.log4j.Logger rootLogger = LogManager.getRootLogger(); org.apache.log4j.Logger rootLogger = LogManager.getRootLogger();
rootLogger.setLevel(Level.DEBUG); rootLogger.setLevel(Level.DEBUG);
@ -80,7 +81,7 @@ public void testDelegationToken() throws IOException, InterruptedException {
final long renewInterval = 10000l; final long renewInterval = 10000l;
JobHistoryServer jobHistoryServer = null; JobHistoryServer jobHistoryServer = null;
MRClientProtocol clientUsingDT = null; MRClientProtocol clientUsingDT;
long tokenFetchTime; long tokenFetchTime;
try { try {
jobHistoryServer = new JobHistoryServer() { jobHistoryServer = new JobHistoryServer() {
@ -156,12 +157,9 @@ protected JHSDelegationTokenSecretManager createJHSSecretManager(
Thread.sleep(50l); Thread.sleep(50l);
LOG.info("At time: " + System.currentTimeMillis() + ", token should be invalid"); LOG.info("At time: " + System.currentTimeMillis() + ", token should be invalid");
// Token should have expired. // Token should have expired.
try { final MRClientProtocol finalClientUsingDT = clientUsingDT;
clientUsingDT.getJobReport(jobReportRequest); LambdaTestUtils.intercept(SecretManager.InvalidToken.class, "has expired",
fail("Should not have succeeded with an expired token"); () -> finalClientUsingDT.getJobReport(jobReportRequest));
} catch (IOException e) {
assertTrue(e.getCause().getMessage().contains("is expired"));
}
// Test cancellation // Test cancellation
// Stop the existing proxy, start another. // Stop the existing proxy, start another.