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 api tests to junit 5 #4376

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
123
sherlock-lin committed May 8, 2024
commit babd85a37f9cfce0cec461ebf33609798ce7645e
Original file line number Diff line number Diff line change
@@ -90,23 +90,28 @@
/**
* Testing ledger write entry cases.
*/
//当类被@RunWith注解修饰,或者类继承了一个被该注解修饰的类,JUnit将会使用这个注解所指明的运行器(runner)来运行测试,而不使用JUnit默认的运行器。
//要进行参数化测试,需要在类上面指定如下的运行器:@RunWith(Parameterized.class)
@RunWith(Parameterized.class)
public class BookieWriteLedgerTest extends
BookKeeperClusterTestCase implements AddCallback {

private static final Logger LOG = LoggerFactory
.getLogger(BookieWriteLedgerTest.class);

//在提供数据的方法上加上一个@Parameters注解,这个方法必须是静态static的,并且返回一个集合Collection。
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ true, true }, { true, false }, { false, true }, { false, false }
});
}

//first data value (0) is default,不能为 private
@Parameterized.Parameter(0)
public boolean useV2;

//不能为 private
@Parameterized.Parameter(1)
public boolean writeJournal;

@@ -135,6 +140,7 @@ public SyncObj() {
@Override
@Before
public void setUp() throws Exception {
System.out.println("开始进行方法单元测试=======================");
baseConf.setJournalWriteData(writeJournal);
baseClientConf.setUseV2WireProtocol(useV2);

@@ -162,12 +168,17 @@ public BookieWriteLedgerTest() {
/**
* Verify write when few bookie failures in last ensemble and forcing
* ensemble reformation.
* 验证在写最后一个ensemble时,少数失败并不影响写入的最终效果
*
*/
@Test
public void testWithMultipleBookieFailuresInLastEnsemble() throws Exception {
// Create a ledger
//创建一个写5副本,至少4个算成功的Ledger
lh = bkc.createLedger(5, 4, digestType, ledgerPassword);
LOG.info("Ledger ID: " + lh.getId());

//循环往里面写入100次数据
for (int i = 0; i < numEntriesToWrite; i++) {
ByteBuffer entry = ByteBuffer.allocate(4);
entry.putInt(rng.nextInt(maxInt));
@@ -887,11 +898,12 @@ public void testLedgerCreateAdvWithLedgerIdInLoop2() throws Exception {

/**
* Verify asynchronous writing when few bookie failures in last ensemble.
* 测试异步写最后一条消息失败的场景
*/
@Test
public void testAsyncWritesWithMultipleFailuresInLastEnsemble()
throws Exception {
// Create ledgers123
// Create ledgers
lh = bkc.createLedger(5, 4, digestType, ledgerPassword);
lh2 = bkc.createLedger(5, 4, digestType, ledgerPassword);

Original file line number Diff line number Diff line change
@@ -90,6 +90,8 @@

/**
* A class runs several bookie servers for testing.
*
* 这个类会启动几台bookie用于测试
*/
public abstract class BookKeeperClusterTestCase {

@@ -157,6 +159,7 @@ public BookKeeperClusterTestCase(int numBookies, int numOfZKNodes, int testTimeo
}
}

//每个方法执行前会启动这个
@Before
public void setUp() throws Exception {
setUp("/ledgers");
@@ -187,6 +190,7 @@ protected String getMetadataServiceUri(String ledgersRootPath) {
return zkUtil.getMetadataServiceUri(ledgersRootPath);
}

//每个方法执行结束会执行这个
@After
public void tearDown() throws Exception {
boolean failed = false;