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

Refactoring org.apache.cloudstack.network.tungsten.service #8098

Conversation

gzhao9
Copy link
Contributor

@gzhao9 gzhao9 commented Oct 15, 2023

Description

This PR addresses the issue mentioned in #8087 by refactoring the test suites in three classes: TungstenElementTest.java, TungstenFabricUtilsTest.java, and TungstenServiceImplTest.java. The issue involves redundant mock object creations for TungstenAnswer in these test suites.

Proposed Changes

I propose refactoring the test code to eliminate redundancy and improve maintainability. Specifically, I suggest creating a reusable CreateMockTungstenAnswer class for creating TungstenAnswer mock objects with consistent stub behavior.

Benefits of the Proposed Refactoring:

  • As a result, we can reduce 321 lines of code, which makes the test cases smaller, easier to understand, and better to maintain.
  • After refactoring, if the TungstenAnswer mock creation needs to be modified in the future, the developer only needs to modify one time in CreateMockTungstenAnswer instead of 151 places of duplicate mock creation in 3 testclasses.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@boring-cyborg
Copy link

boring-cyborg bot commented Oct 15, 2023

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

@harikrishna-patnala
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@harikrishna-patnala a [SF] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@codecov
Copy link

codecov bot commented Oct 16, 2023

Codecov Report

Merging #8098 (5deb5dd) into main (543c54c) will increase coverage by 1.02%.
Report is 25 commits behind head on main.
The diff coverage is n/a.

@@             Coverage Diff              @@
##               main    #8098      +/-   ##
============================================
+ Coverage     28.15%   29.18%   +1.02%     
- Complexity    29181    31003    +1822     
============================================
  Files          5111     5181      +70     
  Lines        360669   365208    +4539     
  Branches      52700    53420     +720     
============================================
+ Hits         101562   106581    +5019     
+ Misses       245113   244022    -1091     
- Partials      13994    14605     +611     
Flag Coverage Δ
simulator-marvin-tests 25.14% <ø> (+1.27%) ⬆️
uitests 4.50% <ø> (-0.30%) ⬇️
unit-tests 14.80% <ø> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 428 files with indirect coverage changes

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

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

good change, some build error though. I added some suggestions as well.

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class CreateMockTungstenAnswer {
Copy link
Contributor

Choose a reason for hiding this comment

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

would a more appropriate name be MockTungstenAnswerFactory?

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 suggestion, I've renamed CreateMockTungstenAnswer to MockTungstenAnswerFactory and recommitted.

@DaanHoogland
Copy link
Contributor

not sure if the build errors are related to this PR

@gzhao9
Copy link
Contributor Author

gzhao9 commented Oct 17, 2023

not sure if the build errors are related to this PR

I found the error reason; the parameter used Result, which doesn't follow camel case naming. I've made an update.

@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@DaanHoogland a [SF] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✖️ el7 ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 7417

@DaanHoogland
Copy link
Contributor

not sure if the build errors are related to this PR

I found the error reason; the parameter used Result, which doesn't follow camel case naming. I've made an update.

it still doesn't compile @gzhao9 , can you have a look?

@gzhao9
Copy link
Contributor Author

gzhao9 commented Oct 18, 2023

not sure if the build errors are related to this PR

I found the error reason; the parameter used Result, which doesn't follow camel case naming. I've made an update.

it still doesn't compile @gzhao9 , can you have a look?

This is because the most recent update involved a file that I had committed.

I've made the update and made sure it works on my end.

@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@DaanHoogland a [LL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@DaanHoogland
Copy link
Contributor

@gzhao9 have a look at https://github.com/apache/cloudstack/actions/runs/6560826849/job/17824151994?pr=8098#step:6:9444 it seems you have some line endings mixed (\n instead of \r?)

@blueorangutan
Copy link

Packaging result [LL]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 6208

@gzhao9
Copy link
Contributor Author

gzhao9 commented Oct 18, 2023

@gzhao9 have a look at https://github.com/apache/cloudstack/actions/runs/6560826849/job/17824151994?pr=8098#step:6:9444 it seems you have some line endings mixed (\n instead of \r?)

I'm done replacing.

@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@DaanHoogland
Copy link
Contributor

@gzhao9
Copy link
Contributor Author

gzhao9 commented Oct 19, 2023

according to https://github.com/apache/cloudstack/actions/runs/6564274866/job/17850770581?pr=8098#step:6:9439 you still have mixed line endings @gzhao9 .

I'll keep trying to deal with it. BTW I was very confused. Another PR I submitted did not have this formatting problem.
Also, I'm curious how you guys generally deal with this issue on Windows.

@DaanHoogland
Copy link
Contributor

according to https://github.com/apache/cloudstack/actions/runs/6564274866/job/17850770581?pr=8098#step:6:9439 you still have mixed line endings @gzhao9 .

I'll keep trying to deal with it. BTW I was very confused. Another PR I submitted did not have this formatting problem. Also, I'm curious how you guys generally deal with this issue on Windows.

I don´t work on windows recently, but I remember a tool called d2u or dos2unix. it can do the conversions to and from. nowadays there is also the use of a VM that could help ;)

@gzhao9
Copy link
Contributor Author

gzhao9 commented Oct 24, 2023

according to https://github.com/apache/cloudstack/actions/runs/6564274866/job/17850770581?pr=8098#step:6:9439 you still have mixed line endings @gzhao9 .

I'll keep trying to deal with it. BTW I was very confused. Another PR I submitted did not have this formatting problem. Also, I'm curious how you guys generally deal with this issue on Windows.

I don´t work on windows recently, but I remember a tool called d2u or dos2unix. it can do the conversions to and from. nowadays there is also the use of a VM that could help ;)

I tried another update to fix the end of line issue.

@gzhao9 gzhao9 mentioned this pull request Oct 24, 2023
@gzhao9
Copy link
Contributor Author

gzhao9 commented Oct 24, 2023

@DaanHoogland To avoid also having the ending problem. I submitted two more PRs #8137 and #8139. also with similar idea to solve the duplicate creation problem of mock. If you are interested you can take a look.

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

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

clgtm

@DaanHoogland
Copy link
Contributor

unit tests only , GHA should suffice.

@rohityadavcloud rohityadavcloud merged commit 9e8f591 into apache:main Nov 3, 2023
26 checks passed
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request Nov 8, 2023
* Refactoring reduces mock cloning of TungstenAnswer

* Apply suggestions from code review

Great suggestions, thanks a lot!

Co-authored-by: dahn <daan.hoogland@gmail.com>

* Rename CreateMockTungstenAnswer  to MockTungstenAnswerFactory

* Updated parameter to camel case.

* Revised in accordance with the latest update

* Replace all `\r` with `\n`.

* Replace all \r with \n.

* temp for re-uploading

* reupdate

* update line ending

* update ling ending

* Add static methods to avoid duplicate creation of new

---------

Co-authored-by: dahn <daan.hoogland@gmail.com>
Dajeong-Park added a commit to Dajeong-Park/ablestack-cloud that referenced this pull request Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants