-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Bson specification testing #1820
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
Open
rozza
wants to merge
13
commits into
mongodb:main
Choose a base branch
from
rozza:JAVA-5877
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+232
−5,599
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
36cfff4
Bson specification testing
rozza 3f54ffc
Update bson/src/main/org/bson/json/JsonDoubleHelper.java
rozza 75df9bb
Checkstyle fix
rozza 1287f1b
Update bson/src/test/unit/org/bson/BinaryVectorTest.java
rozza 024981d
Update bson/src/test/unit/org/bson/BinaryVectorTest.java
rozza 16acd75
Apply suggestion from @vbabanin
rozza 89120fd
PR updates
rozza 60814a7
Remove duplicate validation
rozza ba76152
Move Prose back add specification links
rozza 791f59a
Revert decoding check logic
rozza 5b86753
Manually copied logback-test.xml from main due to conflict
rozza 3353da0
Merge branch 'main' into JAVA-5877
rozza 84889e2
Delete driver-core/src/test/resources - use testing/resources instead
rozza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| [submodule "specifications"] | ||
| path = driver-core/src/test/resources/specifications | ||
| path = testing/resources/specifications | ||
| url = https://github.com/mongodb/specifications |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright 2008-present MongoDB, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.bson.json; | ||
|
|
||
| import java.util.regex.Pattern; | ||
|
|
||
| final class JsonDoubleHelper { | ||
|
|
||
| private static final Pattern POSITIVE_EXPONENT_PATTERN = Pattern.compile("E(\\d+)"); | ||
| private static final String POSITIVE_EXPONENT_REPLACER = "E+$1"; | ||
|
|
||
| static String toString(final double value) { | ||
| String doubleString = Double.toString(value); | ||
| return POSITIVE_EXPONENT_PATTERN.matcher(doubleString).replaceAll(POSITIVE_EXPONENT_REPLACER); | ||
| } | ||
|
|
||
| private JsonDoubleHelper() { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the rationale for moving the validation into the constructor. The reason it wasn’t placed there originally is that we had two different validation paths:
IllegalArgumentException(isTrueArgument(...)).isTrue(...)). See: BinaryVectorHelper.java#L97-L98.Putting the checks in the constructor means we now perform the same validation twice, which was something we tried to avoid for performance considerations initially, given that these checks could be executed frequently. We haven’t measured the exact impact, but it does introduce extra work.
As a side note:
We still haven’t fully aligned on validation boundaries, whether to validate strictly at API entry points (and accept duplication) or centralize deeper in the code. The driver currently uses both approaches in different areas. This might be worth discussing as a team at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed from the checks from helper to just be in the constructor - as we have a public API
BsonVector.packedBitVectorthat also requires the validation. This removes the double validation but does put the validation deeper in the code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up reverting that - as we return different errors depending on the scenarion - decoding data or constructing a new instance.
I think the cost will be minor of the duplicated check, however the public API does also require guarding for invalid data.
Its a slightly unusual scenario - we could add a flag to constructor to remove the extra checks but that would also be setting up a new convention.