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

Correct comparator of item sorter in Dynamo DB adapter #327

Merged
merged 6 commits into from
Oct 4, 2021

Conversation

thongdk8
Copy link
Contributor

Current implementation using byte buffer comparator so it makes the result when scanning with clustering key of blob values not correctly. This PR made for correct the comparator. Please take a look. Thank you.

@thongdk8 thongdk8 self-assigned this Sep 30, 2021
brfrn169
brfrn169 previously approved these changes Oct 1, 2021
Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

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

LGTM! Good catch! Thank you!

@brfrn169 brfrn169 self-requested a review October 3, 2021 00:32
@brfrn169
Copy link
Collaborator

brfrn169 commented Oct 3, 2021

@thongdk8 Sorry, I forgot one thing. Can you please add a unit test for this? We basically need a unit test to make sure the bug is really fixed in this kind of case.

@thongdk8
Copy link
Contributor Author

thongdk8 commented Oct 4, 2021

@brfrn169 We had a unit test for this here but it seems that it did not cover well. I made some changes in this commit, after changing this test case failed with the previous comparator and passed with the new corrected one.

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

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

Nice work! Thank you.
Left 1 comment. PTAL:bow:

@@ -264,10 +266,27 @@ public void sort_ItemsGivenWithDescOrderingText_ShouldSortProperly() {
@Test
public void sort_ItemsGivenWithDescOrderingBlob_ShouldSortProperly() {
// Arrange
Random random = new Random(777);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just wondering if there is any benefit of using Random with a fixed seed here.
I feel it's better to use fixed hard-coded byte arrays so that we (people) can see what is the expected result.
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. I had been thought about using a loop for the test with many values, so I used Random. Actually, I see some libraries still using Random for testing, so I thought it's common. For example from guava
I made to use fixed hard-coded byte arrays in this commit. Thank you for your suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

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

It makes more sense if we test many cases using loop and random but the test was only comparing two byte-arrays, that's why I asked.

Copy link
Contributor Author

@thongdk8 thongdk8 Oct 4, 2021

Choose a reason for hiding this comment

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

That's right. So should we use random and for loop here or keep it like the new commit I made?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the current code is fine and consistent with other tests.
If you feel it's not tested well, we can add more tests with loop and random. (please add instead of update in such a case)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@thongdk8 I will merge this. If you want add more tests with loop and random, please create a new PR for that. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Thank you.

@thongdk8 thongdk8 requested a review from feeblefakie October 4, 2021 04:15
Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@brfrn169 brfrn169 merged commit a55653e into master Oct 4, 2021
@brfrn169 brfrn169 deleted the fix-dynamo-item-sorting branch October 4, 2021 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants