Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: migrate client module bookie tests to junit 5 #4359

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -36,18 +39,18 @@ public void testResolve() {
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,7 +35,7 @@
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;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary blank line

/**
* Unit test of bookie decommission operations.
Expand Down Expand Up @@ -149,7 +149,7 @@ public void testDecommissionForLedgersWithMultipleSegmentsAndNotWriteClosed() th

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);
Expand Down Expand Up @@ -224,12 +224,12 @@ public void testDecommissionForEmptyLedgers() throws Exception {

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,8 +32,8 @@
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.
Expand Down Expand Up @@ -85,7 +85,7 @@ public void testFollowBookieAddressChange() throws Exception {
}

@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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,9 +46,9 @@
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;

Expand Down Expand Up @@ -104,7 +104,7 @@ public BookieRecoveryTest() {
baseClientConf.setLedgerManagerFactoryClassName(ledgerManagerFactory);
}

@Before
@BeforeEach
@Override
public void setUp() throws Exception {
// Set up the configuration properties needed.
Expand All @@ -119,7 +119,7 @@ public void setUp() throws Exception {
bkAdmin = new BookKeeperAdmin(adminConf);
}

@After
@AfterEach
@Override
public void tearDown() throws Exception {
// Release any resources used by the BookieRecoveryTest instance.
Expand Down Expand Up @@ -279,7 +279,7 @@ void metadataConflictWithRecovery(BookKeeper bkc) throws Exception {
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();
}

Expand Down Expand Up @@ -607,7 +607,7 @@ public void testBookieRecoveryOnClosedLedgers() throws Exception {

bkAdmin.recoverBookieData(bookieToKill);
for (LedgerHandle lh : lhs) {
assertTrue("Not fully replicated", verifyFullyReplicated(lh, numMsgs));
assertTrue(verifyFullyReplicated(lh, numMsgs), "Not fully replicated");
lh.close();
}
}
Expand Down Expand Up @@ -637,7 +637,7 @@ public void testBookieRecoveryOnOpenedLedgers() throws Exception {
bkAdmin.recoverBookieData(bookieToKill);

for (LedgerHandle lh : lhs) {
assertTrue("Not fully replicated", verifyFullyReplicated(lh, numMsgs));
assertTrue(verifyFullyReplicated(lh, numMsgs), "Not fully replicated");
}

try {
Expand Down Expand Up @@ -694,7 +694,7 @@ public void testBookieRecoveryOnInRecoveryLedger() throws Exception {
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
Expand Down Expand Up @@ -770,13 +770,13 @@ public void testSyncBookieRecoveryToRandomBookiesCheckForDupes() throws Exceptio
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();
}
}
Expand All @@ -801,7 +801,7 @@ public void recoverWithoutPasswordInConf() throws Exception {

// 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
Expand All @@ -818,7 +818,7 @@ public void recoverWithoutPasswordInConf() throws Exception {
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);
Expand All @@ -827,7 +827,7 @@ public void recoverWithoutPasswordInConf() throws Exception {

// 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
Expand All @@ -840,7 +840,7 @@ public void recoverWithoutPasswordInConf() throws Exception {
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,24 @@
*/
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.
*/
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
Expand Down Expand Up @@ -75,6 +70,6 @@ public void openComplete(int rc, LedgerHandle lh, Object ctx) {
}, 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);
}
}
Loading