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

optimize: expand unit test coverage for the [rocketmq] module. #6927

Open
wants to merge 13 commits into
base: 2.x
Choose a base branch
from

Conversation

psxjoy
Copy link
Contributor

@psxjoy psxjoy commented Oct 15, 2024

  • I have registered the PR changes.
  • I have optimized the code using seata-codestyle.xml.
  • I have checked all codes using seata-checkstyle.xml.

Ⅰ. Describe what this PR did

Add unit test cases to complete the unit testing objectives for the seata-rocketmq module.
增加单元测试用例,完成 rocketmq模块的单元测试目标

Instructions Cov. Branches Cov. Missed Cxty Missed Lines Missed Methods Missed Classes
Before 31% 8% 27 40 67 98 10 22 0 4
After 95% 83% 8 41 5 101 2 23 0 4

Ⅱ. Does this pull request fix one issue?

fix #6506

Ⅲ. Why don't you add test cases (unit test/integration test)?

Not applicate
不适用

Ⅳ. Describe how to verify it

Run mvn clean test

Ⅴ. Special notes for reviews

In the SeataMQProducer class, there's a method doSendMessageInTransaction, which calls the parent class method send(Message msg, long timeout). Since Mockito can't mock certain parent methods, the functionality has been refactored to ensure the unit test coverage exceeds 70%. The changes are as follows:

SeataMQProducer类中有个函数doSendMessageInTransaction,里面调用了父类的函数 send(Message msg, long timeout)
因为Mockit 无法模拟父类的某些方法,为了单元测试用例覆盖率达到70%以上,进行了拆分。具体的修改为:

Before

public SendResult doSendMessageInTransaction(final Message msg, long timeout, String xid, long branchId)
	throws MQClientException {
	//...
	try {
		sendResult = super.send(msg, timeout);
	} catch (Exception e) {
		throw new MQClientException("send message Exception", e);
	}
	//...
}

After

public SendResult doSendMessageInTransaction(final Message msg, long timeout, String xid, long branchId)
	throws MQClientException {
	//...
	try {
		sendResult = superSend(msg, timeout);
	} catch (Exception e) {
		throw new MQClientException("send message Exception", e);
	}
	//...
}
public SendResult superSend(Message msg, long timeout)
	throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
	return super.send(msg, timeout);
}

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 51.93%. Comparing base (1e26c91) to head (4598d9f).

Files with missing lines Patch % Lines
...he/seata/integration/rocketmq/SeataMQProducer.java 85.71% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #6927      +/-   ##
============================================
+ Coverage     51.80%   51.93%   +0.12%     
- Complexity     6462     6473      +11     
============================================
  Files          1122     1122              
  Lines         39857    39860       +3     
  Branches       4668     4670       +2     
============================================
+ Hits          20649    20701      +52     
+ Misses        17248    17194      -54     
- Partials       1960     1965       +5     
Files with missing lines Coverage Δ
...he/seata/integration/rocketmq/SeataMQProducer.java 85.96% <85.71%> (+63.74%) ⬆️

... and 6 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

task: Improve the test case coverage of [rocketmq] module to 70%
1 participant