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

refactor: refactor the Result Class #7176

Merged
merged 15 commits into from
Mar 9, 2025
Merged

Conversation

YongGoose
Copy link
Contributor

  • I have registered the PR changes.

Ⅰ. Describe what this PR did

Ⅱ. Does this pull request fix one issue?

fixes #7158

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

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

Copy link

codecov bot commented Feb 22, 2025

Codecov Report

Attention: Patch coverage is 41.50943% with 31 lines in your changes missing coverage. Please review.

Project coverage is 51.58%. Comparing base (efa341a) to head (d0cd289).
Report is 3 commits behind head on 2.x.

Files with missing lines Patch % Lines
...ache/seata/namingserver/manager/NamingManager.java 12.50% 14 Missing ⚠️
...eata/namingserver/controller/NamingController.java 30.00% 7 Missing ⚠️
...ata/server/controller/VGroupMappingController.java 0.00% 4 Missing ⚠️
...seata/server/console/impl/AbstractLockService.java 0.00% 2 Missing ⚠️
...che/seata/server/controller/ClusterController.java 0.00% 2 Missing ⚠️
...in/java/org/apache/seata/common/result/Result.java 50.00% 1 Missing ⚠️
...eata/namingserver/controller/HealthController.java 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##                2.x    #7176   +/-   ##
=========================================
  Coverage     51.58%   51.58%           
- Complexity     6815     6818    +3     
=========================================
  Files          1169     1169           
  Lines         41505    41487   -18     
  Branches       4857     4858    +1     
=========================================
- Hits          21409    21402    -7     
+ Misses        18073    18061   -12     
- Partials       2023     2024    +1     
Files with missing lines Coverage Δ
...main/java/org/apache/seata/common/result/Code.java 86.66% <100.00%> (-2.81%) ⬇️
...ava/org/apache/seata/common/result/PageResult.java 87.71% <100.00%> (ø)
...a/org/apache/seata/common/result/SingleResult.java 100.00% <100.00%> (+15.38%) ⬆️
...in/java/org/apache/seata/common/result/Result.java 77.77% <50.00%> (+24.44%) ⬆️
...eata/namingserver/controller/HealthController.java 50.00% <0.00%> (ø)
...seata/server/console/impl/AbstractLockService.java 9.09% <0.00%> (ø)
...che/seata/server/controller/ClusterController.java 8.88% <0.00%> (+0.19%) ⬆️
...ata/server/controller/VGroupMappingController.java 11.76% <0.00%> (+2.24%) ⬆️
...eata/namingserver/controller/NamingController.java 28.57% <30.00%> (-3.25%) ⬇️
...ache/seata/namingserver/manager/NamingManager.java 49.39% <12.50%> (-0.81%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


public Result() {
this(SUCCESS.code, SUCCESS.msg);
Copy link
Member

Choose a reason for hiding this comment

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

An implicit success isn't a great design choice because it doesn't align with the conventional understanding of a zero value. If it needs to represent success, it's better to make it clear in the method name rather than assigning it to a default constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch :)
Done in 3b4370f !

@YongGoose YongGoose requested a review from slievrly February 23, 2025 00:42
Comment on lines -393 to +392
Result<String> res = createGroup(namespace, vGroup, clusterName, unitName);
SingleResult<Void> res = createGroup(namespace, vGroup, clusterName, unitName);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the refactorings I made was distinguishing between setting the message of Result as a String and making the generic type of Result a String—these are separate concerns.

I understand that there are many instances of this pattern in the code.
I plan to focus on refactoring this part as well.

@slievrly
Copy link
Member

slievrly commented Mar 6, 2025

@YongGoose
Copy link
Contributor Author

@YongGoose some UT cases failed. https://github.com/apache/incubator-seata/actions/runs/13701955489/job/38317801470?pr=7176

I also saw the UT cases failed.
However, I can’t figure out why the test is failing.

To explain in more detail, I can see that testIsSuccess in ResultTest has failed.

org.opentest4j.AssertionFailedError: expected: but was:
at org.apache.seata.common.result.ResultTest.testIsSuccess(ResultTest.java:36)

This test checks the isSuccess method of the Result class, verifying whether the code consists of the string 200.

public boolean isSuccess() {
    return this.code.equals(SUCCESS.code);
}

---

SUCCESS("200", "ok"),

When checking the unit test, I can confirm that the values 200 and ok are being set correctly.

@Test
void testIsSuccess() {
    Result result = new Result("200", "ok");
    Assertions.assertTrue(result.isSuccess());
}

@slievrly What do you think?

PS. please assign below issue to me :) I'll do my best to implement this issue

And I’m interested in your mission among Seata’s GSOC missions. 🙂

@slievrly
Copy link
Member

slievrly commented Mar 8, 2025

@YongGoose some UT cases failed. https://github.com/apache/incubator-seata/actions/runs/13701955489/job/38317801470?pr=7176

I also saw the UT cases failed. However, I can’t figure out why the test is failing.

To explain in more detail, I can see that testIsSuccess in ResultTest has failed.

org.opentest4j.AssertionFailedError: expected: but was:
at org.apache.seata.common.result.ResultTest.testIsSuccess(ResultTest.java:36)

This test checks the isSuccess method of the Result class, verifying whether the code consists of the string 200.

public boolean isSuccess() {
    return this.code.equals(SUCCESS.code);
}

---

SUCCESS("200", "ok"),

When checking the unit test, I can confirm that the values 200 and ok are being set correctly.

@Test
void testIsSuccess() {
    Result result = new Result("200", "ok");
    Assertions.assertTrue(result.isSuccess());
}

@slievrly What do you think?

It was a little confusing. I can run your PR code locally and it will pass the unit test. Maybe it's not the code itself, and I'll try to pinpoint the cause.

PS. please assign below issue to me :) I'll do my best to implement this issue

I have already commented on this issue.

And I’m interested in your mission among Seata’s GSOC missions. 🙂

Are you talking about this GSoC project? https://cwiki.apache.org/confluence/display/COMDEV/GSoC+2025+Ideas+list#GSoC2025Ideaslist-GSoC2025-ApacheSeata(Incubating)EnhancingConnectionPoolManagementforApacheSeataAT/XATransactionModes

@YongGoose
Copy link
Contributor Author

@slievrly
Copy link
Member

slievrly commented Mar 8, 2025

Are you talking about this GSoC project? https://cwiki.apache.org/confluence/display/COMDEV/GSoC+2025+Ideas+list#GSoC2025Ideaslist-GSoC2025-ApacheSeata(Incubating)EnhancingConnectionPoolManagementforApacheSeataAT/XATransactionModes

Yes, I'm interested in this issue.

GSoC project has to apply for conditions to open source mainly for beginner or student, specific refer to: https://developers.google.cn/open-source/gsoc/faq

If you meet the requirements for registration, you are welcome to apply.

In addition, the projects you see on this page are currently in idea status, and ASF needs to further approve which projects will eventually participate in GSoC.

@slievrly
Copy link
Member

slievrly commented Mar 8, 2025

@YongGoose some UT cases failed. https://github.com/apache/incubator-seata/actions/runs/13701955489/job/38317801470?pr=7176

I also saw the UT cases failed. However, I can’t figure out why the test is failing.
To explain in more detail, I can see that testIsSuccess in ResultTest has failed.

org.opentest4j.AssertionFailedError: expected: but was:
at org.apache.seata.common.result.ResultTest.testIsSuccess(ResultTest.java:36)

This test checks the isSuccess method of the Result class, verifying whether the code consists of the string 200.

public boolean isSuccess() {
    return this.code.equals(SUCCESS.code);
}

---

SUCCESS("200", "ok"),

When checking the unit test, I can confirm that the values 200 and ok are being set correctly.

@Test
void testIsSuccess() {
    Result result = new Result("200", "ok");
    Assertions.assertTrue(result.isSuccess());
}

@slievrly What do you think?

It was a little confusing. I can run your PR code locally and it will pass the unit test. Maybe it's not the code itself, and I'll try to pinpoint the cause.

https://github.com/apache/incubator-seata/blob/2.x/common/src/test/java/org/apache/seata/common/code/CodeTest.java#L46

Copy link
Member

@slievrly slievrly left a comment

Choose a reason for hiding this comment

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

LGTM

@slievrly slievrly changed the title refactor: Refactoring the Result Class refactor: refactor the Result Class Mar 9, 2025
@slievrly slievrly merged commit 01877a9 into apache:2.x Mar 9, 2025
7 checks passed
@slievrly slievrly added this to the 2.4.0 milestone Mar 9, 2025
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.

Refactor: Refactoring the Result Class
3 participants