Skip to content

Commit 6ba6ad2

Browse files
sherlock-linStevenLuMT
authored andcommitted
test: migrate client module bookie tests to junit 5 (#4359)
(cherry picked from commit 2c62567)
1 parent 1663a5f commit 6ba6ad2

6 files changed

Lines changed: 65 additions & 67 deletions

File tree

bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BKExceptionTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,47 @@
2020
*/
2121
package org.apache.bookkeeper.client;
2222

23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
2325
import java.util.concurrent.CompletionException;
2426
import java.util.concurrent.ExecutionException;
25-
import org.junit.Assert;
26-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2728

2829
/**
2930
* Test for extracting codes from BKException.
3031
*/
3132
public class BKExceptionTest {
33+
3234
@Test
3335
public void testBKExceptionCode() {
34-
Assert.assertEquals(BKException.Code.WriteException,
35-
BKException.getExceptionCode(new BKException.BKWriteException(),
36-
BKException.Code.ReadException));
36+
assertEquals(BKException.Code.WriteException,
37+
BKException.getExceptionCode(new BKException.BKWriteException(),
38+
BKException.Code.ReadException));
3739
}
3840

3941
@Test
4042
public void testNonBKExceptionCode() {
41-
Assert.assertEquals(BKException.Code.ReadException,
42-
BKException.getExceptionCode(new Exception(),
43-
BKException.Code.ReadException));
44-
43+
assertEquals(BKException.Code.ReadException,
44+
BKException.getExceptionCode(new Exception(),
45+
BKException.Code.ReadException));
4546
}
4647

4748
@Test
4849
public void testNestedBKExceptionCode() {
49-
Assert.assertEquals(BKException.Code.WriteException,
50-
BKException.getExceptionCode(
51-
new ExecutionException("test", new BKException.BKWriteException()),
52-
BKException.Code.ReadException));
50+
assertEquals(BKException.Code.WriteException,
51+
BKException.getExceptionCode(
52+
new ExecutionException("test", new BKException.BKWriteException()),
53+
BKException.Code.ReadException));
5354
}
5455

5556
@Test
5657
public void testDoubleNestedBKExceptionCode() {
57-
Assert.assertEquals(BKException.Code.WriteException,
58-
BKException.getExceptionCode(
59-
new ExecutionException("test",
60-
new CompletionException("blah",
61-
new BKException.BKWriteException())),
62-
BKException.Code.ReadException));
63-
58+
assertEquals(BKException.Code.WriteException,
59+
BKException.getExceptionCode(
60+
new ExecutionException("test",
61+
new CompletionException("blah",
62+
new BKException.BKWriteException())),
63+
BKException.Code.ReadException));
6464
}
6565
}
6666

bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieAddressResolverDisabledTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
*/
2121
package org.apache.bookkeeper.client;
2222

23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
import static org.junit.jupiter.api.Assertions.fail;
26+
2327
import org.apache.bookkeeper.net.BookieId;
2428
import org.apache.bookkeeper.net.BookieSocketAddress;
2529
import org.apache.bookkeeper.proto.BookieAddressResolver;
26-
import org.junit.Assert;
27-
import org.junit.Test;
30+
import org.junit.jupiter.api.Test;
2831

2932
/**
3033
* Unit test of {@link BookieAddressResolverDisabled}.
@@ -36,18 +39,18 @@ public void testResolve() {
3639
BookieAddressResolver resolver = new BookieAddressResolverDisabled();
3740

3841
BookieSocketAddress addr1 = resolver.resolve(BookieId.parse("127.0.0.1:3181"));
39-
Assert.assertEquals("127.0.0.1", addr1.getHostName());
40-
Assert.assertEquals(3181, addr1.getPort());
42+
assertEquals("127.0.0.1", addr1.getHostName());
43+
assertEquals(3181, addr1.getPort());
4144

4245
BookieSocketAddress addr2 = resolver.resolve(BookieId.parse("localhost:3182"));
43-
Assert.assertEquals("localhost", addr2.getHostName());
44-
Assert.assertEquals(3182, addr2.getPort());
46+
assertEquals("localhost", addr2.getHostName());
47+
assertEquals(3182, addr2.getPort());
4548

4649
try {
4750
resolver.resolve(BookieId.parse("foobar"));
48-
Assert.fail("Non-legacy style bookie id should fail to resolve address");
51+
fail("Non-legacy style bookie id should fail to resolve address");
4952
} catch (Exception e) {
50-
Assert.assertTrue(e instanceof BookieAddressResolver.BookieIdNotResolvedException);
53+
assertTrue(e instanceof BookieAddressResolver.BookieIdNotResolvedException);
5154
}
5255
}
5356

bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieDecommissionTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
*/
1919
package org.apache.bookkeeper.client;
2020

21-
import static org.junit.Assert.assertEquals;
22-
import static org.junit.Assert.assertNotEquals;
23-
import static org.junit.Assert.fail;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
23+
import static org.junit.jupiter.api.Assertions.fail;
2424

2525
import java.util.Iterator;
2626
import java.util.LinkedList;
@@ -35,7 +35,7 @@
3535
import org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager;
3636
import org.apache.bookkeeper.net.BookieId;
3737
import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
38-
import org.junit.Test;
38+
import org.junit.jupiter.api.Test;
3939

4040
/**
4141
* Unit test of bookie decommission operations.
@@ -149,7 +149,7 @@ public void testDecommissionForLedgersWithMultipleSegmentsAndNotWriteClosed() th
149149

150150
startNewBookie();
151151

152-
assertEquals("Number of Available Bookies", NUM_OF_BOOKIES + 1, bkAdmin.getAvailableBookies().size());
152+
assertEquals(NUM_OF_BOOKIES + 1, bkAdmin.getAvailableBookies().size(), "Number of Available Bookies");
153153

154154
BookieId killedBookieId = getBookie(0);
155155
log.warn("Killing bookie {}", killedBookieId);
@@ -224,12 +224,12 @@ public void testDecommissionForEmptyLedgers() throws Exception {
224224

225225
startNewBookie();
226226

227-
assertEquals("Number of Available Bookies", NUM_OF_BOOKIES + 1, bkAdmin.getAvailableBookies().size());
227+
assertEquals(NUM_OF_BOOKIES + 1, bkAdmin.getAvailableBookies().size(), "Number of Available Bookies");
228228

229229
BookieId killedBookieId = getBookie(0);
230230
log.warn("Killing bookie {}", killedBookieId);
231231
killBookie(0);
232-
assertEquals("Number of Available Bookies", NUM_OF_BOOKIES, bkAdmin.getAvailableBookies().size());
232+
assertEquals(NUM_OF_BOOKIES, bkAdmin.getAvailableBookies().size(), "Number of Available Bookies");
233233

234234
bkAdmin.decommissionBookie(killedBookieId);
235235
bkAdmin.triggerAudit();

bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieNetworkAddressChangeTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
*/
2121
package org.apache.bookkeeper.client;
2222

23-
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assert.fail;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.fail;
2525

2626
import lombok.extern.slf4j.Slf4j;
2727
import org.apache.bookkeeper.client.BKException.BKBookieHandleNotAvailableException;
@@ -32,8 +32,8 @@
3232
import org.apache.bookkeeper.conf.ClientConfiguration;
3333
import org.apache.bookkeeper.discover.ZKRegistrationClient;
3434
import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
35-
import org.junit.Ignore;
36-
import org.junit.Test;
35+
import org.junit.jupiter.api.Disabled;
36+
import org.junit.jupiter.api.Test;
3737

3838
/**
3939
* Tests of the main BookKeeper client and the BP-41 bookieAddressTracking feature.
@@ -85,7 +85,7 @@ public void testFollowBookieAddressChange() throws Exception {
8585
}
8686

8787
@Test
88-
@Ignore("PLSR-1850 Seems like restart of the bookie always comes up on same port hence failing this test")
88+
@Disabled("PLSR-1850 Seems like restart of the bookie always comes up on same port hence failing this test")
8989
public void testFollowBookieAddressChangeTrckingDisabled() throws Exception {
9090
ClientConfiguration conf = new ClientConfiguration();
9191
conf.setMetadataServiceUri(zkUtil.getMetadataServiceUri());

bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieRecoveryTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
*/
2121
package org.apache.bookkeeper.client;
2222

23-
import static org.junit.Assert.assertFalse;
24-
import static org.junit.Assert.assertTrue;
25-
import static org.junit.Assert.fail;
23+
import static org.junit.jupiter.api.Assertions.assertFalse;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
import static org.junit.jupiter.api.Assertions.fail;
2626

2727
import io.netty.buffer.ByteBuf;
2828
import java.io.IOException;
@@ -46,9 +46,9 @@
4646
import org.apache.bookkeeper.proto.BookieProtocol;
4747
import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.ReadEntryCallback;
4848
import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
49-
import org.junit.After;
50-
import org.junit.Before;
51-
import org.junit.Test;
49+
import org.junit.jupiter.api.AfterEach;
50+
import org.junit.jupiter.api.BeforeEach;
51+
import org.junit.jupiter.api.Test;
5252
import org.slf4j.Logger;
5353
import org.slf4j.LoggerFactory;
5454

@@ -104,7 +104,7 @@ public BookieRecoveryTest() {
104104
baseClientConf.setLedgerManagerFactoryClassName(ledgerManagerFactory);
105105
}
106106

107-
@Before
107+
@BeforeEach
108108
@Override
109109
public void setUp() throws Exception {
110110
// Set up the configuration properties needed.
@@ -119,7 +119,7 @@ public void setUp() throws Exception {
119119
bkAdmin = new BookKeeperAdmin(adminConf);
120120
}
121121

122-
@After
122+
@AfterEach
123123
@Override
124124
public void tearDown() throws Exception {
125125
// Release any resources used by the BookieRecoveryTest instance.
@@ -279,7 +279,7 @@ void metadataConflictWithRecovery(BookKeeper bkc) throws Exception {
279279
startAndAddBookie(confOfKilledBookie);
280280

281281
// all ensembles should be fully replicated since it is recovered
282-
assertTrue("Not fully replicated", verifyFullyReplicated(lh, 3 * numEntries));
282+
assertTrue(verifyFullyReplicated(lh, 3 * numEntries), "Not fully replicated");
283283
lh.close();
284284
}
285285

@@ -607,7 +607,7 @@ public void testBookieRecoveryOnClosedLedgers() throws Exception {
607607

608608
bkAdmin.recoverBookieData(bookieToKill);
609609
for (LedgerHandle lh : lhs) {
610-
assertTrue("Not fully replicated", verifyFullyReplicated(lh, numMsgs));
610+
assertTrue(verifyFullyReplicated(lh, numMsgs), "Not fully replicated");
611611
lh.close();
612612
}
613613
}
@@ -637,7 +637,7 @@ public void testBookieRecoveryOnOpenedLedgers() throws Exception {
637637
bkAdmin.recoverBookieData(bookieToKill);
638638

639639
for (LedgerHandle lh : lhs) {
640-
assertTrue("Not fully replicated", verifyFullyReplicated(lh, numMsgs));
640+
assertTrue(verifyFullyReplicated(lh, numMsgs), "Not fully replicated");
641641
}
642642

643643
try {
@@ -694,7 +694,7 @@ public void testBookieRecoveryOnInRecoveryLedger() throws Exception {
694694
bkAdmin.recoverBookieData(bookieToKill);
695695

696696
for (LedgerHandle lh : lhs) {
697-
assertTrue("Not fully replicated", verifyFullyReplicated(lh, numMsgs));
697+
assertTrue(verifyFullyReplicated(lh, numMsgs), "Not fully replicated");
698698
}
699699

700700
// open ledgers to read metadata
@@ -770,13 +770,13 @@ public void testSyncBookieRecoveryToRandomBookiesCheckForDupes() throws Exceptio
770770
sync.value = false;
771771
bkAdmin.recoverBookieData(bookieSrc);
772772

773-
assertFalse("Dupes exist in ensembles", findDupesInEnsembles(lhs));
773+
assertFalse(findDupesInEnsembles(lhs), "Dupes exist in ensembles");
774774

775775
// Write some more entries to ensure fencing hasn't broken stuff
776776
writeEntriestoLedgers(numMsgs, numMsgs * 2, lhs);
777777

778778
for (LedgerHandle lh : lhs) {
779-
assertTrue("Not fully replicated", verifyFullyReplicated(lh, numMsgs * 3));
779+
assertTrue(verifyFullyReplicated(lh, numMsgs * 3), "Not fully replicated");
780780
lh.close();
781781
}
782782
}
@@ -801,7 +801,7 @@ public void recoverWithoutPasswordInConf() throws Exception {
801801

802802
// Check that entries are missing
803803
lh = bkc.openLedgerNoRecovery(ledgerId, digestCorrect, passwdCorrect);
804-
assertFalse("Should be entries missing", verifyFullyReplicated(lh, 100));
804+
assertFalse(verifyFullyReplicated(lh, 100), "Should be entries missing");
805805
lh.close();
806806

807807
// Try to recover with bad password in conf
@@ -818,7 +818,7 @@ public void recoverWithoutPasswordInConf() throws Exception {
818818
bka.close();
819819

820820
lh = bkc.openLedgerNoRecovery(ledgerId, digestCorrect, passwdCorrect);
821-
assertTrue("Should be back to fully replication", verifyFullyReplicated(lh, 100));
821+
assertTrue(verifyFullyReplicated(lh, 100), "Should be back to fully replication");
822822
lh.close();
823823

824824
bookieSrc = addressByIndex(0);
@@ -827,7 +827,7 @@ public void recoverWithoutPasswordInConf() throws Exception {
827827

828828
// Check that entries are missing
829829
lh = bkc.openLedgerNoRecovery(ledgerId, digestCorrect, passwdCorrect);
830-
assertFalse("Should be entries missing", verifyFullyReplicated(lh, 100));
830+
assertFalse(verifyFullyReplicated(lh, 100), "Should be entries missing");
831831
lh.close();
832832

833833
// Try to recover with no password in conf
@@ -840,7 +840,7 @@ public void recoverWithoutPasswordInConf() throws Exception {
840840
bka.close();
841841

842842
lh = bkc.openLedgerNoRecovery(ledgerId, digestCorrect, passwdCorrect);
843-
assertTrue("Should be back to fully replication", verifyFullyReplicated(lh, 100));
843+
assertTrue(verifyFullyReplicated(lh, 100), "Should be back to fully replication");
844844
lh.close();
845845
}
846846

bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieRecoveryUseIOThreadTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,24 @@
1818
*/
1919
package org.apache.bookkeeper.client;
2020

21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
2123
import java.io.IOException;
2224
import java.util.concurrent.CountDownLatch;
2325
import java.util.concurrent.atomic.AtomicInteger;
2426
import org.apache.bookkeeper.conf.ClientConfiguration;
2527
import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
26-
import org.junit.Assert;
27-
import org.junit.Test;
28-
28+
import org.junit.jupiter.api.Test;
2929
/**
3030
* Tests for Bookie recovery use IO threads.
3131
*/
3232
public class BookieRecoveryUseIOThreadTest extends BookKeeperClusterTestCase {
3333

3434
public BookieRecoveryUseIOThreadTest() {
3535
super(1);
36-
}
37-
38-
@Override
39-
public void setUp() throws Exception {
4036
baseConf.setNumAddWorkerThreads(0);
4137
baseConf.setNumReadWorkerThreads(0);
4238
baseConf.setNumHighPriorityWorkerThreads(0);
43-
super.setUp();
4439
}
4540

4641
@Test
@@ -75,6 +70,6 @@ public void openComplete(int rc, LedgerHandle lh, Object ctx) {
7570
}, null);
7671
latch.await();
7772
}
78-
Assert.assertEquals(finalRc.get(), org.apache.bookkeeper.client.api.BKException.Code.OK);
73+
assertEquals(finalRc.get(), org.apache.bookkeeper.client.api.BKException.Code.OK);
7974
}
8075
}

0 commit comments

Comments
 (0)