-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add Client Metadata Update Support. #1708
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
9753f28
889d5c8
4b3065c
2a684bf
28c1844
371ce0b
972fe9d
bcf9cc8
179b262
bc43ba0
3f5fc91
61192d8
e9f8dd6
95c1bb1
dd63a49
89d67bb
8a18d39
f296d0c
a8dc4fb
8ade58b
71350fa
9890aa1
28f7d88
246a040
8a58294
15ecef8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -180,6 +180,31 @@ static boolean clientMetadataDocumentTooLarge(final BsonDocument document) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return buffer.getPosition() > MAXIMUM_CLIENT_METADATA_ENCODED_SIZE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public static BsonDocument updateClientMedataDocument(final BsonDocument clientMetadataDocument, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Renamed, thanks! |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
final MongoDriverInformation mongoDriverInformation) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BsonDocument updatedClientMetadataDocument = clientMetadataDocument.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BsonDocument driverInformation = clientMetadataDocument.getDocument("driver"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if the user doesn't supply the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean during initial metadata creation or subsequent updates? For updates: mongo-java-driver/driver-core/src/main/com/mongodb/MongoDriverInformation.java Lines 158 to 172 in d65def4
For initial metadata creation: mongo-java-driver/driver-core/src/main/com/mongodb/internal/connection/ClientMetadataHelper.java Lines 296 to 305 in 8ade58b
This is also tested via prose tests: Lines 75 to 82 in 71350fa
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MongoDriverInformation.Builder builder = MongoDriverInformation.builder(mongoDriverInformation) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.driverName(driverInformation.getString("name").getValue()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.driverVersion(driverInformation.getString("version").getValue()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (updatedClientMetadataDocument.containsKey("platform")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
builder.driverPlatform(updatedClientMetadataDocument.getString("platform").getValue()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MongoDriverInformation updatedDriverInformation = builder.build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tryWithLimit(updatedClientMetadataDocument, d -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
putAtPath(d, "driver.name", listToString(updatedDriverInformation.getDriverNames())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
putAtPath(d, "driver.version", listToString(updatedDriverInformation.getDriverVersions())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tryWithLimit(updatedClientMetadataDocument, d -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
putAtPath(d, "platform", listToString(updatedDriverInformation.getDriverPlatforms())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return updatedClientMetadataDocument; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public enum ContainerRuntime { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DOCKER("docker") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
AssertJ has been used in this PR and added to test-base as it is a useful library that could be shared across all modules.