Skip to content

Commit b12b81d

Browse files
author
fanshilun
committed
HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part4.
1 parent 80ac7bf commit b12b81d

11 files changed

+343
-357
lines changed

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public void testConfGetPassword() throws Exception {
353353
// let's make sure that a password that doesn't exist returns an
354354
// empty string as currently expected and used to trigger a call to
355355
// extract password
356-
assertEquals("", mapping.getPassword(conf,"invalid-alias", ""));
356+
assertEquals("", mapping.getPassword(conf, "invalid-alias", ""));
357357
}
358358

359359
@Test

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestShellBasedUnixGroupsMapping.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,12 @@ public void testFiniteGroupResolutionTime() throws Exception {
337337
ReflectionUtils.newInstance(TestDelayedGroupCommand.class, conf);
338338

339339
executor = mapping.createGroupExecutor(userName);
340-
assertEquals(defaultTimeout,
341-
executor.getTimeoutInterval(), "Expected the group names executor to carry the default timeout");
340+
assertEquals(defaultTimeout, executor.getTimeoutInterval(),
341+
"Expected the group names executor to carry the default timeout");
342342

343343
executor = mapping.createGroupIDExecutor(userName);
344-
assertEquals(defaultTimeout,
345-
executor.getTimeoutInterval(), "Expected the group ID executor to carry the default timeout");
344+
assertEquals(defaultTimeout, executor.getTimeoutInterval(),
345+
"Expected the group ID executor to carry the default timeout");
346346

347347
mapping.getGroups(userName);
348348
assertFalse(shellMappingLog.getOutput().contains(commandTimeoutMessage),

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUGILoginFromKeytab.java

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ public void testUGILoginFromKeytab() throws Exception {
116116

117117
UserGroupInformation.loginUserFromKeytab(principal, keytab.getPath());
118118
UserGroupInformation ugi = UserGroupInformation.getLoginUser();
119-
assertTrue(
120-
ugi.isFromKeytab(), "UGI should be configured to login from keytab");
119+
assertTrue(ugi.isFromKeytab(),
120+
"UGI should be configured to login from keytab");
121121

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

125-
assertTrue(
126-
user.getLastLogin() > beforeLogin, "User login time is less than before login time, "
125+
assertTrue(user.getLastLogin() > beforeLogin,
126+
"User login time is less than before login time, "
127127
+ "beforeLoginTime:" + beforeLogin + " userLoginTime:" + user.getLastLogin());
128128
}
129129

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

140140
UserGroupInformation.loginUserFromKeytab(principal, keytab.getPath());
141141
UserGroupInformation ugi = UserGroupInformation.getLoginUser();
142-
assertTrue(
143-
ugi.isFromKeytab(), "UGI should be configured to login from keytab");
142+
assertTrue(ugi.isFromKeytab(), "UGI should be configured to login from keytab");
144143

145144
// Verify relogin from keytab.
146145
User user = getUser(ugi.getSubject());
@@ -154,8 +153,8 @@ public void testUGIReLoginFromKeytab() throws Exception {
154153
ugi.reloginFromKeytab();
155154
final long secondLogin = user.getLastLogin();
156155
final LoginContext login2 = user.getLogin();
157-
assertTrue(
158-
secondLogin > firstLogin, "User should have been able to relogin from keytab");
156+
assertTrue(secondLogin > firstLogin,
157+
"User should have been able to relogin from keytab");
159158
assertNotNull(login2);
160159
assertNotSame(login1, login2);
161160
}
@@ -174,8 +173,7 @@ public void testUGIForceReLoginFromKeytab() throws Exception {
174173

175174
UserGroupInformation.loginUserFromKeytab(principal, keytab.getPath());
176175
UserGroupInformation ugi = UserGroupInformation.getLoginUser();
177-
assertTrue(
178-
ugi.isFromKeytab(), "UGI should be configured to login from keytab");
176+
assertTrue(ugi.isFromKeytab(), "UGI should be configured to login from keytab");
179177

180178
// Verify relogin from keytab.
181179
User user = getUser(ugi.getSubject());
@@ -190,8 +188,8 @@ public void testUGIForceReLoginFromKeytab() throws Exception {
190188
ugi.forceReloginFromKeytab();
191189
final long secondLogin = user.getLastLogin();
192190
final LoginContext login2 = user.getLogin();
193-
assertTrue(
194-
secondLogin > firstLogin, "User should have been able to relogin from keytab");
191+
assertTrue(secondLogin > firstLogin,
192+
"User should have been able to relogin from keytab");
195193
assertNotNull(login2);
196194
assertNotSame(login1, login2);
197195
}
@@ -287,11 +285,9 @@ public void testUGIRefreshFromKeytab() throws Exception {
287285
assertEquals(UserGroupInformation.AuthenticationMethod.KERBEROS,
288286
ugi.getAuthenticationMethod());
289287
assertTrue(ugi.isFromKeytab());
290-
assertTrue(
291-
UserGroupInformation.isKerberosKeyTabLoginRenewalEnabled());
292-
assertTrue(
293-
UserGroupInformation.getKerberosLoginRenewalExecutor()
294-
.isPresent());
288+
assertTrue(UserGroupInformation.isKerberosKeyTabLoginRenewalEnabled());
289+
assertTrue(UserGroupInformation.getKerberosLoginRenewalExecutor()
290+
.isPresent());
295291
}
296292

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

313309
UserGroupInformation ugi = UserGroupInformation.getLoginUser();
314310
assertEquals(UserGroupInformation.AuthenticationMethod.KERBEROS,
315-
ugi.getAuthenticationMethod());
311+
ugi.getAuthenticationMethod());
316312
assertTrue(ugi.isFromKeytab());
317-
assertFalse(
318-
UserGroupInformation.isKerberosKeyTabLoginRenewalEnabled());
319-
assertFalse(
320-
UserGroupInformation.getKerberosLoginRenewalExecutor()
321-
.isPresent());
313+
assertFalse(UserGroupInformation.isKerberosKeyTabLoginRenewalEnabled());
314+
assertFalse(UserGroupInformation.getKerberosLoginRenewalExecutor()
315+
.isPresent());
322316
}
323317

324318
private static KerberosTicket getTicket(UserGroupInformation ugi) {
@@ -331,10 +325,8 @@ private static KerberosTicket getTicket(UserGroupInformation ugi) {
331325
// the expected principal.
332326
private static KerberosTicket checkTicketAndKeytab(UserGroupInformation ugi,
333327
KerberosPrincipal principal, boolean expectIsKeytab) {
334-
assertEquals(
335-
principal.getName(), ugi.getUserName(), "wrong principal");
336-
assertEquals(
337-
expectIsKeytab, ugi.isFromKeytab(), "is not keytab");
328+
assertEquals(principal.getName(), ugi.getUserName(), "wrong principal");
329+
assertEquals(expectIsKeytab, ugi.isFromKeytab(), "is not keytab");
338330
KerberosTicket ticket = getTicket(ugi);
339331
assertNotNull(ticket, "no ticket");
340332
assertEquals(principal, ticket.getClient(), "wrong principal");
@@ -438,9 +430,9 @@ public Void run() throws IOException {
438430
// original login user not affected.
439431
extLoginUser.reloginFromKeytab();
440432
assertSame(extLoginUserTicket,
441-
checkTicketAndKeytab(extLoginUser, principal2, false));
433+
checkTicketAndKeytab(extLoginUser, principal2, false));
442434
assertSame(originalLoginUserTicket,
443-
checkTicketAndKeytab(originalLoginUser, principal1, true));
435+
checkTicketAndKeytab(originalLoginUser, principal1, true));
444436

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

546537
// although the logout removed the keytab instance, verify the ugi
547538
// knows from its login params that it is supposed to be from a keytab.

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredShell.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public void testEmptyArgForCommands() throws Exception {
263263

264264
for (String cmd : Arrays.asList("create", "delete")) {
265265
shell.setConf(new Configuration());
266-
assertEquals(1, shell.init(new String[] { cmd }),
266+
assertEquals(1, shell.init(new String[]{cmd}),
267267
"Expected empty argument on " + cmd + " to return 1");
268268
}
269269
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredentialProviderFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,6 @@ public void checkPermissionRetention(Configuration conf, String ourUrl,
277277
FileSystem fs = path.getFileSystem(conf);
278278
FileStatus s = fs.getFileStatus(path);
279279
assertEquals("rwxrwxrwx", s.getPermission().toString(),
280-
"Permissions should have been retained from the preexisting keystore.");
280+
"Permissions should have been retained from the preexisting keystore.");
281281
}
282282
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/http/TestCrossOriginFilter.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@ public void testAllowAllOrigins() throws ServletException, IOException {
8888
public void testEncodeHeaders() {
8989
String validOrigin = "http://localhost:12345";
9090
String encodedValidOrigin = CrossOriginFilter.encodeHeader(validOrigin);
91-
assertEquals(
92-
validOrigin, encodedValidOrigin, "Valid origin encoding should match exactly");
91+
assertEquals(validOrigin, encodedValidOrigin,
92+
"Valid origin encoding should match exactly");
9393

9494
String httpResponseSplitOrigin = validOrigin + " \nSecondHeader: value";
9595
String encodedResponseSplitOrigin =
9696
CrossOriginFilter.encodeHeader(httpResponseSplitOrigin);
97-
assertEquals(
98-
validOrigin, encodedResponseSplitOrigin, "Http response split origin should be protected against");
97+
assertEquals(validOrigin, encodedResponseSplitOrigin,
98+
"Http response split origin should be protected against");
9999

100100
// Test Origin List
101101
String validOriginList = "http://foo.example.com:12345 http://bar.example.com:12345";
102102
String encodedValidOriginList = CrossOriginFilter
103103
.encodeHeader(validOriginList);
104-
assertEquals(
105-
validOriginList, encodedValidOriginList, "Valid origin list encoding should match exactly");
104+
assertEquals(validOriginList, encodedValidOriginList,
105+
"Valid origin list encoding should match exactly");
106106
}
107107

108108
@Test
@@ -348,12 +348,10 @@ public void testCrossOriginFilterAfterRestart() throws ServletException {
348348
filter.init(filterConfig);
349349

350350
//verify filter values
351-
assertTrue(
352-
filter.getAllowedHeadersHeader()
353-
.compareTo("X-Requested-With,Accept") == 0, "Allowed headers do not match");
354-
assertTrue(
355-
filter.getAllowedMethodsHeader()
356-
.compareTo("GET,POST") == 0, "Allowed methods do not match");
351+
assertTrue(filter.getAllowedHeadersHeader().
352+
compareTo("X-Requested-With,Accept") == 0, "Allowed headers do not match");
353+
assertTrue(filter.getAllowedMethodsHeader().
354+
compareTo("GET,POST") == 0, "Allowed methods do not match");
357355
assertTrue(filter.areOriginsAllowed("example.com"));
358356

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

372370
//verify filter values
373-
assertTrue(
374-
filter.getAllowedHeadersHeader()
375-
.compareTo("Content-Type,Origin") == 0, "Allowed headers do not match");
376-
assertTrue(
377-
filter.getAllowedMethodsHeader()
378-
.compareTo("GET,HEAD") == 0, "Allowed methods do not match");
371+
assertTrue(filter.getAllowedHeadersHeader().compareTo("Content-Type,Origin") == 0,
372+
"Allowed headers do not match");
373+
assertTrue(filter.getAllowedMethodsHeader().compareTo("GET,HEAD") == 0,
374+
"Allowed methods do not match");
379375
assertTrue(filter.areOriginsAllowed("newexample.com"));
380376

381377
//destroy filter values

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/http/TestXFrameOptionsFilter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
7070
@Override
7171
public Object answer(InvocationOnMock invocation) throws Throwable {
7272
Object[] args = invocation.getArguments();
73-
assertTrue(
74-
"DENY".equals(args[1]), "Options value incorrect should be DENY but is: "
75-
+ args[1]);
73+
assertTrue("DENY".equals(args[1]),
74+
"Options value incorrect should be DENY but is: " + args[1]);
7675
headers.add((String)args[1]);
7776
return null;
7877
}

0 commit comments

Comments
 (0)