Skip to content

Commit 7063d58

Browse files
slfan1989anujmodi2021cnauroth
authored
HADOOP-19617. [JDK17] Remove JUnit4 Dependency. (#7957)
* HADOOP-19617 - [JDK17] Remove JUnit4 Dependency. Co-authored-by: Anuj Modi <[email protected]> Co-authored-by: Chris Nauroth <[email protected]> Reviewed-by: Anuj Modi <[email protected]> Reviewed-by: Chris Nauroth <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent b4b778e commit 7063d58

File tree

14 files changed

+127
-221
lines changed

14 files changed

+127
-221
lines changed

hadoop-client-modules/hadoop-client-minicluster/pom.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@
5151
<artifactId>hadoop-client-runtime</artifactId>
5252
<scope>runtime</scope>
5353
</dependency>
54-
<!-- Leave JUnit as a direct dependency -->
55-
<dependency>
56-
<groupId>junit</groupId>
57-
<artifactId>junit</artifactId>
58-
<scope>runtime</scope>
59-
</dependency>
6054
<!-- Adding hadoop-annotations so we can make it optional to remove from our transitive tree -->
6155
<dependency>
6256
<groupId>org.apache.hadoop</groupId>
@@ -629,6 +623,10 @@
629623
<groupId>jakarta.servlet</groupId>
630624
<artifactId>jakarta.servlet-api</artifactId>
631625
</exclusion>
626+
<exclusion>
627+
<artifactId>junit-jupiter</artifactId>
628+
<groupId>org.junit.jupiter</groupId>
629+
</exclusion>
632630
</exclusions>
633631
<optional>true</optional>
634632
</dependency>
@@ -640,6 +638,10 @@
640638
<groupId>jakarta.ws.rs</groupId>
641639
<artifactId>jakarta.ws.rs-api</artifactId>
642640
</exclusion>
641+
<exclusion>
642+
<artifactId>junit-jupiter</artifactId>
643+
<groupId>org.junit.jupiter</groupId>
644+
</exclusion>
643645
</exclusions>
644646
<optional>true</optional>
645647
</dependency>

hadoop-common-project/hadoop-auth/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,26 @@
204204
<artifactId>assertj-core</artifactId>
205205
<scope>test</scope>
206206
</dependency>
207+
<dependency>
208+
<groupId>org.junit.jupiter</groupId>
209+
<artifactId>junit-jupiter-api</artifactId>
210+
<scope>test</scope>
211+
</dependency>
212+
<dependency>
213+
<groupId>org.junit.jupiter</groupId>
214+
<artifactId>junit-jupiter-engine</artifactId>
215+
<scope>test</scope>
216+
</dependency>
217+
<dependency>
218+
<groupId>org.junit.jupiter</groupId>
219+
<artifactId>junit-jupiter-params</artifactId>
220+
<scope>test</scope>
221+
</dependency>
222+
<dependency>
223+
<groupId>org.junit.platform</groupId>
224+
<artifactId>junit-platform-launcher</artifactId>
225+
<scope>test</scope>
226+
</dependency>
207227
</dependencies>
208228

209229
<build>

hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/util/TestZookeeperClientCreation.java

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import org.apache.zookeeper.ZooDefs;
2525
import org.apache.zookeeper.client.ZKClientConfig;
2626
import org.apache.zookeeper.common.ClientX509Util;
27-
import org.hamcrest.Matcher;
28-
import org.hamcrest.core.IsNull;
2927
import org.junit.jupiter.api.BeforeEach;
3028
import org.junit.jupiter.api.Test;
3129
import org.mockito.ArgumentCaptor;
@@ -35,10 +33,7 @@
3533

3634
import java.util.Arrays;
3735

38-
import static org.hamcrest.CoreMatchers.anyOf;
39-
import static org.hamcrest.CoreMatchers.containsString;
40-
import static org.hamcrest.CoreMatchers.is;
41-
import static org.hamcrest.MatcherAssert.assertThat;
36+
import static org.assertj.core.api.Assertions.assertThat;
4237
import static org.junit.jupiter.api.Assertions.assertThrows;
4338
import static org.mockito.ArgumentCaptor.forClass;
4439
import static org.mockito.ArgumentMatchers.isA;
@@ -219,14 +214,18 @@ public void testSSLConfiguration() {
219214
verify(cfBuilder).zkClientConfig(clientConfCaptor.capture());
220215
ZKClientConfig conf = clientConfCaptor.getValue();
221216

222-
assertThat(conf.getProperty(ZKClientConfig.SECURE_CLIENT), is("true"));
223-
assertThat(conf.getProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET),
224-
is("org.apache.zookeeper.ClientCnxnSocketNetty"));
217+
assertThat(conf.getProperty(ZKClientConfig.SECURE_CLIENT)).isEqualTo("true");
218+
assertThat(conf.getProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET))
219+
.isEqualTo("org.apache.zookeeper.ClientCnxnSocketNetty");
225220
try (ClientX509Util sslOpts = new ClientX509Util()) {
226-
assertThat(conf.getProperty(sslOpts.getSslKeystoreLocationProperty()), is("keystoreLoc"));
227-
assertThat(conf.getProperty(sslOpts.getSslKeystorePasswdProperty()), is("ksPass"));
228-
assertThat(conf.getProperty(sslOpts.getSslTruststoreLocationProperty()), is("truststoreLoc"));
229-
assertThat(conf.getProperty(sslOpts.getSslTruststorePasswdProperty()), is("tsPass"));
221+
assertThat(conf.getProperty(sslOpts.getSslKeystoreLocationProperty()))
222+
.isEqualTo("keystoreLoc");
223+
assertThat(conf.getProperty(sslOpts.getSslKeystorePasswdProperty()))
224+
.isEqualTo("ksPass");
225+
assertThat(conf.getProperty(sslOpts.getSslTruststoreLocationProperty()))
226+
.isEqualTo("truststoreLoc");
227+
assertThat(conf.getProperty(sslOpts.getSslTruststorePasswdProperty()))
228+
.isEqualTo("tsPass");
230229
}
231230

232231
verifyDummyConnectionString();
@@ -244,39 +243,39 @@ public void testNoConnectionString(){
244243
clientConfigurer.withConnectionString(null);
245244

246245
Throwable t = assertThrows(NullPointerException.class, () -> clientConfigurer.create());
247-
assertThat(t.getMessage(), containsString("Zookeeper connection string cannot be null!"));
246+
assertThat(t.getMessage()).contains("Zookeeper connection string cannot be null!");
248247
}
249248

250249
@Test
251250
public void testNoRetryPolicy() {
252251
clientConfigurer.withRetryPolicy(null);
253252

254253
Throwable t = assertThrows(NullPointerException.class, () -> clientConfigurer.create());
255-
assertThat(t.getMessage(), containsString("Zookeeper connection retry policy cannot be null!"));
254+
assertThat(t.getMessage()).contains("Zookeeper connection retry policy cannot be null!");
256255
}
257256

258257
@Test
259258
public void testNoAuthType() {
260259
clientConfigurer.withAuthType(null);
261260

262261
Throwable t = assertThrows(NullPointerException.class, () -> clientConfigurer.create());
263-
assertThat(t.getMessage(), containsString("Zookeeper authType cannot be null!"));
262+
assertThat(t.getMessage()).contains("Zookeeper authType cannot be null!");
264263
}
265264

266265
@Test
267266
public void testUnrecognizedAuthType() {
268267
clientConfigurer.withAuthType("something");
269268

270269
Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
271-
assertThat(t.getMessage(), is("Zookeeper authType must be one of [none, sasl]!"));
270+
assertThat(t.getMessage()).isEqualTo("Zookeeper authType must be one of [none, sasl]!");
272271
}
273272

274273
@Test
275274
public void testSaslAuthTypeWithoutKeytab() {
276275
clientConfigurer.withAuthType("sasl");
277276

278277
Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
279-
assertThat(t.getMessage(), is("Zookeeper client's Kerberos Keytab must be specified!"));
278+
assertThat(t.getMessage()).isEqualTo("Zookeeper client's Kerberos Keytab must be specified!");
280279
}
281280

282281
@Test
@@ -286,7 +285,8 @@ public void testSaslAuthTypeWithEmptyKeytab() {
286285
.withKeytab("");
287286

288287
Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
289-
assertThat(t.getMessage(), is("Zookeeper client's Kerberos Keytab must be specified!"));
288+
289+
assertThat(t.getMessage()).isEqualTo("Zookeeper client's Kerberos Keytab must be specified!");
290290
}
291291

292292
@Test
@@ -296,7 +296,8 @@ public void testSaslAuthTypeWithoutPrincipal() {
296296
.withKeytab("keytabLoc");
297297

298298
Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
299-
assertThat(t.getMessage(), is("Zookeeper client's Kerberos Principal must be specified!"));
299+
assertThat(t.getMessage()).isEqualTo(
300+
"Zookeeper client's Kerberos Principal must be specified!");
300301
}
301302

302303
@Test
@@ -307,7 +308,8 @@ public void testSaslAuthTypeWithEmptyPrincipal() {
307308
.withPrincipal("");
308309

309310
Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
310-
assertThat(t.getMessage(), is("Zookeeper client's Kerberos Principal must be specified!"));
311+
assertThat(t.getMessage()).isEqualTo(
312+
"Zookeeper client's Kerberos Principal must be specified!");
311313
}
312314

313315
@Test
@@ -319,7 +321,7 @@ public void testSaslAuthTypeWithoutJaasLoginEntryName() {
319321
.withJaasLoginEntryName(null);
320322

321323
Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
322-
assertThat(t.getMessage(), is("JAAS Login Entry name must be specified!"));
324+
assertThat(t.getMessage()).isEqualTo("JAAS Login Entry name must be specified!");
323325
}
324326

325327
@Test
@@ -331,7 +333,7 @@ public void testSaslAuthTypeWithEmptyJaasLoginEntryName() {
331333
.withJaasLoginEntryName("");
332334

333335
Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
334-
assertThat(t.getMessage(), is("JAAS Login Entry name must be specified!"));
336+
assertThat(t.getMessage()).isEqualTo("JAAS Login Entry name must be specified!");
335337
}
336338

337339
@Test
@@ -340,8 +342,8 @@ public void testSSLWithoutKeystore() {
340342
.enableSSL(true);
341343

342344
Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
343-
assertThat(t.getMessage(),
344-
is("The keystore location parameter is empty for the ZooKeeper client connection."));
345+
assertThat(t.getMessage()).isEqualTo(
346+
"The keystore location parameter is empty for the ZooKeeper client connection.");
345347
}
346348

347349
@Test
@@ -351,8 +353,8 @@ public void testSSLWithEmptyKeystore() {
351353
.withKeystore("");
352354

353355
Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
354-
assertThat(t.getMessage(),
355-
is("The keystore location parameter is empty for the ZooKeeper client connection."));
356+
assertThat(t.getMessage()).isEqualTo(
357+
"The keystore location parameter is empty for the ZooKeeper client connection.");
356358
}
357359

358360
@Test
@@ -362,8 +364,8 @@ public void testSSLWithoutTruststore() {
362364
.withKeystore("keyStoreLoc");
363365

364366
Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
365-
assertThat(t.getMessage(),
366-
is("The truststore location parameter is empty for the ZooKeeper client connection."));
367+
assertThat(t.getMessage()).isEqualTo(
368+
"The truststore location parameter is empty for the ZooKeeper client connection.");
367369
}
368370

369371
@Test
@@ -374,8 +376,8 @@ public void testSSLWithEmptyTruststore() {
374376
.withTruststore("");
375377

376378
Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
377-
assertThat(t.getMessage(),
378-
is("The truststore location parameter is empty for the ZooKeeper client connection."));
379+
assertThat(t.getMessage()).isEqualTo(
380+
"The truststore location parameter is empty for the ZooKeeper client connection.");
379381
}
380382

381383
private void testSaslAuthType(String vendor) {
@@ -395,36 +397,39 @@ private void testSaslAuthType(String vendor) {
395397
verify(cfBuilder).aclProvider(aclProviderCaptor.capture());
396398
SASLOwnerACLProvider aclProvider = aclProviderCaptor.getValue();
397399

398-
assertThat(aclProvider.getDefaultAcl().size(), is(1));
399-
assertThat(aclProvider.getDefaultAcl().get(0).getId().getScheme(), is("sasl"));
400-
assertThat(aclProvider.getDefaultAcl().get(0).getId().getId(), is("principal"));
401-
assertThat(aclProvider.getDefaultAcl().get(0).getPerms(), is(ZooDefs.Perms.ALL));
400+
assertThat(aclProvider.getDefaultAcl().size()).isEqualTo(1);
401+
assertThat(aclProvider.getDefaultAcl().get(0).getId().getScheme()).isEqualTo("sasl");
402+
assertThat(aclProvider.getDefaultAcl().get(0).getId().getId()).isEqualTo("principal");
403+
assertThat(aclProvider.getDefaultAcl().get(0).getPerms()).isEqualTo(ZooDefs.Perms.ALL);
402404

403405
Arrays.stream(new String[] {"/", "/foo", "/foo/bar/baz", "/random/path"})
404406
.forEach(s -> {
405-
assertThat(aclProvider.getAclForPath(s).size(), is(1));
406-
assertThat(aclProvider.getAclForPath(s).get(0).getId().getScheme(), is("sasl"));
407-
assertThat(aclProvider.getAclForPath(s).get(0).getId().getId(), is("principal"));
408-
assertThat(aclProvider.getAclForPath(s).get(0).getPerms(), is(ZooDefs.Perms.ALL));
407+
assertThat(aclProvider.getAclForPath(s).size()).isEqualTo(1);
408+
assertThat(aclProvider.getAclForPath(s).get(0).getId().getScheme()).isEqualTo("sasl");
409+
assertThat(aclProvider.getAclForPath(s).get(0).getId().getId()).isEqualTo("principal");
410+
assertThat(aclProvider.getAclForPath(s).get(0).getPerms()).isEqualTo(ZooDefs.Perms.ALL);
409411
});
410412

411-
assertThat(System.getProperty(ZKClientConfig.LOGIN_CONTEXT_NAME_KEY), is("TestEntry"));
412-
assertThat(System.getProperty("zookeeper.authProvider.1"),
413-
is("org.apache.zookeeper.server.auth.SASLAuthenticationProvider"));
413+
assertThat(System.getProperty(ZKClientConfig.LOGIN_CONTEXT_NAME_KEY)).isEqualTo("TestEntry");
414+
assertThat(System.getProperty("zookeeper.authProvider.1")).isEqualTo(
415+
"org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
414416

415417
Configuration config = Configuration.getConfiguration();
416-
assertThat(config.getAppConfigurationEntry("TestEntry").length, is(1));
418+
assertThat(config.getAppConfigurationEntry("TestEntry").length).isEqualTo(1);
417419
AppConfigurationEntry entry = config.getAppConfigurationEntry("TestEntry")[0];
418-
assertThat(entry.getOptions().get("keyTab"), is("keytabLoc"));
419-
assertThat(entry.getOptions().get("principal"), is("[email protected]/SOME.REALM"));
420-
assertThat(entry.getOptions().get("useKeyTab"), is("true"));
421-
assertThat(entry.getOptions().get("storeKey"), is("true"));
422-
assertThat(entry.getOptions().get("useTicketCache"), is("false"));
423-
assertThat(entry.getOptions().get("refreshKrb5Config"), is("true"));
420+
assertThat(entry.getOptions().get("keyTab")).isEqualTo("keytabLoc");
421+
assertThat(entry.getOptions().get("principal")).isEqualTo("[email protected]/SOME.REALM");
422+
assertThat(entry.getOptions().get("useKeyTab")).isEqualTo("true");
423+
assertThat(entry.getOptions().get("storeKey")).isEqualTo("true");
424+
assertThat(entry.getOptions().get("useTicketCache")).isEqualTo("false");
425+
assertThat(entry.getOptions().get("refreshKrb5Config")).isEqualTo("true");
426+
424427
if (System.getProperty("java.vendor").contains("IBM")){
425-
assertThat(entry.getLoginModuleName(), is("com.ibm.security.auth.module.Krb5LoginModule"));
428+
assertThat(entry.getLoginModuleName()).isEqualTo(
429+
"com.ibm.security.auth.module.Krb5LoginModule");
426430
} else {
427-
assertThat(entry.getLoginModuleName(), is("com.sun.security.auth.module.Krb5LoginModule"));
431+
assertThat(entry.getLoginModuleName()).isEqualTo(
432+
"com.sun.security.auth.module.Krb5LoginModule");
428433
}
429434
} finally {
430435
Configuration.setConfiguration(origConf);
@@ -465,8 +470,8 @@ private void verifyDefaultRetryPolicy() {
465470
verify(cfBuilder).retryPolicy(retry.capture());
466471
ExponentialBackoffRetry policy = retry.getValue();
467472

468-
assertThat(policy.getBaseSleepTimeMs(), is(1000));
469-
assertThat(policy.getN(), is(3));
473+
assertThat(policy.getBaseSleepTimeMs()).isEqualTo(1000);
474+
assertThat(policy.getN()).isEqualTo(3);
470475
}
471476

472477
private void verifyDefaultAclProvider() {
@@ -478,21 +483,16 @@ private void verifyDefaultZKClientConfig() {
478483
verify(cfBuilder).zkClientConfig(clientConfCaptor.capture());
479484
ZKClientConfig conf = clientConfCaptor.getValue();
480485

481-
assertThat(conf.getProperty(ZKClientConfig.SECURE_CLIENT), isEmptyOrFalse());
486+
assertThat(conf.getProperty(ZKClientConfig.SECURE_CLIENT))
487+
.satisfiesAnyOf(value -> assertThat(value).isNullOrEmpty(),
488+
value -> assertThat(value).isEqualTo("false"));
489+
482490
try (ClientX509Util sslOpts = new ClientX509Util()) {
483-
assertThat(conf.getProperty(sslOpts.getSslKeystoreLocationProperty()), isEmpty());
484-
assertThat(conf.getProperty(sslOpts.getSslKeystorePasswdProperty()), isEmpty());
485-
assertThat(conf.getProperty(sslOpts.getSslTruststoreLocationProperty()), isEmpty());
486-
assertThat(conf.getProperty(sslOpts.getSslTruststorePasswdProperty()), isEmpty());
491+
assertThat(conf.getProperty(sslOpts.getSslKeystoreLocationProperty())).isNullOrEmpty();
492+
assertThat(conf.getProperty(sslOpts.getSslKeystorePasswdProperty())).isNullOrEmpty();
493+
assertThat(conf.getProperty(sslOpts.getSslTruststoreLocationProperty())).isNullOrEmpty();
494+
assertThat(conf.getProperty(sslOpts.getSslTruststorePasswdProperty())).isNullOrEmpty();
487495
}
488496
}
489497

490-
private Matcher<String> isEmptyOrFalse() {
491-
return anyOf(isEmpty(), is("false"));
492-
}
493-
494-
private Matcher<String> isEmpty() {
495-
return anyOf(new IsNull<>(), is(""));
496-
}
497-
498498
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,12 +2610,6 @@ public void testGettingPropertiesWithPrefix() throws Exception {
26102610
assertTrue(prefixedProps.isEmpty());
26112611
}
26122612

2613-
public static void main(String[] argv) throws Exception {
2614-
junit.textui.TestRunner.main(new String[]{
2615-
TestConfiguration.class.getName()
2616-
});
2617-
}
2618-
26192613
@Test
26202614
public void testGetAllPropertiesByTags() throws Exception {
26212615

hadoop-common-project/hadoop-minikdc/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@
4343
<artifactId>slf4j-reload4j</artifactId>
4444
<scope>compile</scope>
4545
</dependency>
46-
<dependency>
47-
<groupId>junit</groupId>
48-
<artifactId>junit</artifactId>
49-
<scope>compile</scope>
50-
</dependency>
5146
<dependency>
5247
<groupId>org.assertj</groupId>
5348
<artifactId>assertj-core</artifactId>

0 commit comments

Comments
 (0)