-
Notifications
You must be signed in to change notification settings - Fork 1.5k
ClientMetaData refactoring #1807
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 4 commits
6b7dab5
cda23e3
70c8179
c85a77c
3803341
3910d5c
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* Copyright 2010 The Guava Authors | ||
* Copyright 2011 The Guava Authors | ||
* | ||
* 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 com.mongodb.annotations; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Signifies that a public API element is intended for internal use only. | ||
* | ||
* <p>It is inadvisable for <i>applications</i> to use Internal APIs as they are intended for <b>internal library purposes</b> only.</p> | ||
*/ | ||
@Retention(RetentionPolicy.CLASS) | ||
@Target({ | ||
ElementType.ANNOTATION_TYPE, | ||
ElementType.CONSTRUCTOR, | ||
ElementType.FIELD, | ||
ElementType.METHOD, | ||
ElementType.PACKAGE, | ||
ElementType.TYPE }) | ||
@Documented | ||
@Alpha(Reason.CLIENT) | ||
public @interface Internal { | ||
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. Had to add an internal method If this ok, then I'll add a ticket to annotation each of 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. We already have ![]() 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. I didnt want to misuse that as it's not for testing. It's needed for the |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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 com.mongodb.internal.client; | ||
|
||
import com.mongodb.lang.Nullable; | ||
|
||
import java.util.Objects; | ||
|
||
public final class DriverInformation { | ||
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. The changes required by the spec ensure that driver information as a whole can be checked for equality - so that duplicates aren't appended. |
||
@Nullable | ||
private final String driverName; | ||
@Nullable | ||
private final String driverVersion; | ||
@Nullable | ||
private final String driverPlatform; | ||
|
||
public DriverInformation(@Nullable final String driverName, | ||
@Nullable final String driverVersion, | ||
@Nullable final String driverPlatform) { | ||
this.driverName = driverName == null || driverName.isEmpty() ? null : driverName; | ||
this.driverVersion = driverVersion == null || driverVersion.isEmpty() ? null : driverVersion; | ||
this.driverPlatform = driverPlatform == null || driverPlatform.isEmpty() ? null : driverPlatform; | ||
} | ||
|
||
@Nullable | ||
public String getDriverName() { | ||
return driverName; | ||
} | ||
|
||
@Nullable | ||
public String getDriverVersion() { | ||
return driverVersion; | ||
} | ||
|
||
@Nullable | ||
public String getDriverPlatform() { | ||
return driverPlatform; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
final DriverInformation that = (DriverInformation) o; | ||
return Objects.equals(driverName, that.driverName) | ||
&& Objects.equals(driverVersion, that.driverVersion) | ||
&& Objects.equals(driverPlatform, that.driverPlatform); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hashCode(driverName); | ||
result = 31 * result + Objects.hashCode(driverVersion); | ||
result = 31 * result + Objects.hashCode(driverPlatform); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DriverInformation{" | ||
+ "driverName='" + driverName + '\'' | ||
+ ", driverVersion='" + driverVersion + '\'' | ||
+ ", driverPlatform='" + driverPlatform + '\'' | ||
+ '}'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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 com.mongodb.internal.client; | ||
|
||
import com.mongodb.internal.build.MongoDriverVersion; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static com.mongodb.assertions.Assertions.fail; | ||
import static java.lang.String.format; | ||
import static java.lang.System.getProperty; | ||
|
||
public final class DriverInformationHelper { | ||
|
||
public static final DriverInformation INITIAL_DRIVER_INFORMATION = | ||
new DriverInformation(MongoDriverVersion.NAME, MongoDriverVersion.VERSION, | ||
format("Java/%s/%s", getProperty("java.vendor", "unknown-vendor"), | ||
getProperty("java.runtime.version", "unknown-version"))); | ||
|
||
public static List<String> getNames(final List<DriverInformation> driverInformation) { | ||
return getDriverField(DriverInformation::getDriverName, driverInformation); | ||
} | ||
|
||
public static List<String> getVersions(final List<DriverInformation> driverInformation) { | ||
return getDriverInformation(DriverInformation::getDriverVersion, driverInformation); | ||
} | ||
|
||
public static List<String> getPlatforms(final List<DriverInformation> driverInformation) { | ||
return getDriverField(DriverInformation::getDriverPlatform, driverInformation); | ||
} | ||
|
||
private static List<String> getDriverField(final Function<DriverInformation, String> fieldSupplier, | ||
final List<DriverInformation> driverInformation) { | ||
return Collections.unmodifiableList(driverInformation.stream() | ||
.map(fieldSupplier) | ||
.filter(Objects::nonNull) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
private DriverInformationHelper() { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* This package contains classes for internal client functionality. | ||
*/ | ||
|
||
@NonNullApi | ||
nhachicha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
package com.mongodb.internal.client; | ||
|
||
import com.mongodb.lang.NonNullApi; |
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.
Using lists of Strings, no longer works for the new test cases - as it meant we couldn't check for duplicates effectively.