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 unit tests for codec #562

Conversation

martin-gaievski
Copy link
Member

Signed-off-by: Martin Gaievski [email protected]

Description

Current structure of unit tests for codec does not allow to upgrade codec easy. For new codec it's required to copy test code to a new codec specific unit test. With this change this test has been parametrized and codec and perFieldFormat can be injected by caller.

Check List

  • All tests pass
  • Commits are signed as per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Martin Gaievski <[email protected]>
@martin-gaievski martin-gaievski added Refactoring Improve the design, structure, and implementation while preserving its functionality backport 2.x 2.4.0 labels Sep 20, 2022
@martin-gaievski martin-gaievski requested a review from a team September 20, 2022 16:52
@codecov-commenter
Copy link

Codecov Report

Merging #562 (153943d) into main (a19149a) will decrease coverage by 0.02%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##               main     #562      +/-   ##
============================================
- Coverage     84.07%   84.05%   -0.03%     
+ Complexity     1021     1020       -1     
============================================
  Files           146      146              
  Lines          4195     4195              
  Branches        373      373              
============================================
- Hits           3527     3526       -1     
- Misses          492      493       +1     
  Partials        176      176              
Impacted Files Coverage Δ
...earch/knn/index/codec/KNN910Codec/KNN910Codec.java 85.71% <0.00%> (-14.29%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

reader.close();

/**
* Add doc with field "my_vector"
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not my_vector anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

ack

iwc.setCodec(codec);

/**
* Add doc with field "test_vector"
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be test_vector_one?

Copy link
Member Author

Choose a reason for hiding this comment

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

ack

final MapperService mapperService = mock(MapperService.class);
final KNNMethodContext knnMethodContext = new KNNMethodContext(
KNNEngine.LUCENE,
SpaceType.L2,
new MethodComponentContext(METHOD_HNSW, Map.of(HNSW_ALGO_M, 16, HNSW_ALGO_EF_CONSTRUCTION, 256))
);
final KNNVectorFieldMapper.KNNVectorFieldType mappedFieldType1 = new KNNVectorFieldMapper.KNNVectorFieldType(
fieldName,
FIELD_NAME_ONE,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will there be a way for this class doesn't need to know about FIELD_NAME_ONE and FIELD_NAME_TWO?
This code might reduce code duplication but it seems it does not achieve a separation of concerns. I had to look in to testKnnVectorIndex code and what it does and how FIELD_NAME_ONE and FIELD_NAME_TWO is used. Maybe, it could be because I am not familiar with KNN code base though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see what you mean, I'm also not that happy with this change. let me try few things.

Copy link
Member Author

@martin-gaievski martin-gaievski Sep 20, 2022

Choose a reason for hiding this comment

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

I think I've got it with a function as supplier, will push the commit soon

Signed-off-by: Martin Gaievski <[email protected]>
Copy link
Collaborator

@heemin32 heemin32 left a comment

Choose a reason for hiding this comment

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

Good improvement. LGTM.

@martin-gaievski martin-gaievski merged commit 3201c3a into opensearch-project:main Sep 20, 2022
opensearch-trigger-bot bot pushed a commit that referenced this pull request Sep 20, 2022
* Refactor unit test for codec for easier lucene version upgrades

Signed-off-by: Martin Gaievski <[email protected]>
(cherry picked from commit 3201c3a)
martin-gaievski pushed a commit that referenced this pull request Sep 20, 2022
* Refactor unit test for codec for easier lucene version upgrades

Signed-off-by: Martin Gaievski <[email protected]>
martin-gaievski added a commit that referenced this pull request Sep 28, 2022
* Refactor unit test for codec for easier lucene version upgrades

Signed-off-by: Martin Gaievski <[email protected]>
@heemin32 heemin32 added v2.4.0 'Issues and PRs related to version v2.4.0' and removed 2.4.0 labels Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Refactoring Improve the design, structure, and implementation while preserving its functionality v2.4.0 'Issues and PRs related to version v2.4.0'
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants