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

Adding test for KNNWeight #759

Conversation

martin-gaievski
Copy link
Member

@martin-gaievski martin-gaievski commented Feb 10, 2023

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

Description

We do not have unit tests for KNNWeight, having it would help to catch issues with size of DocIdSetBuilder, like #500 and #751. Along with test adding dependencies for doing mocks of static classes and/or methods.

Check List

  • New functionality includes testing.
  • 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.

@martin-gaievski martin-gaievski added Infrastructure Changes to infrastructure, testing, CI/CD, pipelines, etc. backport 1.x backport 2.x v2.6.0 labels Feb 10, 2023
@martin-gaievski martin-gaievski requested a review from a team February 10, 2023 01:06
@@ -165,6 +165,9 @@ dependencies {
api group: 'com.google.guava', name: 'guava', version:'30.0-jre'
api group: 'commons-lang', name: 'commons-lang', version: '2.6'
testFixturesImplementation "org.opensearch.test:framework:${opensearch_version}"
testImplementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.12.22'
testImplementation group: 'org.objenesis', name: 'objenesis', version: '3.2'
testImplementation group: 'net.bytebuddy', name: 'byte-buddy-agent', version: '1.12.22'
Copy link
Member Author

Choose a reason for hiding this comment

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

this is required to mock static classes/methods

Copy link
Collaborator

Choose a reason for hiding this comment

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

Quick feedback on this:

  1. Is there a possibility that we fix src so that we don't need to mock static functions.
  2. Are we using junit4 or junit5 here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Making changes in source will be problematic, there are many such classes involved in call chain.
We're using junit4, 4.13 to be precise.

@@ -196,6 +199,7 @@ test {
dependsOn buildJniLib
systemProperty 'tests.security.manager', 'false'
systemProperty "java.library.path", "$rootDir/jni/release"
systemProperty "jdk.attach.allowAttachSelf", true
Copy link
Member Author

Choose a reason for hiding this comment

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

this is required to mock static classes/methods

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a comment in the file itself.

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

@martin-gaievski martin-gaievski force-pushed the add-tests-for-knn-weight branch 5 times, most recently from 167bf29 to 3ee085e Compare February 13, 2023 20:20
Signed-off-by: Martin Gaievski <[email protected]>
@martin-gaievski martin-gaievski force-pushed the add-tests-for-knn-weight branch from 3ee085e to 6396272 Compare February 14, 2023 01:15
try {
testQueryScore(space::scoreTranslation, SEGMENT_FILES_NMSLIB, Map.of(SPACE_TYPE, space.getValue()));
} catch (Exception e) {
throw new RuntimeException(e);
Copy link
Member

Choose a reason for hiding this comment

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

Why catch this?

Copy link
Member Author

Choose a reason for hiding this comment

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

that's the syntax required in case we're using forEach. Let me change it to something less verbose and without required catch.

Copy link
Member

@jmazanec15 jmazanec15 left a comment

Choose a reason for hiding this comment

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

LGTM thanks for adding these @martin-gaievski! This improves our coverage greatly!

@martin-gaievski martin-gaievski merged commit 5b06cfe into opensearch-project:main Feb 14, 2023
@opensearch-trigger-bot
Copy link
Contributor

The backport to 1.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.x 1.x
# Navigate to the new working tree
cd .worktrees/backport-1.x
# Create a new branch
git switch --create backport/backport-759-to-1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 5b06cfe8902920161f6515347b49fcb2eae3e4e7
# Push it to GitHub
git push --set-upstream origin backport/backport-759-to-1.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.x

Then, create a pull request where the base branch is 1.x and the compare/head branch is backport/backport-759-to-1.x.

opensearch-trigger-bot bot pushed a commit that referenced this pull request Feb 14, 2023
* Adding test for KNNWeight

Signed-off-by: Martin Gaievski <[email protected]>
(cherry picked from commit 5b06cfe)
martin-gaievski added a commit that referenced this pull request Feb 14, 2023
* Adding test for KNNWeight

Signed-off-by: Martin Gaievski <[email protected]>
(cherry picked from commit 5b06cfe)

Co-authored-by: Martin Gaievski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.x backport 2.x Infrastructure Changes to infrastructure, testing, CI/CD, pipelines, etc. v2.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants