Skip to content

Commit

Permalink
HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part4.
Browse files Browse the repository at this point in the history
  • Loading branch information
fanshilun committed Feb 7, 2025
1 parent 80ac7bf commit b12b81d
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public void testConfGetPassword() throws Exception {
// let's make sure that a password that doesn't exist returns an
// empty string as currently expected and used to trigger a call to
// extract password
assertEquals("", mapping.getPassword(conf,"invalid-alias", ""));
assertEquals("", mapping.getPassword(conf, "invalid-alias", ""));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,12 @@ public void testFiniteGroupResolutionTime() throws Exception {
ReflectionUtils.newInstance(TestDelayedGroupCommand.class, conf);

executor = mapping.createGroupExecutor(userName);
assertEquals(defaultTimeout,
executor.getTimeoutInterval(), "Expected the group names executor to carry the default timeout");
assertEquals(defaultTimeout, executor.getTimeoutInterval(),
"Expected the group names executor to carry the default timeout");

executor = mapping.createGroupIDExecutor(userName);
assertEquals(defaultTimeout,
executor.getTimeoutInterval(), "Expected the group ID executor to carry the default timeout");
assertEquals(defaultTimeout, executor.getTimeoutInterval(),
"Expected the group ID executor to carry the default timeout");

mapping.getGroups(userName);
assertFalse(shellMappingLog.getOutput().contains(commandTimeoutMessage),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ public void testUGILoginFromKeytab() throws Exception {

UserGroupInformation.loginUserFromKeytab(principal, keytab.getPath());
UserGroupInformation ugi = UserGroupInformation.getLoginUser();
assertTrue(
ugi.isFromKeytab(), "UGI should be configured to login from keytab");
assertTrue(ugi.isFromKeytab(),
"UGI should be configured to login from keytab");

User user = getUser(ugi.getSubject());
assertNotNull(user.getLogin());

assertTrue(
user.getLastLogin() > beforeLogin, "User login time is less than before login time, "
assertTrue(user.getLastLogin() > beforeLogin,
"User login time is less than before login time, "
+ "beforeLoginTime:" + beforeLogin + " userLoginTime:" + user.getLastLogin());
}

Expand All @@ -139,8 +139,7 @@ public void testUGIReLoginFromKeytab() throws Exception {

UserGroupInformation.loginUserFromKeytab(principal, keytab.getPath());
UserGroupInformation ugi = UserGroupInformation.getLoginUser();
assertTrue(
ugi.isFromKeytab(), "UGI should be configured to login from keytab");
assertTrue(ugi.isFromKeytab(), "UGI should be configured to login from keytab");

// Verify relogin from keytab.
User user = getUser(ugi.getSubject());
Expand All @@ -154,8 +153,8 @@ public void testUGIReLoginFromKeytab() throws Exception {
ugi.reloginFromKeytab();
final long secondLogin = user.getLastLogin();
final LoginContext login2 = user.getLogin();
assertTrue(
secondLogin > firstLogin, "User should have been able to relogin from keytab");
assertTrue(secondLogin > firstLogin,
"User should have been able to relogin from keytab");
assertNotNull(login2);
assertNotSame(login1, login2);
}
Expand All @@ -174,8 +173,7 @@ public void testUGIForceReLoginFromKeytab() throws Exception {

UserGroupInformation.loginUserFromKeytab(principal, keytab.getPath());
UserGroupInformation ugi = UserGroupInformation.getLoginUser();
assertTrue(
ugi.isFromKeytab(), "UGI should be configured to login from keytab");
assertTrue(ugi.isFromKeytab(), "UGI should be configured to login from keytab");

// Verify relogin from keytab.
User user = getUser(ugi.getSubject());
Expand All @@ -190,8 +188,8 @@ public void testUGIForceReLoginFromKeytab() throws Exception {
ugi.forceReloginFromKeytab();
final long secondLogin = user.getLastLogin();
final LoginContext login2 = user.getLogin();
assertTrue(
secondLogin > firstLogin, "User should have been able to relogin from keytab");
assertTrue(secondLogin > firstLogin,
"User should have been able to relogin from keytab");
assertNotNull(login2);
assertNotSame(login1, login2);
}
Expand Down Expand Up @@ -287,11 +285,9 @@ public void testUGIRefreshFromKeytab() throws Exception {
assertEquals(UserGroupInformation.AuthenticationMethod.KERBEROS,
ugi.getAuthenticationMethod());
assertTrue(ugi.isFromKeytab());
assertTrue(
UserGroupInformation.isKerberosKeyTabLoginRenewalEnabled());
assertTrue(
UserGroupInformation.getKerberosLoginRenewalExecutor()
.isPresent());
assertTrue(UserGroupInformation.isKerberosKeyTabLoginRenewalEnabled());
assertTrue(UserGroupInformation.getKerberosLoginRenewalExecutor()
.isPresent());
}

@Test
Expand All @@ -312,13 +308,11 @@ public void testUGIRefreshFromKeytabDisabled() throws Exception {

UserGroupInformation ugi = UserGroupInformation.getLoginUser();
assertEquals(UserGroupInformation.AuthenticationMethod.KERBEROS,
ugi.getAuthenticationMethod());
ugi.getAuthenticationMethod());
assertTrue(ugi.isFromKeytab());
assertFalse(
UserGroupInformation.isKerberosKeyTabLoginRenewalEnabled());
assertFalse(
UserGroupInformation.getKerberosLoginRenewalExecutor()
.isPresent());
assertFalse(UserGroupInformation.isKerberosKeyTabLoginRenewalEnabled());
assertFalse(UserGroupInformation.getKerberosLoginRenewalExecutor()
.isPresent());
}

private static KerberosTicket getTicket(UserGroupInformation ugi) {
Expand All @@ -331,10 +325,8 @@ private static KerberosTicket getTicket(UserGroupInformation ugi) {
// the expected principal.
private static KerberosTicket checkTicketAndKeytab(UserGroupInformation ugi,
KerberosPrincipal principal, boolean expectIsKeytab) {
assertEquals(
principal.getName(), ugi.getUserName(), "wrong principal");
assertEquals(
expectIsKeytab, ugi.isFromKeytab(), "is not keytab");
assertEquals(principal.getName(), ugi.getUserName(), "wrong principal");
assertEquals(expectIsKeytab, ugi.isFromKeytab(), "is not keytab");
KerberosTicket ticket = getTicket(ugi);
assertNotNull(ticket, "no ticket");
assertEquals(principal, ticket.getClient(), "wrong principal");
Expand Down Expand Up @@ -438,9 +430,9 @@ public Void run() throws IOException {
// original login user not affected.
extLoginUser.reloginFromKeytab();
assertSame(extLoginUserTicket,
checkTicketAndKeytab(extLoginUser, principal2, false));
checkTicketAndKeytab(extLoginUser, principal2, false));
assertSame(originalLoginUserTicket,
checkTicketAndKeytab(originalLoginUser, principal1, true));
checkTicketAndKeytab(originalLoginUser, principal1, true));

// verify original login user gets a new ticket, new login user
// not affected.
Expand Down Expand Up @@ -540,8 +532,7 @@ public Void call() throws Exception {
});
// wait for the thread to block on the barrier in the logout of the
// relogin.
assertTrue(
latch.await(2, TimeUnit.SECONDS), "first relogin didn't block");
assertTrue(latch.await(2, TimeUnit.SECONDS), "first relogin didn't block");

// although the logout removed the keytab instance, verify the ugi
// knows from its login params that it is supposed to be from a keytab.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void testEmptyArgForCommands() throws Exception {

for (String cmd : Arrays.asList("create", "delete")) {
shell.setConf(new Configuration());
assertEquals(1, shell.init(new String[] { cmd }),
assertEquals(1, shell.init(new String[]{cmd}),
"Expected empty argument on " + cmd + " to return 1");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,6 @@ public void checkPermissionRetention(Configuration conf, String ourUrl,
FileSystem fs = path.getFileSystem(conf);
FileStatus s = fs.getFileStatus(path);
assertEquals("rwxrwxrwx", s.getPermission().toString(),
"Permissions should have been retained from the preexisting keystore.");
"Permissions should have been retained from the preexisting keystore.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,21 @@ public void testAllowAllOrigins() throws ServletException, IOException {
public void testEncodeHeaders() {
String validOrigin = "http://localhost:12345";
String encodedValidOrigin = CrossOriginFilter.encodeHeader(validOrigin);
assertEquals(
validOrigin, encodedValidOrigin, "Valid origin encoding should match exactly");
assertEquals(validOrigin, encodedValidOrigin,
"Valid origin encoding should match exactly");

String httpResponseSplitOrigin = validOrigin + " \nSecondHeader: value";
String encodedResponseSplitOrigin =
CrossOriginFilter.encodeHeader(httpResponseSplitOrigin);
assertEquals(
validOrigin, encodedResponseSplitOrigin, "Http response split origin should be protected against");
assertEquals(validOrigin, encodedResponseSplitOrigin,
"Http response split origin should be protected against");

// Test Origin List
String validOriginList = "http://foo.example.com:12345 http://bar.example.com:12345";
String encodedValidOriginList = CrossOriginFilter
.encodeHeader(validOriginList);
assertEquals(
validOriginList, encodedValidOriginList, "Valid origin list encoding should match exactly");
assertEquals(validOriginList, encodedValidOriginList,
"Valid origin list encoding should match exactly");
}

@Test
Expand Down Expand Up @@ -348,12 +348,10 @@ public void testCrossOriginFilterAfterRestart() throws ServletException {
filter.init(filterConfig);

//verify filter values
assertTrue(
filter.getAllowedHeadersHeader()
.compareTo("X-Requested-With,Accept") == 0, "Allowed headers do not match");
assertTrue(
filter.getAllowedMethodsHeader()
.compareTo("GET,POST") == 0, "Allowed methods do not match");
assertTrue(filter.getAllowedHeadersHeader().
compareTo("X-Requested-With,Accept") == 0, "Allowed headers do not match");
assertTrue(filter.getAllowedMethodsHeader().
compareTo("GET,POST") == 0, "Allowed methods do not match");
assertTrue(filter.areOriginsAllowed("example.com"));

//destroy filter values and clear conf
Expand All @@ -370,12 +368,10 @@ public void testCrossOriginFilterAfterRestart() throws ServletException {
filter.init(filterConfig);

//verify filter values
assertTrue(
filter.getAllowedHeadersHeader()
.compareTo("Content-Type,Origin") == 0, "Allowed headers do not match");
assertTrue(
filter.getAllowedMethodsHeader()
.compareTo("GET,HEAD") == 0, "Allowed methods do not match");
assertTrue(filter.getAllowedHeadersHeader().compareTo("Content-Type,Origin") == 0,
"Allowed headers do not match");
assertTrue(filter.getAllowedMethodsHeader().compareTo("GET,HEAD") == 0,
"Allowed methods do not match");
assertTrue(filter.areOriginsAllowed("newexample.com"));

//destroy filter values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
assertTrue(
"DENY".equals(args[1]), "Options value incorrect should be DENY but is: "
+ args[1]);
assertTrue("DENY".equals(args[1]),
"Options value incorrect should be DENY but is: " + args[1]);
headers.add((String)args[1]);
return null;
}
Expand Down
Loading

0 comments on commit b12b81d

Please sign in to comment.