You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by sh...@apache.org on 2024/05/16 07:16:40 UTC
(bookkeeper) branch master updated: test: migrate client module bookie tests to junit 5 (#4359)
This is an automated email from the ASF dual-hosted git repository.
shoothzj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 2c62567687 test: migrate client module bookie tests to junit 5 (#4359)
2c62567687 is described below
commit 2c625676871c82fded636a49a564546186eb8962
Author: sherlock-lin <11...@qq.com>
AuthorDate: Thu May 16 15:16:35 2024 +0800
test: migrate client module bookie tests to junit 5 (#4359)
---
.../apache/bookkeeper/client/BKExceptionTest.java | 40 +++++++++++-----------
.../client/BookieAddressResolverDisabledTest.java | 19 +++++-----
.../bookkeeper/client/BookieDecommissionTest.java | 14 ++++----
.../client/BookieNetworkAddressChangeTest.java | 10 +++---
.../bookkeeper/client/BookieRecoveryTest.java | 36 +++++++++----------
.../client/BookieRecoveryUseIOThreadTest.java | 13 +++----
6 files changed, 65 insertions(+), 67 deletions(-)
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BKExceptionTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BKExceptionTest.java
index fb293924d3..0d74fb6280 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BKExceptionTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BKExceptionTest.java
@@ -20,47 +20,47 @@
*/
package org.apache.bookkeeper.client;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test for extracting codes from BKException.
*/
public class BKExceptionTest {
+
@Test
public void testBKExceptionCode() {
- Assert.assertEquals(BKException.Code.WriteException,
- BKException.getExceptionCode(new BKException.BKWriteException(),
- BKException.Code.ReadException));
+ assertEquals(BKException.Code.WriteException,
+ BKException.getExceptionCode(new BKException.BKWriteException(),
+ BKException.Code.ReadException));
}
@Test
public void testNonBKExceptionCode() {
- Assert.assertEquals(BKException.Code.ReadException,
- BKException.getExceptionCode(new Exception(),
- BKException.Code.ReadException));
-
+ assertEquals(BKException.Code.ReadException,
+ BKException.getExceptionCode(new Exception(),
+ BKException.Code.ReadException));
}
@Test
public void testNestedBKExceptionCode() {
- Assert.assertEquals(BKException.Code.WriteException,
- BKException.getExceptionCode(
- new ExecutionException("test", new BKException.BKWriteException()),
- BKException.Code.ReadException));
+ assertEquals(BKException.Code.WriteException,
+ BKException.getExceptionCode(
+ new ExecutionException("test", new BKException.BKWriteException()),
+ BKException.Code.ReadException));
}
@Test
public void testDoubleNestedBKExceptionCode() {
- Assert.assertEquals(BKException.Code.WriteException,
- BKException.getExceptionCode(
- new ExecutionException("test",
- new CompletionException("blah",
- new BKException.BKWriteException())),
- BKException.Code.ReadException));
-
+ assertEquals(BKException.Code.WriteException,
+ BKException.getExceptionCode(
+ new ExecutionException("test",
+ new CompletionException("blah",
+ new BKException.BKWriteException())),
+ BKException.Code.ReadException));
}
}
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieAddressResolverDisabledTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieAddressResolverDisabledTest.java
index 611e3e9674..fdf608b9a1 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieAddressResolverDisabledTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieAddressResolverDisabledTest.java
@@ -20,11 +20,14 @@
*/
package org.apache.bookkeeper.client;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
import org.apache.bookkeeper.net.BookieId;
import org.apache.bookkeeper.net.BookieSocketAddress;
import org.apache.bookkeeper.proto.BookieAddressResolver;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Unit test of {@link BookieAddressResolverDisabled}.
@@ -36,18 +39,18 @@ public class BookieAddressResolverDisabledTest {
BookieAddressResolver resolver = new BookieAddressResolverDisabled();
BookieSocketAddress addr1 = resolver.resolve(BookieId.parse("127.0.0.1:3181"));
- Assert.assertEquals("127.0.0.1", addr1.getHostName());
- Assert.assertEquals(3181, addr1.getPort());
+ assertEquals("127.0.0.1", addr1.getHostName());
+ assertEquals(3181, addr1.getPort());
BookieSocketAddress addr2 = resolver.resolve(BookieId.parse("localhost:3182"));
- Assert.assertEquals("localhost", addr2.getHostName());
- Assert.assertEquals(3182, addr2.getPort());
+ assertEquals("localhost", addr2.getHostName());
+ assertEquals(3182, addr2.getPort());
try {
resolver.resolve(BookieId.parse("foobar"));
- Assert.fail("Non-legacy style bookie id should fail to resolve address");
+ fail("Non-legacy style bookie id should fail to resolve address");
} catch (Exception e) {
- Assert.assertTrue(e instanceof BookieAddressResolver.BookieIdNotResolvedException);
+ assertTrue(e instanceof BookieAddressResolver.BookieIdNotResolvedException);
}
}
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieDecommissionTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieDecommissionTest.java
index ffd96ed155..8b87b5913b 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieDecommissionTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieDecommissionTest.java
@@ -18,9 +18,9 @@
*/
package org.apache.bookkeeper.client;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.Iterator;
import java.util.LinkedList;
@@ -35,7 +35,7 @@ import org.apache.bookkeeper.meta.UnderreplicatedLedger;
import org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager;
import org.apache.bookkeeper.net.BookieId;
import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Unit test of bookie decommission operations.
@@ -149,7 +149,7 @@ public class BookieDecommissionTest extends BookKeeperClusterTestCase {
startNewBookie();
- assertEquals("Number of Available Bookies", NUM_OF_BOOKIES + 1, bkAdmin.getAvailableBookies().size());
+ assertEquals(NUM_OF_BOOKIES + 1, bkAdmin.getAvailableBookies().size(), "Number of Available Bookies");
BookieId killedBookieId = getBookie(0);
log.warn("Killing bookie {}", killedBookieId);
@@ -224,12 +224,12 @@ public class BookieDecommissionTest extends BookKeeperClusterTestCase {
startNewBookie();
- assertEquals("Number of Available Bookies", NUM_OF_BOOKIES + 1, bkAdmin.getAvailableBookies().size());
+ assertEquals(NUM_OF_BOOKIES + 1, bkAdmin.getAvailableBookies().size(), "Number of Available Bookies");
BookieId killedBookieId = getBookie(0);
log.warn("Killing bookie {}", killedBookieId);
killBookie(0);
- assertEquals("Number of Available Bookies", NUM_OF_BOOKIES, bkAdmin.getAvailableBookies().size());
+ assertEquals(NUM_OF_BOOKIES, bkAdmin.getAvailableBookies().size(), "Number of Available Bookies");
bkAdmin.decommissionBookie(killedBookieId);
bkAdmin.triggerAudit();
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieNetworkAddressChangeTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieNetworkAddressChangeTest.java
index 4bf8287c67..0a6a986920 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieNetworkAddressChangeTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieNetworkAddressChangeTest.java
@@ -20,8 +20,8 @@
*/
package org.apache.bookkeeper.client;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import lombok.extern.slf4j.Slf4j;
import org.apache.bookkeeper.client.BKException.BKBookieHandleNotAvailableException;
@@ -32,8 +32,8 @@ import org.apache.bookkeeper.client.api.WriteHandle;
import org.apache.bookkeeper.conf.ClientConfiguration;
import org.apache.bookkeeper.discover.ZKRegistrationClient;
import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
/**
* Tests of the main BookKeeper client and the BP-41 bookieAddressTracking feature.
@@ -85,7 +85,7 @@ public class BookieNetworkAddressChangeTest extends BookKeeperClusterTestCase {
}
@Test
- @Ignore("PLSR-1850 Seems like restart of the bookie always comes up on same port hence failing this test")
+ @Disabled("PLSR-1850 Seems like restart of the bookie always comes up on same port hence failing this test")
public void testFollowBookieAddressChangeTrckingDisabled() throws Exception {
ClientConfiguration conf = new ClientConfiguration();
conf.setMetadataServiceUri(zkUtil.getMetadataServiceUri());
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieRecoveryTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieRecoveryTest.java
index 2b0c40b23a..8b0ca9b529 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieRecoveryTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieRecoveryTest.java
@@ -20,9 +20,9 @@
*/
package org.apache.bookkeeper.client;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
@@ -46,9 +46,9 @@ import org.apache.bookkeeper.net.BookieId;
import org.apache.bookkeeper.proto.BookieProtocol;
import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.ReadEntryCallback;
import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -104,7 +104,7 @@ public class BookieRecoveryTest extends BookKeeperClusterTestCase {
baseClientConf.setLedgerManagerFactoryClassName(ledgerManagerFactory);
}
- @Before
+ @BeforeEach
@Override
public void setUp() throws Exception {
// Set up the configuration properties needed.
@@ -119,7 +119,7 @@ public class BookieRecoveryTest extends BookKeeperClusterTestCase {
bkAdmin = new BookKeeperAdmin(adminConf);
}
- @After
+ @AfterEach
@Override
public void tearDown() throws Exception {
// Release any resources used by the BookieRecoveryTest instance.
@@ -279,7 +279,7 @@ public class BookieRecoveryTest extends BookKeeperClusterTestCase {
startAndAddBookie(confOfKilledBookie);
// all ensembles should be fully replicated since it is recovered
- assertTrue("Not fully replicated", verifyFullyReplicated(lh, 3 * numEntries));
+ assertTrue(verifyFullyReplicated(lh, 3 * numEntries), "Not fully replicated");
lh.close();
}
@@ -607,7 +607,7 @@ public class BookieRecoveryTest extends BookKeeperClusterTestCase {
bkAdmin.recoverBookieData(bookieToKill);
for (LedgerHandle lh : lhs) {
- assertTrue("Not fully replicated", verifyFullyReplicated(lh, numMsgs));
+ assertTrue(verifyFullyReplicated(lh, numMsgs), "Not fully replicated");
lh.close();
}
}
@@ -637,7 +637,7 @@ public class BookieRecoveryTest extends BookKeeperClusterTestCase {
bkAdmin.recoverBookieData(bookieToKill);
for (LedgerHandle lh : lhs) {
- assertTrue("Not fully replicated", verifyFullyReplicated(lh, numMsgs));
+ assertTrue(verifyFullyReplicated(lh, numMsgs), "Not fully replicated");
}
try {
@@ -694,7 +694,7 @@ public class BookieRecoveryTest extends BookKeeperClusterTestCase {
bkAdmin.recoverBookieData(bookieToKill);
for (LedgerHandle lh : lhs) {
- assertTrue("Not fully replicated", verifyFullyReplicated(lh, numMsgs));
+ assertTrue(verifyFullyReplicated(lh, numMsgs), "Not fully replicated");
}
// open ledgers to read metadata
@@ -770,13 +770,13 @@ public class BookieRecoveryTest extends BookKeeperClusterTestCase {
sync.value = false;
bkAdmin.recoverBookieData(bookieSrc);
- assertFalse("Dupes exist in ensembles", findDupesInEnsembles(lhs));
+ assertFalse(findDupesInEnsembles(lhs), "Dupes exist in ensembles");
// Write some more entries to ensure fencing hasn't broken stuff
writeEntriestoLedgers(numMsgs, numMsgs * 2, lhs);
for (LedgerHandle lh : lhs) {
- assertTrue("Not fully replicated", verifyFullyReplicated(lh, numMsgs * 3));
+ assertTrue(verifyFullyReplicated(lh, numMsgs * 3), "Not fully replicated");
lh.close();
}
}
@@ -801,7 +801,7 @@ public class BookieRecoveryTest extends BookKeeperClusterTestCase {
// Check that entries are missing
lh = bkc.openLedgerNoRecovery(ledgerId, digestCorrect, passwdCorrect);
- assertFalse("Should be entries missing", verifyFullyReplicated(lh, 100));
+ assertFalse(verifyFullyReplicated(lh, 100), "Should be entries missing");
lh.close();
// Try to recover with bad password in conf
@@ -818,7 +818,7 @@ public class BookieRecoveryTest extends BookKeeperClusterTestCase {
bka.close();
lh = bkc.openLedgerNoRecovery(ledgerId, digestCorrect, passwdCorrect);
- assertTrue("Should be back to fully replication", verifyFullyReplicated(lh, 100));
+ assertTrue(verifyFullyReplicated(lh, 100), "Should be back to fully replication");
lh.close();
bookieSrc = addressByIndex(0);
@@ -827,7 +827,7 @@ public class BookieRecoveryTest extends BookKeeperClusterTestCase {
// Check that entries are missing
lh = bkc.openLedgerNoRecovery(ledgerId, digestCorrect, passwdCorrect);
- assertFalse("Should be entries missing", verifyFullyReplicated(lh, 100));
+ assertFalse(verifyFullyReplicated(lh, 100), "Should be entries missing");
lh.close();
// Try to recover with no password in conf
@@ -840,7 +840,7 @@ public class BookieRecoveryTest extends BookKeeperClusterTestCase {
bka.close();
lh = bkc.openLedgerNoRecovery(ledgerId, digestCorrect, passwdCorrect);
- assertTrue("Should be back to fully replication", verifyFullyReplicated(lh, 100));
+ assertTrue(verifyFullyReplicated(lh, 100), "Should be back to fully replication");
lh.close();
}
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieRecoveryUseIOThreadTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieRecoveryUseIOThreadTest.java
index 3bf87f4cf1..3515c7699f 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieRecoveryUseIOThreadTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieRecoveryUseIOThreadTest.java
@@ -18,14 +18,14 @@
*/
package org.apache.bookkeeper.client;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.bookkeeper.conf.ClientConfiguration;
import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
-import org.junit.Assert;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Test;
/**
* Tests for Bookie recovery use IO threads.
*/
@@ -33,14 +33,9 @@ public class BookieRecoveryUseIOThreadTest extends BookKeeperClusterTestCase {
public BookieRecoveryUseIOThreadTest() {
super(1);
- }
-
- @Override
- public void setUp() throws Exception {
baseConf.setNumAddWorkerThreads(0);
baseConf.setNumReadWorkerThreads(0);
baseConf.setNumHighPriorityWorkerThreads(0);
- super.setUp();
}
@Test
@@ -75,6 +70,6 @@ public class BookieRecoveryUseIOThreadTest extends BookKeeperClusterTestCase {
}, null);
latch.await();
}
- Assert.assertEquals(finalRc.get(), org.apache.bookkeeper.client.api.BKException.Code.OK);
+ assertEquals(finalRc.get(), org.apache.bookkeeper.client.api.BKException.Code.OK);
}
}