Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

package org.apache.hadoop.mapreduce.security;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;

import org.apache.hadoop.security.token.SecretManager;
import org.apache.hadoop.test.LambdaTestUtils;
import org.junit.Assert;

import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class TestJHSSecurity {
LoggerFactory.getLogger(TestJHSSecurity.class);

@Test
public void testDelegationToken() throws IOException, InterruptedException {
public void testDelegationToken() throws Exception {

org.apache.log4j.Logger rootLogger = LogManager.getRootLogger();
rootLogger.setLevel(Level.DEBUG);
Expand All @@ -80,7 +81,7 @@ public void testDelegationToken() throws IOException, InterruptedException {
final long renewInterval = 10000l;

JobHistoryServer jobHistoryServer = null;
MRClientProtocol clientUsingDT = null;
MRClientProtocol clientUsingDT;
long tokenFetchTime;
try {
jobHistoryServer = new JobHistoryServer() {
Expand Down Expand Up @@ -155,14 +156,11 @@ protected JHSDelegationTokenSecretManager createJHSSecretManager(
}
Thread.sleep(50l);
LOG.info("At time: " + System.currentTimeMillis() + ", token should be invalid");
// Token should have expired.
try {
clientUsingDT.getJobReport(jobReportRequest);
fail("Should not have succeeded with an expired token");
} catch (IOException e) {
assertTrue(e.getCause().getMessage().contains("is expired"));
}

// Token should have expired.
final MRClientProtocol finalClientUsingDT = clientUsingDT;
LambdaTestUtils.intercept(SecretManager.InvalidToken.class, "has expired",
() -> finalClientUsingDT.getJobReport(jobReportRequest));

// Test cancellation
// Stop the existing proxy, start another.
if (clientUsingDT != null) {
Expand Down