diff --git a/.evergreen/.evg.yml b/.evergreen/.evg.yml index a57f6473b6f..7c1ae2250cc 100644 --- a/.evergreen/.evg.yml +++ b/.evergreen/.evg.yml @@ -509,24 +509,6 @@ functions: mongo --nodb setup.js aws_e2e_ecs.js cd - - "run atlas data lake test": - - command: shell.exec - type: test - params: - working_dir: "src" - script: | - ${PREPARE_SHELL} - JAVA_VERSION=${JAVA_VERSION} .evergreen/run-atlas-data-lake-test.sh - - "run atlas search test": - - command: shell.exec - type: test - params: - working_dir: "src" - script: | - ${PREPARE_SHELL} - MONGODB_URI="${atlas_search_uri}" .evergreen/run-atlas-search-tests.sh - "run-ocsp-test": - command: shell.exec type: test @@ -627,19 +609,6 @@ functions: ${PREPARE_SHELL} PROJECT_DIRECTORY=${PROJECT_DIRECTORY} JAVA_VERSION=${JAVA_VERSION} TOPOLOGY=${TOPOLOGY} STORAGE_ENGINE=${STORAGE_ENGINE} MONGODB_URI="${MONGODB_URI}" .evergreen/run-mmapv1-storage-test.sh - "run atlas test": - - command: shell.exec - type: test - params: - silent: true - working_dir: "src" - script: | - # DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does) - # The connection strings are pipe-delimited - JAVA_VERSION="8" \ - MONGODB_URIS="${atlas_free_tier_uri}|${atlas_replica_set_uri}|${atlas_sharded_uri}|${atlas_tls_v11_uri}|${atlas_tls_v12_uri}|${atlas_free_tier_uri_srv}|${atlas_replica_set_uri_srv}|${atlas_sharded_uri_srv}|${atlas_tls_v11_uri_srv}|${atlas_tls_v12_uri_srv}|${atlas_serverless_uri}|${atlas_serverless_uri_srv}" \ - .evergreen/run-connectivity-tests.sh - run socks5 tests: - command: shell.exec type: test @@ -794,15 +763,7 @@ functions: shell: bash script: | ${PREPARE_SHELL} - cd "$MONGO_ORCHESTRATION_HOME" - # source the mongo-orchestration virtualenv if it exists - if [ -f venv/bin/activate ]; then - . venv/bin/activate - elif [ -f venv/Scripts/activate ]; then - . venv/Scripts/activate - fi - mongo-orchestration stop || true - cd - + bash ${DRIVERS_TOOLS}/.evergreen/stop-orchestration.sh || true rm -rf $DRIVERS_TOOLS || true "fix absolute paths": @@ -837,6 +798,30 @@ functions: ${PREPARE_SHELL} MONGODB_URI="${MONGODB_URI}" JAVA_VERSION="${JAVA_VERSION}" .evergreen/run-graalvm-native-image-app.sh + "oidc-auth-test-k8s-func": + - command: shell.exec + type: test + params: + shell: bash + include_expansions_in_env: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"] + script: |- + set -o errexit + ${PREPARE_SHELL} + export K8S_VARIANT=${VARIANT} + cd src + git add . + git commit --allow-empty -m "add files" + # uncompressed tar used to allow appending .git folder + export K8S_DRIVERS_TAR_FILE=/tmp/mongo-java-driver.tar + git archive -o $K8S_DRIVERS_TAR_FILE HEAD + tar -rf $K8S_DRIVERS_TAR_FILE .git + export K8S_TEST_CMD="OIDC_ENV=k8s VARIANT=${VARIANT} ./.evergreen/run-mongodb-oidc-test.sh" + bash $DRIVERS_TOOLS/.evergreen/auth_oidc/k8s/setup-pod.sh + bash $DRIVERS_TOOLS/.evergreen/auth_oidc/k8s/run-self-test.sh + source $DRIVERS_TOOLS/.evergreen/auth_oidc/k8s/secrets-export.sh + bash $DRIVERS_TOOLS/.evergreen/auth_oidc/k8s/run-driver-test.sh + bash $DRIVERS_TOOLS/.evergreen/auth_oidc/k8s/teardown-pod.sh + # Anchors pre: @@ -960,6 +945,22 @@ tasks: export GCPOIDC_TEST_CMD="OIDC_ENV=gcp ./.evergreen/run-mongodb-oidc-test.sh" bash $DRIVERS_TOOLS/.evergreen/auth_oidc/gcp/run-driver-test.sh + - name: "oidc-auth-test-k8s" + commands: + - command: ec2.assume_role + params: + role_arn: ${aws_test_secrets_role} + duration_seconds: 1800 + - func: "oidc-auth-test-k8s-func" + vars: + VARIANT: eks + - func: "oidc-auth-test-k8s-func" + vars: + VARIANT: aks + - func: "oidc-auth-test-k8s-func" + vars: + VARIANT: gke + - name: serverless-test commands: - func: "run serverless" @@ -1462,14 +1463,50 @@ tasks: OCSP_MUST_STAPLE: "false" OCSP_TLS_SHOULD_SUCCEED: "0" - - name: "atlas-data-lake-test" + - name: "atlas-data-lake-task" commands: - func: "bootstrap mongohoused" - - func: "run atlas data lake test" + - command: shell.exec + type: test + params: + working_dir: "src" + script: | + ${PREPARE_SHELL} + JAVA_VERSION=${JAVA_VERSION} .evergreen/run-atlas-data-lake-test.sh - - name: "atlas-search-test" + - name: "atlas-search-task" commands: - - func: "run atlas search test" + - command: shell.exec + type: test + params: + working_dir: "src" + script: | + ${PREPARE_SHELL} + MONGODB_URI="${atlas_search_uri}" .evergreen/run-atlas-search-tests.sh + + - name: "atlas-connectivity-task" + commands: + - command: shell.exec + type: test + params: + silent: true + working_dir: "src" + script: | + # DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does) + # The connection strings are pipe-delimited + MONGODB_URIS="${atlas_free_tier_uri}|${atlas_replica_set_uri}|${atlas_sharded_uri}|${atlas_tls_v11_uri}|${atlas_tls_v12_uri}|${atlas_free_tier_uri_srv}|${atlas_replica_set_uri_srv}|${atlas_sharded_uri_srv}|${atlas_tls_v11_uri_srv}|${atlas_tls_v12_uri_srv}|${atlas_serverless_uri}|${atlas_serverless_uri_srv}" \ + JAVA_VERSION="8" \ + .evergreen/run-connectivity-tests.sh + + - name: "atlas-search-index-management-task" + commands: + - command: subprocess.exec + params: + working_dir: src + binary: bash + add_expansions_to_env: true + args: + - .evergreen/run-atlas-search-index-management-tests.sh - name: "gssapi-auth-test" commands: @@ -1490,20 +1527,6 @@ tasks: - func: "bootstrap mongo-orchestration" - func: "run netty tests" - - name: "atlas-test" - commands: - - func: "run atlas test" - - - name: "test-atlas-search-index-helpers" - commands: - - command: subprocess.exec - params: - working_dir: src - binary: bash - add_expansions_to_env: true - args: - - .evergreen/run-atlas-search-index-management-tests.sh - - name: publish-snapshot depends_on: - variant: "static-checks" @@ -1536,7 +1559,7 @@ tasks: - func: "run perf tests" - func: "send dashboard data" - - name: "test-aws-lambda-deployed" + - name: "aws-lambda-deployed-task" commands: - command: ec2.assume_role params: @@ -1630,7 +1653,6 @@ tasks: echo "Untarring file ... begin" GCPKMS_CMD="tar xf mongo-java-driver.tgz" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh echo "Untarring file ... end" - - command: shell.exec type: test params: @@ -1918,11 +1940,12 @@ axes: batchtime: 10080 # 7 days task_groups: - - name: test_atlas_task_group_search_indexes + - name: "atlas-deployed-task-group" setup_group: - func: fetch source - func: prepare resources - command: subprocess.exec + type: setup params: working_dir: src binary: bash @@ -1934,6 +1957,7 @@ task_groups: file: src/atlas-expansion.yml teardown_group: - command: subprocess.exec + type: setup params: working_dir: src binary: bash @@ -1943,7 +1967,9 @@ task_groups: setup_group_can_fail_task: true setup_group_timeout_secs: 1800 tasks: - - test-atlas-search-index-helpers + - "atlas-search-index-management-task" + - "aws-lambda-deployed-task" + - name: testgcpkms_task_group setup_group_can_fail_task: true setup_group_timeout_secs: 1800 # 30 minutes @@ -1979,6 +2005,7 @@ task_groups: $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/delete-instance.sh tasks: - testgcpkms-task + - name: testazurekms_task_group setup_group_can_fail_task: true setup_group_timeout_secs: 1800 # 30 minutes @@ -2023,34 +2050,8 @@ task_groups: $DRIVERS_TOOLS/.evergreen/csfle/azurekms/delete-vm.sh tasks: - testazurekms-task - - name: test_atlas_task_group - setup_group: - - func: fetch source - - func: prepare resources - - command: subprocess.exec - params: - working_dir: src - binary: bash - add_expansions_to_env: true - args: - - ${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh - - command: expansions.update - params: - file: src/atlas-expansion.yml - teardown_group: - - command: subprocess.exec - params: - working_dir: src - binary: bash - add_expansions_to_env: true - args: - - ${DRIVERS_TOOLS}/.evergreen/atlas/teardown-atlas-cluster.sh - setup_group_can_fail_task: true - setup_group_timeout_secs: 1800 - tasks: - - test-aws-lambda-deployed - - name: testoidc_task_group + - name: test-oidc-task-group setup_group: - func: fetch source - func: prepare resources @@ -2075,7 +2076,7 @@ task_groups: tasks: - oidc-auth-test - - name: testazureoidc_task_group + - name: test-oidc-azure-task-group setup_group: - func: fetch source - func: prepare resources @@ -2098,7 +2099,7 @@ task_groups: tasks: - oidc-auth-test-azure - - name: testgcpoidc_task_group + - name: test-oidc-gcp-task-group setup_group: - func: fetch source - func: prepare resources @@ -2122,6 +2123,33 @@ task_groups: tasks: - oidc-auth-test-gcp + - name: test-oidc-k8s-task-group + setup_group_can_fail_task: true + setup_group_timeout_secs: 1800 + teardown_task_can_fail_task: true + teardown_group_timeout_secs: 180 + setup_group: + - func: fetch source + - func: prepare resources + - func: fix absolute paths + - command: ec2.assume_role + params: + role_arn: ${aws_test_secrets_role} + - command: subprocess.exec + params: + binary: bash + include_expansions_in_env: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"] + args: + - ${DRIVERS_TOOLS}/.evergreen/auth_oidc/k8s/setup.sh + teardown_group: + - command: subprocess.exec + params: + binary: bash + args: + - ${DRIVERS_TOOLS}/.evergreen/auth_oidc/k8s/teardown.sh + tasks: + - oidc-auth-test-k8s + buildvariants: # Test packaging and other release related routines @@ -2283,43 +2311,38 @@ buildvariants: tasks: - name: "perf" -- name: rhel8-test-atlas - display_name: Atlas Cluster Tests - run_on: rhel80-large - tasks: - - test_atlas_task_group - - name: plain-auth-test display_name: "PLAIN (LDAP) Auth test" run_on: rhel80-small tasks: - name: "plain-auth-test" -- name: rhel80-test-search-indexes - display_name: Atlas Search Index Management Tests - run_on: rhel80-small - tasks: - - name: "test_atlas_task_group_search_indexes" - - name: "oidc-auth-test" display_name: "OIDC Auth" run_on: ubuntu2204-small tasks: - - name: testoidc_task_group + - name: test-oidc-task-group batchtime: 20160 # 14 days -- name: testazureoidc-variant +- name: test-oidc-azure-variant display_name: "OIDC Auth Azure" run_on: ubuntu2204-small tasks: - - name: testazureoidc_task_group + - name: test-oidc-azure-task-group batchtime: 20160 # 14 days -- name: testgcpoidc-variant +- name: test-oidc-gcp-variant display_name: "OIDC Auth GCP" run_on: ubuntu2204-small tasks: - - name: testgcpoidc_task_group + - name: test-oidc-gcp-task-group + batchtime: 20160 # 14 days + +- name: test-oidc-k8s-variant + display_name: "OIDC Auth K8S" + run_on: ubuntu2204-small + tasks: + - name: test-oidc-k8s-task-group batchtime: 20160 # 14 days - matrix_name: "aws-auth-test" @@ -2355,23 +2378,19 @@ buildvariants: tasks: - name: ".ocsp" -- name: atlas-data-lake-test - display_name: "Atlas Data Lake test" - run_on: ubuntu2004-small - tasks: - - name: "atlas-data-lake-test" - -- name: atlas-test - display_name: "Atlas test" +- name: "atlas-search-variant" + display_name: "Atlas Tests" run_on: rhel80-small tasks: - - name: "atlas-test" + - name: "atlas-deployed-task-group" + - name: "atlas-search-task" + - name: "atlas-connectivity-task" -- name: atlas-search-test - display_name: "Atlas Search test" - run_on: rhel80-small +- name: atlas-data-lake-test + display_name: "Atlas Data Lake test" + run_on: ubuntu2004-small tasks: - - name: "atlas-search-test" + - name: "atlas-data-lake-task" - name: "reactive-streams-tck-test" display_name: "Reactive Streams TCK tests" diff --git a/.evergreen/publish.sh b/.evergreen/publish.sh index bfecc0ae865..e3f9f365d42 100755 --- a/.evergreen/publish.sh +++ b/.evergreen/publish.sh @@ -26,6 +26,6 @@ fi SYSTEM_PROPERTIES="-Dorg.gradle.internal.publish.checksums.insecure=true -Dorg.gradle.internal.http.connectionTimeout=120000 -Dorg.gradle.internal.http.socketTimeout=120000" ./gradlew -version -./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info ${TASK} +./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info ${TASK} # Scala 2.13 is published as result of this gradle execution. ./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info :bson-scala:${TASK} :driver-scala:${TASK} -PdefaultScalaVersions=2.12.12 ./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info :bson-scala:${TASK} :driver-scala:${TASK} -PdefaultScalaVersions=2.11.12 diff --git a/.evergreen/run-atlas-search-tests.sh b/.evergreen/run-atlas-search-tests.sh index 36cc981b3f4..f207647825f 100755 --- a/.evergreen/run-atlas-search-tests.sh +++ b/.evergreen/run-atlas-search-tests.sh @@ -16,4 +16,6 @@ echo "Running Atlas Search tests" ./gradlew --stacktrace --info \ -Dorg.mongodb.test.atlas.search=true \ -Dorg.mongodb.test.uri=${MONGODB_URI} \ - driver-core:test --tests AggregatesSearchIntegrationTest --tests AggregatesVectorSearchIntegrationTest + driver-core:test --tests AggregatesSearchIntegrationTest \ + --tests AggregatesBinaryVectorSearchIntegrationTest \ + --tests AggregatesSearchTest \ diff --git a/.evergreen/run-kotlin-tests.sh b/.evergreen/run-kotlin-tests.sh index fecceb28c53..a82c66e9e54 100755 --- a/.evergreen/run-kotlin-tests.sh +++ b/.evergreen/run-kotlin-tests.sh @@ -31,7 +31,10 @@ if [ "$SAFE_FOR_MULTI_MONGOS" == "true" ]; then export MULTI_MONGOS_URI_SYSTEM_PROPERTY="-Dorg.mongodb.test.multi.mongos.uri=${MONGODB_URI}" fi -echo "Running Kotlin tests" - ./gradlew -version -./gradlew kotlinCheck -Dorg.mongodb.test.uri=${MONGODB_URI} ${MULTI_MONGOS_URI_SYSTEM_PROPERTY} + +echo "Running Kotlin Unit Tests" +./gradlew :bson-kotlin:test :bson-kotlinx:test :driver-kotlin-sync:test :driver-kotlin-coroutine:test :driver-kotlin-extensions:test + +echo "Running Kotlin Integration Tests" +./gradlew :driver-kotlin-sync:integrationTest :driver-kotlin-coroutine:integrationTest -Dorg.mongodb.test.uri=${MONGODB_URI} ${MULTI_MONGOS_URI_SYSTEM_PROPERTY} diff --git a/.evergreen/run-mongodb-oidc-test.sh b/.evergreen/run-mongodb-oidc-test.sh index ec2b2c19610..55b0599fd02 100755 --- a/.evergreen/run-mongodb-oidc-test.sh +++ b/.evergreen/run-mongodb-oidc-test.sh @@ -19,6 +19,16 @@ elif [ $OIDC_ENV == "azure" ]; then source ./env.sh elif [ $OIDC_ENV == "gcp" ]; then source ./secrets-export.sh +elif [ $OIDC_ENV == "k8s" ]; then + # Make sure K8S_VARIANT is set. + if [ -z "$K8S_VARIANT" ]; then + echo "Must specify K8S_VARIANT" + popd + exit 1 + fi + + # fix for git permissions issue: + git config --global --add safe.directory /tmp/test else echo "Unrecognized OIDC_ENV $OIDC_ENV" exit 1 diff --git a/.evergreen/ssdlc-report.sh b/.evergreen/ssdlc-report.sh index 2958edb4327..b97eff6d8ba 100755 --- a/.evergreen/ssdlc-report.sh +++ b/.evergreen/ssdlc-report.sh @@ -40,10 +40,10 @@ declare -r EVERGREEN_BUILD_URL_PREFIX="https://spruce.mongodb.com/version" declare -r GIT_TAG="r${PRODUCT_VERSION}" GIT_COMMIT_HASH="$(git rev-list --ignore-missing -n 1 "${GIT_TAG}")" set +e - GIT_BRANCH_MASTER="$(git branch -a --contains "${GIT_TAG}" | grep 'master$')" + GIT_BRANCH_DEFAULT="$(git branch -a --contains "${GIT_TAG}" | grep 'main$')" GIT_BRANCH_PATCH="$(git branch -a --contains "${GIT_TAG}" | grep '\.x$')" set -e -if [ -n "${GIT_BRANCH_MASTER}" ]; then +if [ -n "${GIT_BRANCH_DEFAULT}" ]; then declare -r EVERGREEN_BUILD_URL="${EVERGREEN_BUILD_URL_PREFIX}/${EVERGREEN_PROJECT_NAME_PREFIX}_${GIT_COMMIT_HASH}" elif [ -n "${GIT_BRANCH_PATCH}" ]; then # strip out the patch version @@ -65,7 +65,7 @@ printf "\nCreating SpotBugs SARIF reports\n" set +e # This `gradlew` command is expected to exit with a non-zero exit status, # because it reports all the findings that we normally explicitly exclude as "No Fix Needed"/"False Positive". - ./gradlew -PssdlcReport.enabled=true --continue -x test -x integrationTest -x spotlessApply check scalaCheck kotlinCheck + ./gradlew -PssdlcReport.enabled=true --continue -x test -x integrationTest -x spotlessApply check scalaCheck set -e printf "\nSpotBugs created the following SARIF reports\n" IFS=$'\n' diff --git a/.evergreen/static-checks.sh b/.evergreen/static-checks.sh index 8896692ca66..8b65b15e9a5 100755 --- a/.evergreen/static-checks.sh +++ b/.evergreen/static-checks.sh @@ -12,4 +12,4 @@ RELATIVE_DIR_PATH="$(dirname "${BASH_SOURCE[0]:-$0}")" echo "Compiling JVM drivers" ./gradlew -version -./gradlew -PxmlReports.enabled=true --info -x test -x integrationTest -x spotlessApply clean check scalaCheck kotlinCheck jar testClasses docs +./gradlew -PxmlReports.enabled=true --info -x test -x integrationTest -x spotlessApply clean check scalaCheck jar testClasses docs diff --git a/THIRD-PARTY-NOTICES b/THIRD-PARTY-NOTICES index 7229bf71926..f881b103544 100644 --- a/THIRD-PARTY-NOTICES +++ b/THIRD-PARTY-NOTICES @@ -161,3 +161,26 @@ https://github.com/mongodb/mongo-java-driver. See the License for the specific language governing permissions and limitations under the License. +8) The following files (originally from https://github.com/Litote/kmongo): + + Filters.kt + Properties.kt + KPropertyPath.kt + FiltersTest.kt + KPropertiesTest.kt + + Copyright 2008-present MongoDB, Inc. + Copyright (C) 2016/2022 Litote + + 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. + diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts new file mode 100644 index 00000000000..5d1fb81c384 --- /dev/null +++ b/bom/build.gradle.kts @@ -0,0 +1,23 @@ +group = "org.mongodb" +description = "This Bill of Materials POM simplifies dependency management when referencing multiple" + + " MongoDB Java Driver artifacts in projects using Gradle or Maven." + +dependencies { + constraints { + api(project(":mongodb-crypt")) + api(project(":driver-core")) + api(project(":bson")) + api(project(":bson-record-codec")) + + api(project(":driver-sync")) + api(project(":driver-reactive-streams")) + + api(project(":bson-kotlin")) + api(project(":bson-kotlinx")) + api(project(":driver-kotlin-coroutine")) + api(project(":driver-kotlin-sync")) + + api(project(":bson-scala")) + api(project(":driver-scala")) + } +} diff --git a/bson-kotlin/build.gradle.kts b/bson-kotlin/build.gradle.kts index 3840b3169cf..45e8c9c0e5d 100644 --- a/bson-kotlin/build.gradle.kts +++ b/bson-kotlin/build.gradle.kts @@ -111,13 +111,6 @@ spotbugs { showProgress.set(true) } // =========================== // Test Configuration // =========================== -tasks.create("kotlinCheck") { - description = "Runs all the kotlin checks" - group = "verification" - - dependsOn("clean", "check") - tasks.findByName("check")?.mustRunAfter("clean") -} tasks.test { useJUnitPlatform() } diff --git a/bson-kotlinx/build.gradle.kts b/bson-kotlinx/build.gradle.kts index a278b4a3ab2..ac0b07f18eb 100644 --- a/bson-kotlinx/build.gradle.kts +++ b/bson-kotlinx/build.gradle.kts @@ -128,13 +128,6 @@ spotbugs { showProgress.set(true) } // =========================== // Test Configuration // =========================== -tasks.create("kotlinCheck") { - description = "Runs all the kotlin checks" - group = "verification" - - dependsOn("clean", "check") - tasks.findByName("check")?.mustRunAfter("clean") -} tasks.test { useJUnitPlatform() } diff --git a/bson/src/main/org/bson/AbstractBsonWriter.java b/bson/src/main/org/bson/AbstractBsonWriter.java index a7cc978f8ba..8a8b238e8af 100644 --- a/bson/src/main/org/bson/AbstractBsonWriter.java +++ b/bson/src/main/org/bson/AbstractBsonWriter.java @@ -748,6 +748,15 @@ protected void throwInvalidState(final String methodName, final State... validSt methodName, validStatesString, state)); } + /** + * {@inheritDoc} + *

+ * The {@link #flush()} method of {@link AbstractBsonWriter} does nothing.

+ */ + @Override + public void flush() { + } + @Override public void close() { closed = true; diff --git a/bson/src/main/org/bson/BSONCallbackAdapter.java b/bson/src/main/org/bson/BSONCallbackAdapter.java index d00a2eaecbf..1d8b5ffe746 100644 --- a/bson/src/main/org/bson/BSONCallbackAdapter.java +++ b/bson/src/main/org/bson/BSONCallbackAdapter.java @@ -39,11 +39,6 @@ protected BSONCallbackAdapter(final BsonWriterSettings settings, final BSONCallb this.bsonCallback = bsonCallback; } - @Override - public void flush() { - //Looks like should be no-op? - } - @Override public void doWriteStartDocument() { BsonContextType contextType = getState() == State.SCOPE_DOCUMENT diff --git a/bson/src/main/org/bson/Vector.java b/bson/src/main/org/bson/BinaryVector.java similarity index 76% rename from bson/src/main/org/bson/Vector.java rename to bson/src/main/org/bson/BinaryVector.java index d267387d727..273b4a0e5e9 100644 --- a/bson/src/main/org/bson/Vector.java +++ b/bson/src/main/org/bson/BinaryVector.java @@ -16,16 +16,15 @@ package org.bson; +import org.bson.annotations.Beta; +import org.bson.annotations.Reason; + import static org.bson.assertions.Assertions.isTrueArgument; import static org.bson.assertions.Assertions.notNull; /** - * Represents a vector that is stored and retrieved using the BSON Binary Subtype 9 format. - * This class supports multiple vector {@link DataType}'s and provides static methods to create - * vectors. - *

- * Vectors are densely packed arrays of numbers, all the same type, which are stored efficiently - * in BSON using a binary format. + * Binary Vectors are densely packed arrays of numbers, all the same type, which are stored and retrieved efficiently using the BSON Binary + * Subtype 9 format. This class supports multiple vector {@link DataType}'s and provides static methods to create vectors. *

* NOTE: This class should be treated as sealed: it must not be extended or implemented by consumers of the library. * @@ -33,10 +32,10 @@ * @see BsonBinary * @since 5.3 */ -public abstract class Vector { +public abstract class BinaryVector { private final DataType dataType; - Vector(final DataType dataType) { + BinaryVector(final DataType dataType) { this.dataType = dataType; } @@ -56,18 +55,19 @@ public abstract class Vector { * *

* NOTE: The byte array `data` is not copied; changes to the provided array will be reflected - * in the created {@link PackedBitVector} instance. + * in the created {@link PackedBitBinaryVector} instance. * * @param data The byte array representing the packed bit vector data. Each byte can store 8 bits. * @param padding The number of least-significant bits (0 to 7) to ignore in the final byte of the vector data. - * @return A {@link PackedBitVector} instance with the {@link DataType#PACKED_BIT} data type. + * @return A {@link PackedBitBinaryVector} instance with the {@link DataType#PACKED_BIT} data type. * @throws IllegalArgumentException If the padding value is greater than 7. */ - public static PackedBitVector packedBitVector(final byte[] data, final byte padding) { + @Beta(Reason.SERVER) + public static PackedBitBinaryVector packedBitVector(final byte[] data, final byte padding) { notNull("data", data); isTrueArgument("Padding must be between 0 and 7 bits. Provided padding: " + padding, padding >= 0 && padding <= 7); isTrueArgument("Padding must be 0 if vector is empty. Provided padding: " + padding, padding == 0 || data.length > 0); - return new PackedBitVector(data, padding); + return new PackedBitBinaryVector(data, padding); } /** @@ -77,14 +77,14 @@ public static PackedBitVector packedBitVector(final byte[] data, final byte padd * with values in the range [-128, 127].

*

* NOTE: The byte array `data` is not copied; changes to the provided array will be reflected - * in the created {@link Int8Vector} instance. + * in the created {@link Int8BinaryVector} instance. * * @param data The byte array representing the {@link DataType#INT8} vector data. - * @return A {@link Int8Vector} instance with the {@link DataType#INT8} data type. + * @return A {@link Int8BinaryVector} instance with the {@link DataType#INT8} data type. */ - public static Int8Vector int8Vector(final byte[] data) { + public static Int8BinaryVector int8Vector(final byte[] data) { notNull("data", data); - return new Int8Vector(data); + return new Int8BinaryVector(data); } /** @@ -93,50 +93,50 @@ public static Int8Vector int8Vector(final byte[] data) { * A {@link DataType#FLOAT32} vector is a vector of floating-point numbers, where each element in the vector is a float.

*

* NOTE: The float array `data` is not copied; changes to the provided array will be reflected - * in the created {@link Float32Vector} instance. + * in the created {@link Float32BinaryVector} instance. * * @param data The float array representing the {@link DataType#FLOAT32} vector data. - * @return A {@link Float32Vector} instance with the {@link DataType#FLOAT32} data type. + * @return A {@link Float32BinaryVector} instance with the {@link DataType#FLOAT32} data type. */ - public static Float32Vector floatVector(final float[] data) { + public static Float32BinaryVector floatVector(final float[] data) { notNull("data", data); - return new Float32Vector(data); + return new Float32BinaryVector(data); } /** - * Returns the {@link PackedBitVector}. + * Returns the {@link PackedBitBinaryVector}. * - * @return {@link PackedBitVector}. + * @return {@link PackedBitBinaryVector}. * @throws IllegalStateException if this vector is not of type {@link DataType#PACKED_BIT}. Use {@link #getDataType()} to check the vector * type before calling this method. */ - public PackedBitVector asPackedBitVector() { + public PackedBitBinaryVector asPackedBitVector() { ensureType(DataType.PACKED_BIT); - return (PackedBitVector) this; + return (PackedBitBinaryVector) this; } /** - * Returns the {@link Int8Vector}. + * Returns the {@link Int8BinaryVector}. * - * @return {@link Int8Vector}. + * @return {@link Int8BinaryVector}. * @throws IllegalStateException if this vector is not of type {@link DataType#INT8}. Use {@link #getDataType()} to check the vector * type before calling this method. */ - public Int8Vector asInt8Vector() { + public Int8BinaryVector asInt8Vector() { ensureType(DataType.INT8); - return (Int8Vector) this; + return (Int8BinaryVector) this; } /** - * Returns the {@link Float32Vector}. + * Returns the {@link Float32BinaryVector}. * - * @return {@link Float32Vector}. + * @return {@link Float32BinaryVector}. * @throws IllegalStateException if this vector is not of type {@link DataType#FLOAT32}. Use {@link #getDataType()} to check the vector * type before calling this method. */ - public Float32Vector asFloat32Vector() { + public Float32BinaryVector asFloat32Vector() { ensureType(DataType.FLOAT32); - return (Float32Vector) this; + return (Float32BinaryVector) this; } /** diff --git a/bson/src/main/org/bson/BsonBinary.java b/bson/src/main/org/bson/BsonBinary.java index 8590c2920be..833a1b5ad29 100644 --- a/bson/src/main/org/bson/BsonBinary.java +++ b/bson/src/main/org/bson/BsonBinary.java @@ -18,12 +18,12 @@ import org.bson.assertions.Assertions; import org.bson.internal.UuidHelper; -import org.bson.internal.vector.VectorHelper; +import org.bson.internal.vector.BinaryVectorHelper; import java.util.Arrays; import java.util.UUID; -import static org.bson.internal.vector.VectorHelper.encodeVectorToBinary; +import static org.bson.internal.vector.BinaryVectorHelper.encodeVectorToBinary; /** * A representation of the BSON Binary type. Note that for performance reasons instances of this class are not immutable, @@ -93,12 +93,12 @@ public BsonBinary(final UUID uuid) { } /** - * Constructs a {@linkplain BsonBinarySubType#VECTOR subtype 9} {@link BsonBinary} from the given {@link Vector}. + * Constructs a {@linkplain BsonBinarySubType#VECTOR subtype 9} {@link BsonBinary} from the given {@link BinaryVector}. * - * @param vector the {@link Vector} + * @param vector the {@link BinaryVector} * @since 5.3 */ - public BsonBinary(final Vector vector) { + public BsonBinary(final BinaryVector vector) { if (vector == null) { throw new IllegalArgumentException("Vector must not be null"); } @@ -145,18 +145,18 @@ public UUID asUuid() { } /** - * Returns the binary as a {@link Vector}. The {@linkplain #getType() subtype} must be {@linkplain BsonBinarySubType#VECTOR 9}. + * Returns the binary as a {@link BinaryVector}. The {@linkplain #getType() subtype} must be {@linkplain BsonBinarySubType#VECTOR 9}. * * @return the vector * @throws BsonInvalidOperationException if the binary subtype is not {@link BsonBinarySubType#VECTOR}. * @since 5.3 */ - public Vector asVector() { + public BinaryVector asVector() { if (type != BsonBinarySubType.VECTOR.getValue()) { throw new BsonInvalidOperationException("type must be a Vector subtype."); } - return VectorHelper.decodeBinaryToVector(this.data); + return BinaryVectorHelper.decodeBinaryToVector(this.data); } /** diff --git a/bson/src/main/org/bson/BsonBinarySubType.java b/bson/src/main/org/bson/BsonBinarySubType.java index 7b5948b4efc..08c29e2ef09 100644 --- a/bson/src/main/org/bson/BsonBinarySubType.java +++ b/bson/src/main/org/bson/BsonBinarySubType.java @@ -78,7 +78,7 @@ public enum BsonBinarySubType { * * @mongodb.server.release 6.0 * @since 5.3 - * @see Vector + * @see BinaryVector */ VECTOR((byte) 0x09), diff --git a/bson/src/main/org/bson/BsonBinaryWriter.java b/bson/src/main/org/bson/BsonBinaryWriter.java index d9301fd5cb3..e6255ea8478 100644 --- a/bson/src/main/org/bson/BsonBinaryWriter.java +++ b/bson/src/main/org/bson/BsonBinaryWriter.java @@ -108,10 +108,6 @@ public BsonBinaryWriterSettings getBinaryWriterSettings() { return binaryWriterSettings; } - @Override - public void flush() { - } - @Override protected Context getContext() { return (Context) super.getContext(); diff --git a/bson/src/main/org/bson/BsonDocumentWriter.java b/bson/src/main/org/bson/BsonDocumentWriter.java index 7c36a368336..a34188645cd 100644 --- a/bson/src/main/org/bson/BsonDocumentWriter.java +++ b/bson/src/main/org/bson/BsonDocumentWriter.java @@ -194,10 +194,6 @@ public void doWriteUndefined() { write(new BsonUndefined()); } - @Override - public void flush() { - } - @Override protected Context getContext() { return (Context) super.getContext(); diff --git a/bson/src/main/org/bson/Float32Vector.java b/bson/src/main/org/bson/Float32BinaryVector.java similarity index 81% rename from bson/src/main/org/bson/Float32Vector.java rename to bson/src/main/org/bson/Float32BinaryVector.java index 9678003b72f..37d1b8abb6e 100644 --- a/bson/src/main/org/bson/Float32Vector.java +++ b/bson/src/main/org/bson/Float32BinaryVector.java @@ -23,30 +23,30 @@ /** * Represents a vector of 32-bit floating-point numbers, where each element in the vector is a float. *

- * The {@link Float32Vector} is used to store and retrieve data efficiently using the BSON Binary Subtype 9 format. + * The {@link Float32BinaryVector} is used to store and retrieve data efficiently using the BSON Binary Subtype 9 format. * * @mongodb.server.release 6.0 - * @see Vector#floatVector(float[]) - * @see BsonBinary#BsonBinary(Vector) + * @see BinaryVector#floatVector(float[]) + * @see BsonBinary#BsonBinary(BinaryVector) * @see BsonBinary#asVector() * @since 5.3 */ -public final class Float32Vector extends Vector { +public final class Float32BinaryVector extends BinaryVector { private final float[] data; - Float32Vector(final float[] vectorData) { + Float32BinaryVector(final float[] vectorData) { super(DataType.FLOAT32); this.data = assertNotNull(vectorData); } /** - * Retrieve the underlying float array representing this {@link Float32Vector}, where each float + * Retrieve the underlying float array representing this {@link Float32BinaryVector}, where each float * represents an element of a vector. *

* NOTE: The underlying float array is not copied; changes to the returned array will be reflected in this instance. * - * @return the underlying float array representing this {@link Float32Vector} vector. + * @return the underlying float array representing this {@link Float32BinaryVector} vector. */ public float[] getData() { return assertNotNull(data); @@ -60,7 +60,7 @@ public boolean equals(final Object o) { if (o == null || getClass() != o.getClass()) { return false; } - Float32Vector that = (Float32Vector) o; + Float32BinaryVector that = (Float32BinaryVector) o; return Arrays.equals(data, that.data); } diff --git a/bson/src/main/org/bson/Int8Vector.java b/bson/src/main/org/bson/Int8BinaryVector.java similarity index 81% rename from bson/src/main/org/bson/Int8Vector.java rename to bson/src/main/org/bson/Int8BinaryVector.java index b61e6bfee55..a851aff94ff 100644 --- a/bson/src/main/org/bson/Int8Vector.java +++ b/bson/src/main/org/bson/Int8BinaryVector.java @@ -24,30 +24,30 @@ /** * Represents a vector of 8-bit signed integers, where each element in the vector is a byte. *

- * The {@link Int8Vector} is used to store and retrieve data efficiently using the BSON Binary Subtype 9 format. + * The {@link Int8BinaryVector} is used to store and retrieve data efficiently using the BSON Binary Subtype 9 format. * * @mongodb.server.release 6.0 - * @see Vector#int8Vector(byte[]) - * @see BsonBinary#BsonBinary(Vector) + * @see BinaryVector#int8Vector(byte[]) + * @see BsonBinary#BsonBinary(BinaryVector) * @see BsonBinary#asVector() * @since 5.3 */ -public final class Int8Vector extends Vector { +public final class Int8BinaryVector extends BinaryVector { private byte[] data; - Int8Vector(final byte[] data) { + Int8BinaryVector(final byte[] data) { super(DataType.INT8); this.data = assertNotNull(data); } /** - * Retrieve the underlying byte array representing this {@link Int8Vector} vector, where each byte represents + * Retrieve the underlying byte array representing this {@link Int8BinaryVector} vector, where each byte represents * an element of a vector. *

* NOTE: The underlying byte array is not copied; changes to the returned array will be reflected in this instance. * - * @return the underlying byte array representing this {@link Int8Vector} vector. + * @return the underlying byte array representing this {@link Int8BinaryVector} vector. */ public byte[] getData() { return assertNotNull(data); @@ -61,7 +61,7 @@ public boolean equals(final Object o) { if (o == null || getClass() != o.getClass()) { return false; } - Int8Vector that = (Int8Vector) o; + Int8BinaryVector that = (Int8BinaryVector) o; return Objects.deepEquals(data, that.data); } diff --git a/bson/src/main/org/bson/PackedBitVector.java b/bson/src/main/org/bson/PackedBitBinaryVector.java similarity index 84% rename from bson/src/main/org/bson/PackedBitVector.java rename to bson/src/main/org/bson/PackedBitBinaryVector.java index a5dd8f4dcdf..33200650204 100644 --- a/bson/src/main/org/bson/PackedBitVector.java +++ b/bson/src/main/org/bson/PackedBitBinaryVector.java @@ -16,6 +16,9 @@ package org.bson; +import org.bson.annotations.Beta; +import org.bson.annotations.Reason; + import java.util.Arrays; import java.util.Objects; @@ -24,33 +27,34 @@ /** * Represents a packed bit vector, where each element of the vector is represented by a single bit (0 or 1). *

- * The {@link PackedBitVector} is used to store data efficiently using the BSON Binary Subtype 9 format. + * The {@link PackedBitBinaryVector} is used to store data efficiently using the BSON Binary Subtype 9 format. * * @mongodb.server.release 6.0 - * @see Vector#packedBitVector(byte[], byte) - * @see BsonBinary#BsonBinary(Vector) + * @see BinaryVector#packedBitVector(byte[], byte) + * @see BsonBinary#BsonBinary(BinaryVector) * @see BsonBinary#asVector() * @since 5.3 */ -public final class PackedBitVector extends Vector { +@Beta(Reason.SERVER) +public final class PackedBitBinaryVector extends BinaryVector { private final byte padding; private final byte[] data; - PackedBitVector(final byte[] data, final byte padding) { + PackedBitBinaryVector(final byte[] data, final byte padding) { super(DataType.PACKED_BIT); this.data = assertNotNull(data); this.padding = padding; } /** - * Retrieve the underlying byte array representing this {@link PackedBitVector} vector, where + * Retrieve the underlying byte array representing this {@link PackedBitBinaryVector} vector, where * each bit represents an element of the vector (either 0 or 1). *

* Note that the {@linkplain #getPadding() padding value} should be considered when interpreting the final byte of the array, * as it indicates how many least-significant bits are to be ignored. * - * @return the underlying byte array representing this {@link PackedBitVector} vector. + * @return the underlying byte array representing this {@link PackedBitBinaryVector} vector. * @see #getPadding() */ public byte[] getData() { @@ -81,7 +85,7 @@ public boolean equals(final Object o) { if (o == null || getClass() != o.getClass()) { return false; } - PackedBitVector that = (PackedBitVector) o; + PackedBitBinaryVector that = (PackedBitBinaryVector) o; return padding == that.padding && Arrays.equals(data, that.data); } diff --git a/bson/src/main/org/bson/annotations/Beta.java b/bson/src/main/org/bson/annotations/Beta.java new file mode 100644 index 00000000000..0db9171952c --- /dev/null +++ b/bson/src/main/org/bson/annotations/Beta.java @@ -0,0 +1,56 @@ +/* + * 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 org.bson.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 (public class, method or field) is subject to + * incompatible changes, or even removal, in a future release. An API bearing + * this annotation is exempt from any compatibility guarantees made by its + * containing library. Note that the presence of this annotation implies nothing + * about the quality or performance of the API in question, only the fact that + * it is not "API-frozen." + * + *

It is generally safe for applications to depend on beta APIs, at + * the cost of some extra work during upgrades. However it is generally + * inadvisable for libraries (which get included on users' CLASSPATHs, + * outside the library developers' control) to do so. + * + **/ +@Retention(RetentionPolicy.CLASS) +@Target({ + ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR, + ElementType.FIELD, + ElementType.METHOD, + ElementType.PACKAGE, + ElementType.TYPE }) +@Documented +@Beta(Reason.CLIENT) +public @interface Beta { + /** + * @return The reason an API element is marked with {@link Beta}. + */ + Reason[] value(); +} diff --git a/bson/src/main/org/bson/annotations/Reason.java b/bson/src/main/org/bson/annotations/Reason.java new file mode 100644 index 00000000000..d0b11c79651 --- /dev/null +++ b/bson/src/main/org/bson/annotations/Reason.java @@ -0,0 +1,34 @@ +/* + * 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.annotations; + +/** + * Enumerates the reasons an API element might be marked with annotations like {@link Beta}. + */ +@Beta(Reason.CLIENT) +public enum Reason { + /** + * Indicates that the status of the driver API is the reason for the annotation. + */ + CLIENT, + + /** + * The driver API relies on the server API. + * This dependency is the reason for the annotation and suggests that changes in the server API could impact the driver API. + */ + SERVER +} diff --git a/bson/src/main/org/bson/annotations/package-info.java b/bson/src/main/org/bson/annotations/package-info.java new file mode 100644 index 00000000000..ac5cd9dabf9 --- /dev/null +++ b/bson/src/main/org/bson/annotations/package-info.java @@ -0,0 +1,20 @@ +/* + * 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. + */ + +/** + * Contains annotations that can apply to any part of the BSON library code. + */ +package org.bson.annotations; diff --git a/bson/src/main/org/bson/codecs/VectorCodec.java b/bson/src/main/org/bson/codecs/BinaryVectorCodec.java similarity index 74% rename from bson/src/main/org/bson/codecs/VectorCodec.java rename to bson/src/main/org/bson/codecs/BinaryVectorCodec.java index 87d847664dc..4d23557ad49 100644 --- a/bson/src/main/org/bson/codecs/VectorCodec.java +++ b/bson/src/main/org/bson/codecs/BinaryVectorCodec.java @@ -21,21 +21,21 @@ import org.bson.BsonInvalidOperationException; import org.bson.BsonReader; import org.bson.BsonWriter; -import org.bson.Vector; +import org.bson.BinaryVector; /** - * Encodes and decodes {@link Vector} objects. + * Encodes and decodes {@link BinaryVector} objects. * */ - final class VectorCodec implements Codec { + final class BinaryVectorCodec implements Codec { @Override - public void encode(final BsonWriter writer, final Vector vectorToEncode, final EncoderContext encoderContext) { + public void encode(final BsonWriter writer, final BinaryVector vectorToEncode, final EncoderContext encoderContext) { writer.writeBinaryData(new BsonBinary(vectorToEncode)); } @Override - public Vector decode(final BsonReader reader, final DecoderContext decoderContext) { + public BinaryVector decode(final BsonReader reader, final DecoderContext decoderContext) { byte subType = reader.peekBinarySubType(); if (subType != BsonBinarySubType.VECTOR.getValue()) { @@ -48,8 +48,8 @@ public Vector decode(final BsonReader reader, final DecoderContext decoderContex } @Override - public Class getEncoderClass() { - return Vector.class; + public Class getEncoderClass() { + return BinaryVector.class; } } diff --git a/bson/src/main/org/bson/codecs/BsonArrayCodec.java b/bson/src/main/org/bson/codecs/BsonArrayCodec.java index 2efe3147d8a..9b4bef5e4c5 100644 --- a/bson/src/main/org/bson/codecs/BsonArrayCodec.java +++ b/bson/src/main/org/bson/codecs/BsonArrayCodec.java @@ -23,9 +23,6 @@ import org.bson.BsonWriter; import org.bson.codecs.configuration.CodecRegistry; -import java.util.ArrayList; -import java.util.List; - import static org.bson.assertions.Assertions.notNull; import static org.bson.codecs.configuration.CodecRegistries.fromProviders; @@ -60,16 +57,13 @@ public BsonArrayCodec(final CodecRegistry codecRegistry) { @Override public BsonArray decode(final BsonReader reader, final DecoderContext decoderContext) { + BsonArray bsonArray = new BsonArray(); reader.readStartArray(); - - List list = new ArrayList<>(); while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) { - list.add(readValue(reader, decoderContext)); + bsonArray.add(readValue(reader, decoderContext)); } - reader.readEndArray(); - - return new BsonArray(list); + return bsonArray; } @Override diff --git a/bson/src/main/org/bson/codecs/ContainerCodecHelper.java b/bson/src/main/org/bson/codecs/ContainerCodecHelper.java index b454206d5e8..2243f209528 100644 --- a/bson/src/main/org/bson/codecs/ContainerCodecHelper.java +++ b/bson/src/main/org/bson/codecs/ContainerCodecHelper.java @@ -21,7 +21,7 @@ import org.bson.BsonType; import org.bson.Transformer; import org.bson.UuidRepresentation; -import org.bson.Vector; +import org.bson.BinaryVector; import org.bson.codecs.configuration.CodecConfigurationException; import org.bson.codecs.configuration.CodecRegistry; @@ -68,7 +68,7 @@ private static Codec getBinarySubTypeCodec(final BsonReader reader, final Codec binaryTypeCodec) { if (binarySubType == BsonBinarySubType.VECTOR.getValue()) { - Codec vectorCodec = registry.get(Vector.class, registry); + Codec vectorCodec = registry.get(BinaryVector.class, registry); if (vectorCodec != null) { return vectorCodec; } diff --git a/bson/src/main/org/bson/codecs/Float32VectorCodec.java b/bson/src/main/org/bson/codecs/Float32BinaryVectorCodec.java similarity index 72% rename from bson/src/main/org/bson/codecs/Float32VectorCodec.java rename to bson/src/main/org/bson/codecs/Float32BinaryVectorCodec.java index a6df27e3f87..99f740a6873 100644 --- a/bson/src/main/org/bson/codecs/Float32VectorCodec.java +++ b/bson/src/main/org/bson/codecs/Float32BinaryVectorCodec.java @@ -21,21 +21,21 @@ import org.bson.BsonInvalidOperationException; import org.bson.BsonReader; import org.bson.BsonWriter; -import org.bson.Float32Vector; +import org.bson.Float32BinaryVector; /** - * Encodes and decodes {@link Float32Vector} objects. + * Encodes and decodes {@link Float32BinaryVector} objects. * */ -final class Float32VectorCodec implements Codec { +final class Float32BinaryVectorCodec implements Codec { @Override - public void encode(final BsonWriter writer, final Float32Vector vectorToEncode, final EncoderContext encoderContext) { + public void encode(final BsonWriter writer, final Float32BinaryVector vectorToEncode, final EncoderContext encoderContext) { writer.writeBinaryData(new BsonBinary(vectorToEncode)); } @Override - public Float32Vector decode(final BsonReader reader, final DecoderContext decoderContext) { + public Float32BinaryVector decode(final BsonReader reader, final DecoderContext decoderContext) { byte subType = reader.peekBinarySubType(); if (subType != BsonBinarySubType.VECTOR.getValue()) { @@ -49,8 +49,8 @@ public Float32Vector decode(final BsonReader reader, final DecoderContext decode } @Override - public Class getEncoderClass() { - return Float32Vector.class; + public Class getEncoderClass() { + return Float32BinaryVector.class; } } diff --git a/bson/src/main/org/bson/codecs/Int8VectorCodec.java b/bson/src/main/org/bson/codecs/Int8VectorCodec.java index a9a70f53746..963da625d7f 100644 --- a/bson/src/main/org/bson/codecs/Int8VectorCodec.java +++ b/bson/src/main/org/bson/codecs/Int8VectorCodec.java @@ -21,22 +21,22 @@ import org.bson.BsonInvalidOperationException; import org.bson.BsonReader; import org.bson.BsonWriter; -import org.bson.Int8Vector; +import org.bson.Int8BinaryVector; /** - * Encodes and decodes {@link Int8Vector} objects. + * Encodes and decodes {@link Int8BinaryVector} objects. * * @since 5.3 */ -final class Int8VectorCodec implements Codec { +final class Int8VectorCodec implements Codec { @Override - public void encode(final BsonWriter writer, final Int8Vector vectorToEncode, final EncoderContext encoderContext) { + public void encode(final BsonWriter writer, final Int8BinaryVector vectorToEncode, final EncoderContext encoderContext) { writer.writeBinaryData(new BsonBinary(vectorToEncode)); } @Override - public Int8Vector decode(final BsonReader reader, final DecoderContext decoderContext) { + public Int8BinaryVector decode(final BsonReader reader, final DecoderContext decoderContext) { byte subType = reader.peekBinarySubType(); if (subType != BsonBinarySubType.VECTOR.getValue()) { @@ -51,8 +51,8 @@ public Int8Vector decode(final BsonReader reader, final DecoderContext decoderCo @Override - public Class getEncoderClass() { - return Int8Vector.class; + public Class getEncoderClass() { + return Int8BinaryVector.class; } } diff --git a/bson/src/main/org/bson/codecs/PackedBitVectorCodec.java b/bson/src/main/org/bson/codecs/PackedBitBinaryVectorCodec.java similarity index 72% rename from bson/src/main/org/bson/codecs/PackedBitVectorCodec.java rename to bson/src/main/org/bson/codecs/PackedBitBinaryVectorCodec.java index 6fcb9552955..c8d0410a4c6 100644 --- a/bson/src/main/org/bson/codecs/PackedBitVectorCodec.java +++ b/bson/src/main/org/bson/codecs/PackedBitBinaryVectorCodec.java @@ -21,21 +21,21 @@ import org.bson.BsonInvalidOperationException; import org.bson.BsonReader; import org.bson.BsonWriter; -import org.bson.PackedBitVector; +import org.bson.PackedBitBinaryVector; /** - * Encodes and decodes {@link PackedBitVector} objects. + * Encodes and decodes {@link PackedBitBinaryVector} objects. * */ -final class PackedBitVectorCodec implements Codec { +final class PackedBitBinaryVectorCodec implements Codec { @Override - public void encode(final BsonWriter writer, final PackedBitVector vectorToEncode, final EncoderContext encoderContext) { + public void encode(final BsonWriter writer, final PackedBitBinaryVector vectorToEncode, final EncoderContext encoderContext) { writer.writeBinaryData(new BsonBinary(vectorToEncode)); } @Override - public PackedBitVector decode(final BsonReader reader, final DecoderContext decoderContext) { + public PackedBitBinaryVector decode(final BsonReader reader, final DecoderContext decoderContext) { byte subType = reader.peekBinarySubType(); if (subType != BsonBinarySubType.VECTOR.getValue()) { @@ -51,8 +51,8 @@ public PackedBitVector decode(final BsonReader reader, final DecoderContext deco @Override - public Class getEncoderClass() { - return PackedBitVector.class; + public Class getEncoderClass() { + return PackedBitBinaryVector.class; } } diff --git a/bson/src/main/org/bson/codecs/ValueCodecProvider.java b/bson/src/main/org/bson/codecs/ValueCodecProvider.java index 3a921c1b08a..5c21e048529 100644 --- a/bson/src/main/org/bson/codecs/ValueCodecProvider.java +++ b/bson/src/main/org/bson/codecs/ValueCodecProvider.java @@ -42,10 +42,10 @@ *

  • {@link org.bson.codecs.StringCodec}
  • *
  • {@link org.bson.codecs.SymbolCodec}
  • *
  • {@link org.bson.codecs.UuidCodec}
  • - *
  • {@link VectorCodec}
  • - *
  • {@link Float32VectorCodec}
  • + *
  • {@link BinaryVectorCodec}
  • + *
  • {@link Float32BinaryVectorCodec}
  • *
  • {@link Int8VectorCodec}
  • - *
  • {@link PackedBitVectorCodec}
  • + *
  • {@link PackedBitBinaryVectorCodec}
  • *
  • {@link org.bson.codecs.ByteCodec}
  • *
  • {@link org.bson.codecs.ShortCodec}
  • *
  • {@link org.bson.codecs.ByteArrayCodec}
  • @@ -90,10 +90,10 @@ private void addCodecs() { addCodec(new StringCodec()); addCodec(new SymbolCodec()); addCodec(new OverridableUuidRepresentationUuidCodec()); - addCodec(new VectorCodec()); - addCodec(new Float32VectorCodec()); + addCodec(new BinaryVectorCodec()); + addCodec(new Float32BinaryVectorCodec()); addCodec(new Int8VectorCodec()); - addCodec(new PackedBitVectorCodec()); + addCodec(new PackedBitBinaryVectorCodec()); addCodec(new ByteCodec()); addCodec(new PatternCodec()); diff --git a/bson/src/main/org/bson/internal/vector/VectorHelper.java b/bson/src/main/org/bson/internal/vector/BinaryVectorHelper.java similarity index 81% rename from bson/src/main/org/bson/internal/vector/VectorHelper.java rename to bson/src/main/org/bson/internal/vector/BinaryVectorHelper.java index 9dbf583d2b0..74d50d334fc 100644 --- a/bson/src/main/org/bson/internal/vector/VectorHelper.java +++ b/bson/src/main/org/bson/internal/vector/BinaryVectorHelper.java @@ -18,10 +18,10 @@ import org.bson.BsonBinary; import org.bson.BsonInvalidOperationException; -import org.bson.Float32Vector; -import org.bson.Int8Vector; -import org.bson.PackedBitVector; -import org.bson.Vector; +import org.bson.Float32BinaryVector; +import org.bson.Int8BinaryVector; +import org.bson.PackedBitBinaryVector; +import org.bson.BinaryVector; import org.bson.assertions.Assertions; import org.bson.types.Binary; @@ -35,29 +35,29 @@ *

    * This class is not part of the public API and may be removed or changed at any time. * - * @see Vector + * @see BinaryVector * @see BsonBinary#asVector() - * @see BsonBinary#BsonBinary(Vector) + * @see BsonBinary#BsonBinary(BinaryVector) */ -public final class VectorHelper { +public final class BinaryVectorHelper { private static final ByteOrder STORED_BYTE_ORDER = ByteOrder.LITTLE_ENDIAN; private static final String ERROR_MESSAGE_UNKNOWN_VECTOR_DATA_TYPE = "Unknown vector data type: "; private static final byte ZERO_PADDING = 0; - private VectorHelper() { + private BinaryVectorHelper() { //NOP } private static final int METADATA_SIZE = 2; - public static byte[] encodeVectorToBinary(final Vector vector) { - Vector.DataType dataType = vector.getDataType(); + public static byte[] encodeVectorToBinary(final BinaryVector vector) { + BinaryVector.DataType dataType = vector.getDataType(); switch (dataType) { case INT8: return encodeVector(dataType.getValue(), ZERO_PADDING, vector.asInt8Vector().getData()); case PACKED_BIT: - PackedBitVector packedBitVector = vector.asPackedBitVector(); + PackedBitBinaryVector packedBitVector = vector.asPackedBitVector(); return encodeVector(dataType.getValue(), packedBitVector.getPadding(), packedBitVector.getData()); case FLOAT32: return encodeVector(dataType.getValue(), vector.asFloat32Vector().getData()); @@ -69,11 +69,11 @@ public static byte[] encodeVectorToBinary(final Vector vector) { /** * Decodes a vector from a binary representation. *

    - * encodedVector is not mutated nor stored in the returned {@link Vector}. + * encodedVector is not mutated nor stored in the returned {@link BinaryVector}. */ - public static Vector decodeBinaryToVector(final byte[] encodedVector) { + public static BinaryVector decodeBinaryToVector(final byte[] encodedVector) { isTrue("Vector encoded array length must be at least 2, but found: " + encodedVector.length, encodedVector.length >= METADATA_SIZE); - Vector.DataType dataType = determineVectorDType(encodedVector[0]); + BinaryVector.DataType dataType = determineVectorDType(encodedVector[0]); byte padding = encodedVector[1]; switch (dataType) { case INT8: @@ -87,22 +87,22 @@ public static Vector decodeBinaryToVector(final byte[] encodedVector) { } } - private static Float32Vector decodeFloat32Vector(final byte[] encodedVector, final byte padding) { + private static Float32BinaryVector decodeFloat32Vector(final byte[] encodedVector, final byte padding) { isTrue("Padding must be 0 for FLOAT32 data type, but found: " + padding, padding == 0); - return Vector.floatVector(decodeLittleEndianFloats(encodedVector)); + return BinaryVector.floatVector(decodeLittleEndianFloats(encodedVector)); } - private static PackedBitVector decodePackedBitVector(final byte[] encodedVector, final byte padding) { + private static PackedBitBinaryVector decodePackedBitVector(final byte[] encodedVector, final byte padding) { byte[] packedBitVector = extractVectorData(encodedVector); isTrue("Padding must be 0 if vector is empty, but found: " + padding, padding == 0 || packedBitVector.length > 0); isTrue("Padding must be between 0 and 7 bits, but found: " + padding, padding >= 0 && padding <= 7); - return Vector.packedBitVector(packedBitVector, padding); + return BinaryVector.packedBitVector(packedBitVector, padding); } - private static Int8Vector decodeInt8Vector(final byte[] encodedVector, final byte padding) { + private static Int8BinaryVector decodeInt8Vector(final byte[] encodedVector, final byte padding) { isTrue("Padding must be 0 for INT8 data type, but found: " + padding, padding == 0); byte[] int8Vector = extractVectorData(encodedVector); - return Vector.int8Vector(int8Vector); + return BinaryVector.int8Vector(int8Vector); } private static byte[] extractVectorData(final byte[] encodedVector) { @@ -159,9 +159,9 @@ private static float[] decodeLittleEndianFloats(final byte[] encodedVector) { return floatArray; } - public static Vector.DataType determineVectorDType(final byte dType) { - Vector.DataType[] values = Vector.DataType.values(); - for (Vector.DataType value : values) { + public static BinaryVector.DataType determineVectorDType(final byte dType) { + BinaryVector.DataType[] values = BinaryVector.DataType.values(); + for (BinaryVector.DataType value : values) { if (value.getValue() == dType) { return value; } diff --git a/bson/src/main/org/bson/io/OutputBuffer.java b/bson/src/main/org/bson/io/OutputBuffer.java index 8793acad9a2..00f88cea706 100644 --- a/bson/src/main/org/bson/io/OutputBuffer.java +++ b/bson/src/main/org/bson/io/OutputBuffer.java @@ -41,6 +41,16 @@ public void write(final byte[] b) { public void close() { } + /** + * {@inheritDoc} + *

    + * The {@link #flush()} method of {@link OutputBuffer} does nothing.

    + */ + @Override + public void flush() throws IOException { + super.flush(); + } + @Override public void write(final byte[] bytes, final int offset, final int length) { writeBytes(bytes, offset, length); diff --git a/bson/src/main/org/bson/types/ObjectId.java b/bson/src/main/org/bson/types/ObjectId.java index 7c1b1d29540..927d3ab0c31 100644 --- a/bson/src/main/org/bson/types/ObjectId.java +++ b/bson/src/main/org/bson/types/ObjectId.java @@ -16,17 +16,18 @@ package org.bson.types; +import static org.bson.assertions.Assertions.isTrueArgument; +import static org.bson.assertions.Assertions.notNull; + import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.Serializable; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.security.SecureRandom; import java.util.Date; import java.util.concurrent.atomic.AtomicInteger; -import static org.bson.assertions.Assertions.isTrueArgument; -import static org.bson.assertions.Assertions.notNull; - /** *

    A globally unique identifier for objects.

    * @@ -53,9 +54,8 @@ public final class ObjectId implements Comparable, Serializable { private static final int OBJECT_ID_LENGTH = 12; private static final int LOW_ORDER_THREE_BYTES = 0x00ffffff; - // Use primitives to represent the 5-byte random value. - private static final int RANDOM_VALUE1; - private static final short RANDOM_VALUE2; + // Use upper bytes of a long to represent the 5-byte random value. + private static final long RANDOM_VALUE; private static final AtomicInteger NEXT_COUNTER; @@ -67,18 +67,12 @@ public final class ObjectId implements Comparable, Serializable { * The timestamp */ private final int timestamp; + /** - * The counter. - */ - private final int counter; - /** - * the first four bits of randomness. - */ - private final int randomValue1; - /** - * The last two bits of randomness. + * The final 8 bytes of the ObjectID are 5 bytes probabilistically unique to the machine and + * process, followed by a 3 byte incrementing counter initialized to a random value. */ - private final short randomValue2; + private final long nonce; /** * Gets a new object id. @@ -101,7 +95,7 @@ public static ObjectId get() { * @since 4.1 */ public static ObjectId getSmallestWithDate(final Date date) { - return new ObjectId(dateToTimestampSeconds(date), 0, (short) 0, 0, false); + return new ObjectId(dateToTimestampSeconds(date), 0L); } /** @@ -152,7 +146,7 @@ public ObjectId() { * @param date the date */ public ObjectId(final Date date) { - this(dateToTimestampSeconds(date), NEXT_COUNTER.getAndIncrement() & LOW_ORDER_THREE_BYTES, false); + this(dateToTimestampSeconds(date), RANDOM_VALUE | (NEXT_COUNTER.getAndIncrement() & LOW_ORDER_THREE_BYTES)); } /** @@ -163,7 +157,7 @@ public ObjectId(final Date date) { * @throws IllegalArgumentException if the high order byte of counter is not zero */ public ObjectId(final Date date, final int counter) { - this(dateToTimestampSeconds(date), counter, true); + this(dateToTimestampSeconds(date), getNonceFromUntrustedCounter(counter)); } /** @@ -174,25 +168,19 @@ public ObjectId(final Date date, final int counter) { * @throws IllegalArgumentException if the high order byte of counter is not zero */ public ObjectId(final int timestamp, final int counter) { - this(timestamp, counter, true); + this(timestamp, getNonceFromUntrustedCounter(counter)); } - private ObjectId(final int timestamp, final int counter, final boolean checkCounter) { - this(timestamp, RANDOM_VALUE1, RANDOM_VALUE2, counter, checkCounter); + private ObjectId(final int timestamp, final long nonce) { + this.timestamp = timestamp; + this.nonce = nonce; } - private ObjectId(final int timestamp, final int randomValue1, final short randomValue2, final int counter, - final boolean checkCounter) { - if ((randomValue1 & 0xff000000) != 0) { - throw new IllegalArgumentException("The random value must be between 0 and 16777215 (it must fit in three bytes)."); - } - if (checkCounter && ((counter & 0xff000000) != 0)) { + private static long getNonceFromUntrustedCounter(final int counter) { + if ((counter & 0xff000000) != 0) { throw new IllegalArgumentException("The counter must be between 0 and 16777215 (it must fit in three bytes)."); } - this.timestamp = timestamp; - this.counter = counter & LOW_ORDER_THREE_BYTES; - this.randomValue1 = randomValue1; - this.randomValue2 = randomValue2; + return RANDOM_VALUE | counter; } /** @@ -226,12 +214,14 @@ public ObjectId(final ByteBuffer buffer) { notNull("buffer", buffer); isTrueArgument("buffer.remaining() >=12", buffer.remaining() >= OBJECT_ID_LENGTH); - // Note: Cannot use ByteBuffer.getInt because it depends on tbe buffer's byte order - // and ObjectId's are always in big-endian order. - timestamp = makeInt(buffer.get(), buffer.get(), buffer.get(), buffer.get()); - randomValue1 = makeInt((byte) 0, buffer.get(), buffer.get(), buffer.get()); - randomValue2 = makeShort(buffer.get(), buffer.get()); - counter = makeInt((byte) 0, buffer.get(), buffer.get(), buffer.get()); + ByteOrder originalOrder = buffer.order(); + try { + buffer.order(ByteOrder.BIG_ENDIAN); + this.timestamp = buffer.getInt(); + this.nonce = buffer.getLong(); + } finally { + buffer.order(originalOrder); + } } /** @@ -240,9 +230,11 @@ public ObjectId(final ByteBuffer buffer) { * @return the byte array */ public byte[] toByteArray() { - ByteBuffer buffer = ByteBuffer.allocate(OBJECT_ID_LENGTH); - putToByteBuffer(buffer); - return buffer.array(); // using .allocate ensures there is a backing array that can be returned + // using .allocate ensures there is a backing array that can be returned + return ByteBuffer.allocate(OBJECT_ID_LENGTH) + .putInt(this.timestamp) + .putLong(this.nonce) + .array(); } /** @@ -257,18 +249,14 @@ public void putToByteBuffer(final ByteBuffer buffer) { notNull("buffer", buffer); isTrueArgument("buffer.remaining() >=12", buffer.remaining() >= OBJECT_ID_LENGTH); - buffer.put(int3(timestamp)); - buffer.put(int2(timestamp)); - buffer.put(int1(timestamp)); - buffer.put(int0(timestamp)); - buffer.put(int2(randomValue1)); - buffer.put(int1(randomValue1)); - buffer.put(int0(randomValue1)); - buffer.put(short1(randomValue2)); - buffer.put(short0(randomValue2)); - buffer.put(int2(counter)); - buffer.put(int1(counter)); - buffer.put(int0(counter)); + ByteOrder originalOrder = buffer.order(); + try { + buffer.order(ByteOrder.BIG_ENDIAN); + buffer.putInt(this.timestamp); + buffer.putLong(this.nonce); + } finally { + buffer.order(originalOrder); + } } /** @@ -313,49 +301,26 @@ public boolean equals(final Object o) { return false; } - ObjectId objectId = (ObjectId) o; - - if (counter != objectId.counter) { - return false; - } - if (timestamp != objectId.timestamp) { - return false; - } - - if (randomValue1 != objectId.randomValue1) { + ObjectId other = (ObjectId) o; + if (timestamp != other.timestamp) { return false; } - - if (randomValue2 != objectId.randomValue2) { - return false; - } - - return true; + return nonce == other.nonce; } @Override public int hashCode() { - int result = timestamp; - result = 31 * result + counter; - result = 31 * result + randomValue1; - result = 31 * result + randomValue2; - return result; + return 31 * timestamp + Long.hashCode(nonce); } @Override public int compareTo(final ObjectId other) { - if (other == null) { - throw new NullPointerException(); + int cmp = Integer.compareUnsigned(this.timestamp, other.timestamp); + if (cmp != 0) { + return cmp; } - byte[] byteArray = toByteArray(); - byte[] otherByteArray = other.toByteArray(); - for (int i = 0; i < OBJECT_ID_LENGTH; i++) { - if (byteArray[i] != otherByteArray[i]) { - return ((byteArray[i] & 0xff) < (otherByteArray[i] & 0xff)) ? -1 : 1; - } - } - return 0; + return Long.compareUnsigned(nonce, other.nonce); } @Override @@ -407,8 +372,7 @@ private Object readResolve() { static { try { SecureRandom secureRandom = new SecureRandom(); - RANDOM_VALUE1 = secureRandom.nextInt(0x01000000); - RANDOM_VALUE2 = (short) secureRandom.nextInt(0x00008000); + RANDOM_VALUE = secureRandom.nextLong() & ~LOW_ORDER_THREE_BYTES; NEXT_COUNTER = new AtomicInteger(secureRandom.nextInt()); } catch (Exception e) { throw new RuntimeException(e); @@ -443,46 +407,4 @@ private static int hexCharToInt(final char c) { private static int dateToTimestampSeconds(final Date time) { return (int) (time.getTime() / 1000); } - - // Big-Endian helpers, in this class because all other BSON numbers are little-endian - - private static int makeInt(final byte b3, final byte b2, final byte b1, final byte b0) { - // CHECKSTYLE:OFF - return (((b3) << 24) | - ((b2 & 0xff) << 16) | - ((b1 & 0xff) << 8) | - ((b0 & 0xff))); - // CHECKSTYLE:ON - } - - private static short makeShort(final byte b1, final byte b0) { - // CHECKSTYLE:OFF - return (short) (((b1 & 0xff) << 8) | ((b0 & 0xff))); - // CHECKSTYLE:ON - } - - private static byte int3(final int x) { - return (byte) (x >> 24); - } - - private static byte int2(final int x) { - return (byte) (x >> 16); - } - - private static byte int1(final int x) { - return (byte) (x >> 8); - } - - private static byte int0(final int x) { - return (byte) (x); - } - - private static byte short1(final short x) { - return (byte) (x >> 8); - } - - private static byte short0(final short x) { - return (byte) (x); - } - } diff --git a/bson/src/test/resources/bson/binary.json b/bson/src/test/resources/bson/binary.json index 29d88471afe..0e0056f3a2c 100644 --- a/bson/src/test/resources/bson/binary.json +++ b/bson/src/test/resources/bson/binary.json @@ -1,153 +1,153 @@ { - "description": "Binary type", - "bson_type": "0x05", - "test_key": "x", - "valid": [ - { - "description": "subtype 0x00 (Zero-length)", - "canonical_bson": "0D000000057800000000000000", - "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}" - }, - { - "description": "subtype 0x00 (Zero-length, keys reversed)", - "canonical_bson": "0D000000057800000000000000", - "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}", - "degenerate_extjson": "{\"x\" : { \"$binary\" : {\"subType\" : \"00\", \"base64\" : \"\"}}}" - }, - { - "description": "subtype 0x00", - "canonical_bson": "0F0000000578000200000000FFFF00", - "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"00\"}}}" - }, - { - "description": "subtype 0x01", - "canonical_bson": "0F0000000578000200000001FFFF00", - "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"01\"}}}" - }, - { - "description": "subtype 0x02", - "canonical_bson": "13000000057800060000000202000000FFFF00", - "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"02\"}}}" - }, - { - "description": "subtype 0x03", - "canonical_bson": "1D000000057800100000000373FFD26444B34C6990E8E7D1DFC035D400", - "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"03\"}}}" - }, - { - "description": "subtype 0x04", - "canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400", - "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}" - }, - { - "description": "subtype 0x04 UUID", - "canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400", - "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}", - "degenerate_extjson": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}" - }, - { - "description": "subtype 0x05", - "canonical_bson": "1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400", - "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"05\"}}}" - }, - { - "description": "subtype 0x07", - "canonical_bson": "1D000000057800100000000773FFD26444B34C6990E8E7D1DFC035D400", - "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"07\"}}}" - }, - { - "description": "subtype 0x08", - "canonical_bson": "1D000000057800100000000873FFD26444B34C6990E8E7D1DFC035D400", - "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"08\"}}}" - }, - { - "description": "subtype 0x80", - "canonical_bson": "0F0000000578000200000080FFFF00", - "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"80\"}}}" - }, - { - "description": "$type query operator (conflicts with legacy $binary form with $type field)", - "canonical_bson": "1F000000037800170000000224747970650007000000737472696E67000000", - "canonical_extjson": "{\"x\" : { \"$type\" : \"string\"}}" - }, - { - "description": "$type query operator (conflicts with legacy $binary form with $type field)", - "canonical_bson": "180000000378001000000010247479706500020000000000", - "canonical_extjson": "{\"x\" : { \"$type\" : {\"$numberInt\": \"2\"}}}" - }, - { - "description": "subtype 0x09 Vector FLOAT32", - "canonical_bson": "170000000578000A0000000927000000FE420000E04000", - "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"JwAAAP5CAADgQA==\", \"subType\": \"09\"}}}" - }, - { - "description": "subtype 0x09 Vector INT8", - "canonical_bson": "11000000057800040000000903007F0700", - "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"AwB/Bw==\", \"subType\": \"09\"}}}" - }, - { - "description": "subtype 0x09 Vector PACKED_BIT", - "canonical_bson": "11000000057800040000000910007F0700", - "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"EAB/Bw==\", \"subType\": \"09\"}}}" - }, - { - "description": "subtype 0x09 Vector (Zero-length) FLOAT32", - "canonical_bson": "0F0000000578000200000009270000", - "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"JwA=\", \"subType\": \"09\"}}}" - }, - { - "description": "subtype 0x09 Vector (Zero-length) INT8", - "canonical_bson": "0F0000000578000200000009030000", - "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"AwA=\", \"subType\": \"09\"}}}" - }, - { - "description": "subtype 0x09 Vector (Zero-length) PACKED_BIT", - "canonical_bson": "0F0000000578000200000009100000", - "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"EAA=\", \"subType\": \"09\"}}}" - } - ], - "decodeErrors": [ - { - "description": "Length longer than document", - "bson": "1D000000057800FF0000000573FFD26444B34C6990E8E7D1DFC035D400" - }, - { - "description": "Negative length", - "bson": "0D000000057800FFFFFFFF0000" - }, - { - "description": "subtype 0x02 length too long ", - "bson": "13000000057800060000000203000000FFFF00" - }, - { - "description": "subtype 0x02 length too short", - "bson": "13000000057800060000000201000000FFFF00" - }, - { - "description": "subtype 0x02 length negative one", - "bson": "130000000578000600000002FFFFFFFFFFFF00" - } - ], - "parseErrors": [ - { - "description": "$uuid wrong type", - "string": "{\"x\" : { \"$uuid\" : { \"data\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}}" - }, - { - "description": "$uuid invalid value--too short", - "string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-90e8-e7d1dfc035d4\"}}" - }, - { - "description": "$uuid invalid value--too long", - "string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4-789e4\"}}" - }, - { - "description": "$uuid invalid value--misplaced hyphens", - "string": "{\"x\" : { \"$uuid\" : \"73ff-d26444b-34c6-990e8e-7d1dfc035d4\"}}" - }, - { - "description": "$uuid invalid value--too many hyphens", - "string": "{\"x\" : { \"$uuid\" : \"----d264-44b3-4--9-90e8-e7d1dfc0----\"}}" - } - ] -} \ No newline at end of file + "description": "Binary type", + "bson_type": "0x05", + "test_key": "x", + "valid": [ + { + "description": "subtype 0x00 (Zero-length)", + "canonical_bson": "0D000000057800000000000000", + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}" + }, + { + "description": "subtype 0x00 (Zero-length, keys reversed)", + "canonical_bson": "0D000000057800000000000000", + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"\", \"subType\" : \"00\"}}}", + "degenerate_extjson": "{\"x\" : { \"$binary\" : {\"subType\" : \"00\", \"base64\" : \"\"}}}" + }, + { + "description": "subtype 0x00", + "canonical_bson": "0F0000000578000200000000FFFF00", + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"00\"}}}" + }, + { + "description": "subtype 0x01", + "canonical_bson": "0F0000000578000200000001FFFF00", + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"01\"}}}" + }, + { + "description": "subtype 0x02", + "canonical_bson": "13000000057800060000000202000000FFFF00", + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"02\"}}}" + }, + { + "description": "subtype 0x03", + "canonical_bson": "1D000000057800100000000373FFD26444B34C6990E8E7D1DFC035D400", + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"03\"}}}" + }, + { + "description": "subtype 0x04", + "canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400", + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}" + }, + { + "description": "subtype 0x04 UUID", + "canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400", + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}", + "degenerate_extjson": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}" + }, + { + "description": "subtype 0x05", + "canonical_bson": "1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400", + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"05\"}}}" + }, + { + "description": "subtype 0x07", + "canonical_bson": "1D000000057800100000000773FFD26444B34C6990E8E7D1DFC035D400", + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"07\"}}}" + }, + { + "description": "subtype 0x08", + "canonical_bson": "1D000000057800100000000873FFD26444B34C6990E8E7D1DFC035D400", + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"08\"}}}" + }, + { + "description": "subtype 0x80", + "canonical_bson": "0F0000000578000200000080FFFF00", + "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"//8=\", \"subType\" : \"80\"}}}" + }, + { + "description": "$type query operator (conflicts with legacy $binary form with $type field)", + "canonical_bson": "1F000000037800170000000224747970650007000000737472696E67000000", + "canonical_extjson": "{\"x\" : { \"$type\" : \"string\"}}" + }, + { + "description": "$type query operator (conflicts with legacy $binary form with $type field)", + "canonical_bson": "180000000378001000000010247479706500020000000000", + "canonical_extjson": "{\"x\" : { \"$type\" : {\"$numberInt\": \"2\"}}}" + }, + { + "description": "subtype 0x09 Vector FLOAT32", + "canonical_bson": "170000000578000A0000000927000000FE420000E04000", + "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"JwAAAP5CAADgQA==\", \"subType\": \"09\"}}}" + }, + { + "description": "subtype 0x09 Vector INT8", + "canonical_bson": "11000000057800040000000903007F0700", + "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"AwB/Bw==\", \"subType\": \"09\"}}}" + }, + { + "description": "subtype 0x09 Vector PACKED_BIT", + "canonical_bson": "11000000057800040000000910007F0700", + "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"EAB/Bw==\", \"subType\": \"09\"}}}" + }, + { + "description": "subtype 0x09 Vector (Zero-length) FLOAT32", + "canonical_bson": "0F0000000578000200000009270000", + "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"JwA=\", \"subType\": \"09\"}}}" + }, + { + "description": "subtype 0x09 Vector (Zero-length) INT8", + "canonical_bson": "0F0000000578000200000009030000", + "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"AwA=\", \"subType\": \"09\"}}}" + }, + { + "description": "subtype 0x09 Vector (Zero-length) PACKED_BIT", + "canonical_bson": "0F0000000578000200000009100000", + "canonical_extjson": "{\"x\": {\"$binary\": {\"base64\": \"EAA=\", \"subType\": \"09\"}}}" + } + ], + "decodeErrors": [ + { + "description": "Length longer than document", + "bson": "1D000000057800FF0000000573FFD26444B34C6990E8E7D1DFC035D400" + }, + { + "description": "Negative length", + "bson": "0D000000057800FFFFFFFF0000" + }, + { + "description": "subtype 0x02 length too long ", + "bson": "13000000057800060000000203000000FFFF00" + }, + { + "description": "subtype 0x02 length too short", + "bson": "13000000057800060000000201000000FFFF00" + }, + { + "description": "subtype 0x02 length negative one", + "bson": "130000000578000600000002FFFFFFFFFFFF00" + } + ], + "parseErrors": [ + { + "description": "$uuid wrong type", + "string": "{\"x\" : { \"$uuid\" : { \"data\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}}" + }, + { + "description": "$uuid invalid value--too short", + "string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-90e8-e7d1dfc035d4\"}}" + }, + { + "description": "$uuid invalid value--too long", + "string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4-789e4\"}}" + }, + { + "description": "$uuid invalid value--misplaced hyphens", + "string": "{\"x\" : { \"$uuid\" : \"73ff-d26444b-34c6-990e8e-7d1dfc035d4\"}}" + }, + { + "description": "$uuid invalid value--too many hyphens", + "string": "{\"x\" : { \"$uuid\" : \"----d264-44b3-4--9-90e8-e7d1dfc0----\"}}" + } + ] +} diff --git a/bson/src/test/resources/bson/datetime.json b/bson/src/test/resources/bson/datetime.json index 60506ce1749..f857afdc367 100644 --- a/bson/src/test/resources/bson/datetime.json +++ b/bson/src/test/resources/bson/datetime.json @@ -25,6 +25,12 @@ "description" : "Y10K", "canonical_bson" : "1000000009610000DC1FD277E6000000", "canonical_extjson" : "{\"a\":{\"$date\":{\"$numberLong\":\"253402300800000\"}}}" + }, + { + "description": "leading zero ms", + "canonical_bson": "10000000096100D1D6D6CC3B01000000", + "relaxed_extjson": "{\"a\" : {\"$date\" : \"2012-12-24T12:15:30.001Z\"}}", + "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330001\"}}}" } ], "decodeErrors": [ diff --git a/bson/src/test/resources/bson/dbref.json b/bson/src/test/resources/bson/dbref.json index 1fe12c6f68d..41c0b09d0ea 100644 --- a/bson/src/test/resources/bson/dbref.json +++ b/bson/src/test/resources/bson/dbref.json @@ -1,5 +1,5 @@ { - "description": "DBRef", + "description": "Document type (DBRef sub-documents)", "bson_type": "0x03", "valid": [ { @@ -26,6 +26,26 @@ "description": "Document with key names similar to those of a DBRef", "canonical_bson": "3e0000000224726566000c0000006e6f742d612d646272656600072469640058921b3e6e32ab156a22b59e022462616e616e6100050000007065656c0000", "canonical_extjson": "{\"$ref\": \"not-a-dbref\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$banana\": \"peel\"}" + }, + { + "description": "DBRef with additional dollar-prefixed and dotted fields", + "canonical_bson": "48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e10612e62000100000010246300010000000000", + "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"a.b\": {\"$numberInt\": \"1\"}, \"$c\": {\"$numberInt\": \"1\"}}}" + }, + { + "description": "Sub-document resembles DBRef but $id is missing", + "canonical_bson": "26000000036462726566001a0000000224726566000b000000636f6c6c656374696f6e000000", + "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\"}}" + }, + { + "description": "Sub-document resembles DBRef but $ref is not a string", + "canonical_bson": "2c000000036462726566002000000010247265660001000000072469640058921b3e6e32ab156a22b59e0000", + "canonical_extjson": "{\"dbref\": {\"$ref\": {\"$numberInt\": \"1\"}, \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}}}" + }, + { + "description": "Sub-document resembles DBRef but $db is not a string", + "canonical_bson": "4000000003646272656600340000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e1024646200010000000000", + "canonical_extjson": "{\"dbref\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"58921b3e6e32ab156a22b59e\"}, \"$db\": {\"$numberInt\": \"1\"}}}" } ] } diff --git a/bson/src/test/resources/bson/decimal128-1.json b/bson/src/test/resources/bson/decimal128-1.json index 7eefec6bf79..8e7fbc93c6f 100644 --- a/bson/src/test/resources/bson/decimal128-1.json +++ b/bson/src/test/resources/bson/decimal128-1.json @@ -312,6 +312,30 @@ "canonical_bson": "18000000136400000000000a5bc138938d44c64d31cc3700", "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"}}", "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"1.000000000000000000000000000000000E+999\"}}" + }, + { + "description": "Clamped zeros with a large positive exponent", + "canonical_bson": "180000001364000000000000000000000000000000FE5F00", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+2147483647\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E+6111\"}}" + }, + { + "description": "Clamped zeros with a large negative exponent", + "canonical_bson": "180000001364000000000000000000000000000000000000", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-2147483647\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"0E-6176\"}}" + }, + { + "description": "Clamped negative zeros with a large positive exponent", + "canonical_bson": "180000001364000000000000000000000000000000FEDF00", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+2147483647\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E+6111\"}}" + }, + { + "description": "Clamped negative zeros with a large negative exponent", + "canonical_bson": "180000001364000000000000000000000000000000008000", + "degenerate_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-2147483647\"}}", + "canonical_extjson": "{\"d\" : {\"$numberDecimal\" : \"-0E-6176\"}}" } ] } diff --git a/bson/src/test/resources/bson/multi-type-deprecated.json b/bson/src/test/resources/bson/multi-type-deprecated.json index 5aac1bd2e7d..665f388cd41 100644 --- a/bson/src/test/resources/bson/multi-type-deprecated.json +++ b/bson/src/test/resources/bson/multi-type-deprecated.json @@ -5,10 +5,10 @@ "valid": [ { "description": "All BSON types", - "canonical_bson": "3B020000075F69640057E193D7A9CC81B4027498B50E53796D626F6C000700000073796D626F6C0002537472696E670007000000737472696E670010496E743332002A00000012496E743634002A0000000000000001446F75626C6500000000000000F0BF0542696E617279001000000003A34C38F7C3ABEDC8A37814A992AB8DB60542696E61727955736572446566696E656400050000008001020304050D436F6465000E00000066756E6374696F6E2829207B7D000F436F64655769746853636F7065001B0000000E00000066756E6374696F6E2829207B7D00050000000003537562646F63756D656E74001200000002666F6F0004000000626172000004417272617900280000001030000100000010310002000000103200030000001033000400000010340005000000001154696D657374616D7000010000002A0000000B5265676578007061747465726E0000094461746574696D6545706F6368000000000000000000094461746574696D65506F73697469766500FFFFFF7F00000000094461746574696D654E656761746976650000000080FFFFFFFF085472756500010846616C736500000C4442506F696E746572000E00000064622E636F6C6C656374696F6E0057E193D7A9CC81B4027498B1034442526566003D0000000224726566000B000000636F6C6C656374696F6E00072469640057FD71E96E32AB4225B723FB02246462000900000064617461626173650000FF4D696E6B6579007F4D61786B6579000A4E756C6C0006556E646566696E65640000", - "converted_bson": "4b020000075f69640057e193d7a9cc81b4027498b50253796d626f6c000700000073796d626f6c0002537472696e670007000000737472696e670010496e743332002a00000012496e743634002a0000000000000001446f75626c6500000000000000f0bf0542696e617279001000000003a34c38f7c3abedc8a37814a992ab8db60542696e61727955736572446566696e656400050000008001020304050d436f6465000e00000066756e6374696f6e2829207b7d000f436f64655769746853636f7065001b0000000e00000066756e6374696f6e2829207b7d00050000000003537562646f63756d656e74001200000002666f6f0004000000626172000004417272617900280000001030000100000010310002000000103200030000001033000400000010340005000000001154696d657374616d7000010000002a0000000b5265676578007061747465726e0000094461746574696d6545706f6368000000000000000000094461746574696d65506f73697469766500ffffff7f00000000094461746574696d654e656761746976650000000080ffffffff085472756500010846616c73650000034442506f696e746572002e0000000224726566000e00000064622e636f6c6c656374696f6e00072469640057e193d7a9cc81b4027498b100034442526566003d0000000224726566000b000000636f6c6c656374696f6e00072469640057fd71e96e32ab4225b723fb02246462000900000064617461626173650000ff4d696e6b6579007f4d61786b6579000a4e756c6c000a556e646566696e65640000", - "canonical_extjson": "{\"_id\": {\"$oid\": \"57e193d7a9cc81b4027498b5\"}, \"Symbol\": {\"$symbol\": \"symbol\"}, \"String\": \"string\", \"Int32\": {\"$numberInt\": \"42\"}, \"Int64\": {\"$numberLong\": \"42\"}, \"Double\": {\"$numberDouble\": \"-1.0\"}, \"Binary\": { \"$binary\" : {\"base64\": \"o0w498Or7cijeBSpkquNtg==\", \"subType\": \"03\"}}, \"BinaryUserDefined\": { \"$binary\" : {\"base64\": \"AQIDBAU=\", \"subType\": \"80\"}}, \"Code\": {\"$code\": \"function() {}\"}, \"CodeWithScope\": {\"$code\": \"function() {}\", \"$scope\": {}}, \"Subdocument\": {\"foo\": \"bar\"}, \"Array\": [{\"$numberInt\": \"1\"}, {\"$numberInt\": \"2\"}, {\"$numberInt\": \"3\"}, {\"$numberInt\": \"4\"}, {\"$numberInt\": \"5\"}], \"Timestamp\": {\"$timestamp\": {\"t\": 42, \"i\": 1}}, \"Regex\": {\"$regularExpression\": {\"pattern\": \"pattern\", \"options\": \"\"}}, \"DatetimeEpoch\": {\"$date\": {\"$numberLong\": \"0\"}}, \"DatetimePositive\": {\"$date\": {\"$numberLong\": \"2147483647\"}}, \"DatetimeNegative\": {\"$date\": {\"$numberLong\": \"-2147483648\"}}, \"True\": true, \"False\": false, \"DBPointer\": {\"$dbPointer\": {\"$ref\": \"db.collection\", \"$id\": {\"$oid\": \"57e193d7a9cc81b4027498b1\"}}}, \"DBRef\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"57fd71e96e32ab4225b723fb\"}, \"$db\": \"database\"}, \"Minkey\": {\"$minKey\": 1}, \"Maxkey\": {\"$maxKey\": 1}, \"Null\": null, \"Undefined\": {\"$undefined\": true}}", - "converted_extjson": "{\"_id\": {\"$oid\": \"57e193d7a9cc81b4027498b5\"}, \"Symbol\": \"symbol\", \"String\": \"string\", \"Int32\": {\"$numberInt\": \"42\"}, \"Int64\": {\"$numberLong\": \"42\"}, \"Double\": {\"$numberDouble\": \"-1.0\"}, \"Binary\": { \"$binary\" : {\"base64\": \"o0w498Or7cijeBSpkquNtg==\", \"subType\": \"03\"}}, \"BinaryUserDefined\": { \"$binary\" : {\"base64\": \"AQIDBAU=\", \"subType\": \"80\"}}, \"Code\": {\"$code\": \"function() {}\"}, \"CodeWithScope\": {\"$code\": \"function() {}\", \"$scope\": {}}, \"Subdocument\": {\"foo\": \"bar\"}, \"Array\": [{\"$numberInt\": \"1\"}, {\"$numberInt\": \"2\"}, {\"$numberInt\": \"3\"}, {\"$numberInt\": \"4\"}, {\"$numberInt\": \"5\"}], \"Timestamp\": {\"$timestamp\": {\"t\": 42, \"i\": 1}}, \"Regex\": {\"$regularExpression\": {\"pattern\": \"pattern\", \"options\": \"\"}}, \"DatetimeEpoch\": {\"$date\": {\"$numberLong\": \"0\"}}, \"DatetimePositive\": {\"$date\": {\"$numberLong\": \"2147483647\"}}, \"DatetimeNegative\": {\"$date\": {\"$numberLong\": \"-2147483648\"}}, \"True\": true, \"False\": false, \"DBPointer\": {\"$ref\": \"db.collection\", \"$id\": {\"$oid\": \"57e193d7a9cc81b4027498b1\"}}, \"DBRef\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"57fd71e96e32ab4225b723fb\"}, \"$db\": \"database\"}, \"Minkey\": {\"$minKey\": 1}, \"Maxkey\": {\"$maxKey\": 1}, \"Null\": null, \"Undefined\": null}" + "canonical_bson": "38020000075F69640057E193D7A9CC81B4027498B50E53796D626F6C000700000073796D626F6C0002537472696E670007000000737472696E670010496E743332002A00000012496E743634002A0000000000000001446F75626C6500000000000000F0BF0542696E617279001000000003A34C38F7C3ABEDC8A37814A992AB8DB60542696E61727955736572446566696E656400050000008001020304050D436F6465000E00000066756E6374696F6E2829207B7D000F436F64655769746853636F7065001B0000000E00000066756E6374696F6E2829207B7D00050000000003537562646F63756D656E74001200000002666F6F0004000000626172000004417272617900280000001030000100000010310002000000103200030000001033000400000010340005000000001154696D657374616D7000010000002A0000000B5265676578007061747465726E0000094461746574696D6545706F6368000000000000000000094461746574696D65506F73697469766500FFFFFF7F00000000094461746574696D654E656761746976650000000080FFFFFFFF085472756500010846616C736500000C4442506F696E746572000B000000636F6C6C656374696F6E0057E193D7A9CC81B4027498B1034442526566003D0000000224726566000B000000636F6C6C656374696F6E00072469640057FD71E96E32AB4225B723FB02246462000900000064617461626173650000FF4D696E6B6579007F4D61786B6579000A4E756C6C0006556E646566696E65640000", + "converted_bson": "48020000075f69640057e193d7a9cc81b4027498b50253796d626f6c000700000073796d626f6c0002537472696e670007000000737472696e670010496e743332002a00000012496e743634002a0000000000000001446f75626c6500000000000000f0bf0542696e617279001000000003a34c38f7c3abedc8a37814a992ab8db60542696e61727955736572446566696e656400050000008001020304050d436f6465000e00000066756e6374696f6e2829207b7d000f436f64655769746853636f7065001b0000000e00000066756e6374696f6e2829207b7d00050000000003537562646f63756d656e74001200000002666f6f0004000000626172000004417272617900280000001030000100000010310002000000103200030000001033000400000010340005000000001154696d657374616d7000010000002a0000000b5265676578007061747465726e0000094461746574696d6545706f6368000000000000000000094461746574696d65506f73697469766500ffffff7f00000000094461746574696d654e656761746976650000000080ffffffff085472756500010846616c73650000034442506f696e746572002b0000000224726566000b000000636f6c6c656374696f6e00072469640057e193d7a9cc81b4027498b100034442526566003d0000000224726566000b000000636f6c6c656374696f6e00072469640057fd71e96e32ab4225b723fb02246462000900000064617461626173650000ff4d696e6b6579007f4d61786b6579000a4e756c6c000a556e646566696e65640000", + "canonical_extjson": "{\"_id\": {\"$oid\": \"57e193d7a9cc81b4027498b5\"}, \"Symbol\": {\"$symbol\": \"symbol\"}, \"String\": \"string\", \"Int32\": {\"$numberInt\": \"42\"}, \"Int64\": {\"$numberLong\": \"42\"}, \"Double\": {\"$numberDouble\": \"-1.0\"}, \"Binary\": { \"$binary\" : {\"base64\": \"o0w498Or7cijeBSpkquNtg==\", \"subType\": \"03\"}}, \"BinaryUserDefined\": { \"$binary\" : {\"base64\": \"AQIDBAU=\", \"subType\": \"80\"}}, \"Code\": {\"$code\": \"function() {}\"}, \"CodeWithScope\": {\"$code\": \"function() {}\", \"$scope\": {}}, \"Subdocument\": {\"foo\": \"bar\"}, \"Array\": [{\"$numberInt\": \"1\"}, {\"$numberInt\": \"2\"}, {\"$numberInt\": \"3\"}, {\"$numberInt\": \"4\"}, {\"$numberInt\": \"5\"}], \"Timestamp\": {\"$timestamp\": {\"t\": 42, \"i\": 1}}, \"Regex\": {\"$regularExpression\": {\"pattern\": \"pattern\", \"options\": \"\"}}, \"DatetimeEpoch\": {\"$date\": {\"$numberLong\": \"0\"}}, \"DatetimePositive\": {\"$date\": {\"$numberLong\": \"2147483647\"}}, \"DatetimeNegative\": {\"$date\": {\"$numberLong\": \"-2147483648\"}}, \"True\": true, \"False\": false, \"DBPointer\": {\"$dbPointer\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"57e193d7a9cc81b4027498b1\"}}}, \"DBRef\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"57fd71e96e32ab4225b723fb\"}, \"$db\": \"database\"}, \"Minkey\": {\"$minKey\": 1}, \"Maxkey\": {\"$maxKey\": 1}, \"Null\": null, \"Undefined\": {\"$undefined\": true}}", + "converted_extjson": "{\"_id\": {\"$oid\": \"57e193d7a9cc81b4027498b5\"}, \"Symbol\": \"symbol\", \"String\": \"string\", \"Int32\": {\"$numberInt\": \"42\"}, \"Int64\": {\"$numberLong\": \"42\"}, \"Double\": {\"$numberDouble\": \"-1.0\"}, \"Binary\": { \"$binary\" : {\"base64\": \"o0w498Or7cijeBSpkquNtg==\", \"subType\": \"03\"}}, \"BinaryUserDefined\": { \"$binary\" : {\"base64\": \"AQIDBAU=\", \"subType\": \"80\"}}, \"Code\": {\"$code\": \"function() {}\"}, \"CodeWithScope\": {\"$code\": \"function() {}\", \"$scope\": {}}, \"Subdocument\": {\"foo\": \"bar\"}, \"Array\": [{\"$numberInt\": \"1\"}, {\"$numberInt\": \"2\"}, {\"$numberInt\": \"3\"}, {\"$numberInt\": \"4\"}, {\"$numberInt\": \"5\"}], \"Timestamp\": {\"$timestamp\": {\"t\": 42, \"i\": 1}}, \"Regex\": {\"$regularExpression\": {\"pattern\": \"pattern\", \"options\": \"\"}}, \"DatetimeEpoch\": {\"$date\": {\"$numberLong\": \"0\"}}, \"DatetimePositive\": {\"$date\": {\"$numberLong\": \"2147483647\"}}, \"DatetimeNegative\": {\"$date\": {\"$numberLong\": \"-2147483648\"}}, \"True\": true, \"False\": false, \"DBPointer\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"57e193d7a9cc81b4027498b1\"}}, \"DBRef\": {\"$ref\": \"collection\", \"$id\": {\"$oid\": \"57fd71e96e32ab4225b723fb\"}, \"$db\": \"database\"}, \"Minkey\": {\"$minKey\": 1}, \"Maxkey\": {\"$maxKey\": 1}, \"Null\": null, \"Undefined\": null}" } ] } diff --git a/bson/src/test/resources/bson/regex.json b/bson/src/test/resources/bson/regex.json index cd64bcad4f5..223802169df 100644 --- a/bson/src/test/resources/bson/regex.json +++ b/bson/src/test/resources/bson/regex.json @@ -54,11 +54,11 @@ ], "decodeErrors": [ { - "description": "Null byte in pattern", + "description": "Null byte in pattern string", "bson": "0F0000000B610061006300696D0000" }, { - "description": "Null byte in flags", + "description": "Null byte in flags string", "bson": "100000000B61006162630069006D0000" } ] diff --git a/bson/src/test/resources/bson/timestamp.json b/bson/src/test/resources/bson/timestamp.json index aacac5ea4f1..6f46564a327 100644 --- a/bson/src/test/resources/bson/timestamp.json +++ b/bson/src/test/resources/bson/timestamp.json @@ -21,7 +21,7 @@ }, { "description": "Timestamp with high-order bit set on both seconds and increment (not UINT32_MAX)", - "canonical_bson": "1000000011610000286BEE00286BEE00", + "canonical_bson": "1000000011610000286BEE00286BEE00", "canonical_extjson": "{\"a\" : {\"$timestamp\" : {\"t\" : 4000000000, \"i\" : 4000000000} } }" } ], diff --git a/bson/src/test/resources/bson/top.json b/bson/src/test/resources/bson/top.json index 4faf92dde43..9c649b5e3f0 100644 --- a/bson/src/test/resources/bson/top.json +++ b/bson/src/test/resources/bson/top.json @@ -84,7 +84,6 @@ "description": "Null byte in document key", "bson": "0D000000107800000100000000" } - ], "parseErrors": [ { @@ -248,12 +247,12 @@ "string": "{\"a\": {\"$dbPointer\": {\"a\": {\"$numberInt\": \"1\"}, \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}, \"c\": {\"$numberInt\": \"2\"}, \"$ref\": \"b\"}}}" }, { - "description": "Null byte in document key", - "string": "{\"a\\u0000\": 1 }" + "description" : "Null byte in document key", + "string" : "{\"a\\u0000\": 1 }" }, { - "description": "Null byte in sub-document key", - "string": "{\"a\" : {\"b\\u0000\": 1 }}" + "description" : "Null byte in sub-document key", + "string" : "{\"a\" : {\"b\\u0000\": 1 }}" }, { "description": "Null byte in $regularExpression pattern", diff --git a/bson/src/test/unit/org/bson/VectorTest.java b/bson/src/test/unit/org/bson/BinaryVectorTest.java similarity index 82% rename from bson/src/test/unit/org/bson/VectorTest.java rename to bson/src/test/unit/org/bson/BinaryVectorTest.java index 36cc7156db6..57e8b294019 100644 --- a/bson/src/test/unit/org/bson/VectorTest.java +++ b/bson/src/test/unit/org/bson/BinaryVectorTest.java @@ -25,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -class VectorTest { +class BinaryVectorTest { @Test void shouldCreateInt8Vector() { @@ -33,11 +33,11 @@ void shouldCreateInt8Vector() { byte[] data = {1, 2, 3, 4, 5}; // when - Int8Vector vector = Vector.int8Vector(data); + Int8BinaryVector vector = BinaryVector.int8Vector(data); // then assertNotNull(vector); - assertEquals(Vector.DataType.INT8, vector.getDataType()); + assertEquals(BinaryVector.DataType.INT8, vector.getDataType()); assertArrayEquals(data, vector.getData()); } @@ -47,7 +47,7 @@ void shouldThrowExceptionWhenCreatingInt8VectorWithNullData() { byte[] data = null; // when & Then - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> Vector.int8Vector(data)); + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> BinaryVector.int8Vector(data)); assertEquals("data can not be null", exception.getMessage()); } @@ -57,11 +57,11 @@ void shouldCreateFloat32Vector() { float[] data = {1.0f, 2.0f, 3.0f}; // when - Float32Vector vector = Vector.floatVector(data); + Float32BinaryVector vector = BinaryVector.floatVector(data); // then assertNotNull(vector); - assertEquals(Vector.DataType.FLOAT32, vector.getDataType()); + assertEquals(BinaryVector.DataType.FLOAT32, vector.getDataType()); assertArrayEquals(data, vector.getData()); } @@ -71,7 +71,7 @@ void shouldThrowExceptionWhenCreatingFloat32VectorWithNullData() { float[] data = null; // when & Then - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> Vector.floatVector(data)); + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> BinaryVector.floatVector(data)); assertEquals("data can not be null", exception.getMessage()); } @@ -83,11 +83,11 @@ void shouldCreatePackedBitVector(final byte validPadding) { byte[] data = {(byte) 0b10101010, (byte) 0b01010101}; // when - PackedBitVector vector = Vector.packedBitVector(data, validPadding); + PackedBitBinaryVector vector = BinaryVector.packedBitVector(data, validPadding); // then assertNotNull(vector); - assertEquals(Vector.DataType.PACKED_BIT, vector.getDataType()); + assertEquals(BinaryVector.DataType.PACKED_BIT, vector.getDataType()); assertArrayEquals(data, vector.getData()); assertEquals(validPadding, vector.getPadding()); } @@ -100,7 +100,7 @@ void shouldThrowExceptionWhenPackedBitVectorHasInvalidPadding(final byte invalid // when & Then IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> - Vector.packedBitVector(data, invalidPadding)); + BinaryVector.packedBitVector(data, invalidPadding)); assertEquals("state should be: Padding must be between 0 and 7 bits. Provided padding: " + invalidPadding, exception.getMessage()); } @@ -112,7 +112,7 @@ void shouldThrowExceptionWhenPackedBitVectorIsCreatedWithNullData() { // when & Then IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> - Vector.packedBitVector(data, padding)); + BinaryVector.packedBitVector(data, padding)); assertEquals("data can not be null", exception.getMessage()); } @@ -123,11 +123,11 @@ void shouldCreatePackedBitVectorWithZeroPaddingAndEmptyData() { byte padding = 0; // when - PackedBitVector vector = Vector.packedBitVector(data, padding); + PackedBitBinaryVector vector = BinaryVector.packedBitVector(data, padding); // then assertNotNull(vector); - assertEquals(Vector.DataType.PACKED_BIT, vector.getDataType()); + assertEquals(BinaryVector.DataType.PACKED_BIT, vector.getDataType()); assertArrayEquals(data, vector.getData()); assertEquals(padding, vector.getPadding()); } @@ -140,7 +140,7 @@ void shouldThrowExceptionWhenPackedBitVectorWithNonZeroPaddingAndEmptyData() { // when & Then IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> - Vector.packedBitVector(data, padding)); + BinaryVector.packedBitVector(data, padding)); assertEquals("state should be: Padding must be 0 if vector is empty. Provided padding: " + padding, exception.getMessage()); } @@ -148,7 +148,7 @@ void shouldThrowExceptionWhenPackedBitVectorWithNonZeroPaddingAndEmptyData() { void shouldThrowExceptionWhenRetrievingInt8DataFromNonInt8Vector() { // given float[] data = {1.0f, 2.0f}; - Vector vector = Vector.floatVector(data); + BinaryVector vector = BinaryVector.floatVector(data); // when & Then IllegalStateException exception = assertThrows(IllegalStateException.class, vector::asInt8Vector); @@ -159,7 +159,7 @@ void shouldThrowExceptionWhenRetrievingInt8DataFromNonInt8Vector() { void shouldThrowExceptionWhenRetrievingFloat32DataFromNonFloat32Vector() { // given byte[] data = {1, 2, 3}; - Vector vector = Vector.int8Vector(data); + BinaryVector vector = BinaryVector.int8Vector(data); // when & Then IllegalStateException exception = assertThrows(IllegalStateException.class, vector::asFloat32Vector); @@ -170,7 +170,7 @@ void shouldThrowExceptionWhenRetrievingFloat32DataFromNonFloat32Vector() { void shouldThrowExceptionWhenRetrievingPackedBitDataFromNonPackedBitVector() { // given float[] data = {1.0f, 2.0f}; - Vector vector = Vector.floatVector(data); + BinaryVector vector = BinaryVector.floatVector(data); // when & Then IllegalStateException exception = assertThrows(IllegalStateException.class, vector::asPackedBitVector); diff --git a/bson/src/test/unit/org/bson/BsonBinaryTest.java b/bson/src/test/unit/org/bson/BsonBinaryTest.java index 029c611c594..b47bcbf8a79 100644 --- a/bson/src/test/unit/org/bson/BsonBinaryTest.java +++ b/bson/src/test/unit/org/bson/BsonBinaryTest.java @@ -32,15 +32,15 @@ class BsonBinaryTest { - private static final byte FLOAT32_DTYPE = Vector.DataType.FLOAT32.getValue(); - private static final byte INT8_DTYPE = Vector.DataType.INT8.getValue(); - private static final byte PACKED_BIT_DTYPE = Vector.DataType.PACKED_BIT.getValue(); + private static final byte FLOAT32_DTYPE = BinaryVector.DataType.FLOAT32.getValue(); + private static final byte INT8_DTYPE = BinaryVector.DataType.INT8.getValue(); + private static final byte PACKED_BIT_DTYPE = BinaryVector.DataType.PACKED_BIT.getValue(); public static final int ZERO_PADDING = 0; @Test void shouldThrowExceptionWhenCreatingBsonBinaryWithNullVector() { // given - Vector vector = null; + BinaryVector vector = null; // when & then IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new BsonBinary(vector)); @@ -61,7 +61,7 @@ void shouldThrowExceptionWhenBsonBinarySubTypeIsNotVector(final BsonBinarySubTyp @ParameterizedTest(name = "{index}: {0}") @MethodSource("provideFloatVectors") - void shouldEncodeFloatVector(final Vector actualFloat32Vector, final byte[] expectedBsonEncodedVector) { + void shouldEncodeFloatVector(final BinaryVector actualFloat32Vector, final byte[] expectedBsonEncodedVector) { // when BsonBinary actualBsonBinary = new BsonBinary(actualFloat32Vector); byte[] actualBsonEncodedVector = actualBsonBinary.getData(); @@ -73,9 +73,9 @@ void shouldEncodeFloatVector(final Vector actualFloat32Vector, final byte[] expe @ParameterizedTest(name = "{index}: {0}") @MethodSource("provideFloatVectors") - void shouldDecodeFloatVector(final Float32Vector expectedFloatVector, final byte[] bsonEncodedVector) { + void shouldDecodeFloatVector(final Float32BinaryVector expectedFloatVector, final byte[] bsonEncodedVector) { // when - Float32Vector decodedVector = (Float32Vector) new BsonBinary(BsonBinarySubType.VECTOR, bsonEncodedVector).asVector(); + Float32BinaryVector decodedVector = (Float32BinaryVector) new BsonBinary(BsonBinarySubType.VECTOR, bsonEncodedVector).asVector(); // then assertEquals(expectedFloatVector, decodedVector); @@ -84,7 +84,7 @@ void shouldDecodeFloatVector(final Float32Vector expectedFloatVector, final byte private static Stream provideFloatVectors() { return Stream.of( arguments( - Vector.floatVector(new float[]{1.1f, 2.2f, 3.3f, -1.0f, Float.MAX_VALUE, Float.MIN_VALUE, Float.POSITIVE_INFINITY, + BinaryVector.floatVector(new float[]{1.1f, 2.2f, 3.3f, -1.0f, Float.MAX_VALUE, Float.MIN_VALUE, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY}), new byte[]{FLOAT32_DTYPE, ZERO_PADDING, (byte) 205, (byte) 204, (byte) 140, (byte) 63, // 1.1f in little-endian @@ -98,13 +98,13 @@ private static Stream provideFloatVectors() { } ), arguments( - Vector.floatVector(new float[]{0.0f}), + BinaryVector.floatVector(new float[]{0.0f}), new byte[]{FLOAT32_DTYPE, ZERO_PADDING, (byte) 0, (byte) 0, (byte) 0, (byte) 0 // 0.0f in little-endian } ), arguments( - Vector.floatVector(new float[]{}), + BinaryVector.floatVector(new float[]{}), new byte[]{FLOAT32_DTYPE, ZERO_PADDING} ) ); @@ -112,7 +112,7 @@ private static Stream provideFloatVectors() { @ParameterizedTest(name = "{index}: {0}") @MethodSource("provideInt8Vectors") - void shouldEncodeInt8Vector(final Vector actualInt8Vector, final byte[] expectedBsonEncodedVector) { + void shouldEncodeInt8Vector(final BinaryVector actualInt8Vector, final byte[] expectedBsonEncodedVector) { // when BsonBinary actualBsonBinary = new BsonBinary(actualInt8Vector); byte[] actualBsonEncodedVector = actualBsonBinary.getData(); @@ -124,9 +124,9 @@ void shouldEncodeInt8Vector(final Vector actualInt8Vector, final byte[] expected @ParameterizedTest(name = "{index}: {0}") @MethodSource("provideInt8Vectors") - void shouldDecodeInt8Vector(final Int8Vector expectedInt8Vector, final byte[] bsonEncodedVector) { + void shouldDecodeInt8Vector(final Int8BinaryVector expectedInt8Vector, final byte[] bsonEncodedVector) { // when - Int8Vector decodedVector = (Int8Vector) new BsonBinary(BsonBinarySubType.VECTOR, bsonEncodedVector).asVector(); + Int8BinaryVector decodedVector = (Int8BinaryVector) new BsonBinary(BsonBinarySubType.VECTOR, bsonEncodedVector).asVector(); // then assertEquals(expectedInt8Vector, decodedVector); @@ -135,10 +135,10 @@ void shouldDecodeInt8Vector(final Int8Vector expectedInt8Vector, final byte[] bs private static Stream provideInt8Vectors() { return Stream.of( arguments( - Vector.int8Vector(new byte[]{Byte.MAX_VALUE, 1, 2, 3, 4, Byte.MIN_VALUE}), + BinaryVector.int8Vector(new byte[]{Byte.MAX_VALUE, 1, 2, 3, 4, Byte.MIN_VALUE}), new byte[]{INT8_DTYPE, ZERO_PADDING, Byte.MAX_VALUE, 1, 2, 3, 4, Byte.MIN_VALUE }), - arguments(Vector.int8Vector(new byte[]{}), + arguments(BinaryVector.int8Vector(new byte[]{}), new byte[]{INT8_DTYPE, ZERO_PADDING} ) ); @@ -146,7 +146,7 @@ private static Stream provideInt8Vectors() { @ParameterizedTest @MethodSource("providePackedBitVectors") - void shouldEncodePackedBitVector(final Vector actualPackedBitVector, final byte[] expectedBsonEncodedVector) { + void shouldEncodePackedBitVector(final BinaryVector actualPackedBitVector, final byte[] expectedBsonEncodedVector) { // when BsonBinary actualBsonBinary = new BsonBinary(actualPackedBitVector); byte[] actualBsonEncodedVector = actualBsonBinary.getData(); @@ -158,9 +158,9 @@ void shouldEncodePackedBitVector(final Vector actualPackedBitVector, final byte[ @ParameterizedTest @MethodSource("providePackedBitVectors") - void shouldDecodePackedBitVector(final PackedBitVector expectedPackedBitVector, final byte[] bsonEncodedVector) { + void shouldDecodePackedBitVector(final PackedBitBinaryVector expectedPackedBitVector, final byte[] bsonEncodedVector) { // when - PackedBitVector decodedVector = (PackedBitVector) new BsonBinary(BsonBinarySubType.VECTOR, bsonEncodedVector).asVector(); + PackedBitBinaryVector decodedVector = (PackedBitBinaryVector) new BsonBinary(BsonBinarySubType.VECTOR, bsonEncodedVector).asVector(); // then assertEquals(expectedPackedBitVector, decodedVector); @@ -169,11 +169,11 @@ void shouldDecodePackedBitVector(final PackedBitVector expectedPackedBitVector, private static Stream providePackedBitVectors() { return Stream.of( arguments( - Vector.packedBitVector(new byte[]{(byte) 0, (byte) 255, (byte) 10}, (byte) 2), + BinaryVector.packedBitVector(new byte[]{(byte) 0, (byte) 255, (byte) 10}, (byte) 2), new byte[]{PACKED_BIT_DTYPE, 2, (byte) 0, (byte) 255, (byte) 10} ), arguments( - Vector.packedBitVector(new byte[0], (byte) 0), + BinaryVector.packedBitVector(new byte[0], (byte) 0), new byte[]{PACKED_BIT_DTYPE, 0} )); } diff --git a/bson/src/test/unit/org/bson/BsonBinaryWriterTest.java b/bson/src/test/unit/org/bson/BsonBinaryWriterTest.java index c9e22fcce7a..8e0f7c23c28 100644 --- a/bson/src/test/unit/org/bson/BsonBinaryWriterTest.java +++ b/bson/src/test/unit/org/bson/BsonBinaryWriterTest.java @@ -40,7 +40,7 @@ public class BsonBinaryWriterTest { - private static final byte FLOAT32_DTYPE = Vector.DataType.FLOAT32.getValue(); + private static final byte FLOAT32_DTYPE = BinaryVector.DataType.FLOAT32.getValue(); private static final int ZERO_PADDING = 0; private BsonBinaryWriter writer; diff --git a/bson/src/test/unit/org/bson/codecs/VectorCodecTest.java b/bson/src/test/unit/org/bson/codecs/BinaryBinaryVectorCodecTest.java similarity index 73% rename from bson/src/test/unit/org/bson/codecs/VectorCodecTest.java rename to bson/src/test/unit/org/bson/codecs/BinaryBinaryVectorCodecTest.java index bf33af90cae..fadddb7a635 100644 --- a/bson/src/test/unit/org/bson/codecs/VectorCodecTest.java +++ b/bson/src/test/unit/org/bson/codecs/BinaryBinaryVectorCodecTest.java @@ -25,10 +25,10 @@ import org.bson.BsonType; import org.bson.BsonWriter; import org.bson.ByteBufNIO; -import org.bson.Float32Vector; -import org.bson.Int8Vector; -import org.bson.PackedBitVector; -import org.bson.Vector; +import org.bson.Float32BinaryVector; +import org.bson.Int8BinaryVector; +import org.bson.PackedBitBinaryVector; +import org.bson.BinaryVector; import org.bson.io.BasicOutputBuffer; import org.bson.io.ByteBufferBsonInput; import org.bson.io.OutputBuffer; @@ -50,22 +50,22 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.params.provider.Arguments.arguments; -class VectorCodecTest extends CodecTestCase { +class BinaryBinaryVectorCodecTest extends CodecTestCase { private static Stream provideVectorsAndCodecs() { return Stream.of( - arguments(Vector.floatVector(new float[]{1.1f, 2.2f, 3.3f}), new Float32VectorCodec(), Float32Vector.class), - arguments(Vector.int8Vector(new byte[]{10, 20, 30, 40}), new Int8VectorCodec(), Int8Vector.class), - arguments(Vector.packedBitVector(new byte[]{(byte) 0b10101010, (byte) 0b01010101}, (byte) 3), new PackedBitVectorCodec(), PackedBitVector.class), - arguments(Vector.packedBitVector(new byte[]{(byte) 0b10101010, (byte) 0b01010101}, (byte) 3), new VectorCodec(), Vector.class), - arguments(Vector.int8Vector(new byte[]{10, 20, 30, 40}), new VectorCodec(), Vector.class), - arguments(Vector.packedBitVector(new byte[]{(byte) 0b10101010, (byte) 0b01010101}, (byte) 3), new VectorCodec(), Vector.class) + arguments(BinaryVector.floatVector(new float[]{1.1f, 2.2f, 3.3f}), new Float32BinaryVectorCodec(), Float32BinaryVector.class), + arguments(BinaryVector.int8Vector(new byte[]{10, 20, 30, 40}), new Int8VectorCodec(), Int8BinaryVector.class), + arguments(BinaryVector.packedBitVector(new byte[]{(byte) 0b10101010, (byte) 0b01010101}, (byte) 3), new PackedBitBinaryVectorCodec(), PackedBitBinaryVector.class), + arguments(BinaryVector.packedBitVector(new byte[]{(byte) 0b10101010, (byte) 0b01010101}, (byte) 3), new BinaryVectorCodec(), BinaryVector.class), + arguments(BinaryVector.int8Vector(new byte[]{10, 20, 30, 40}), new BinaryVectorCodec(), BinaryVector.class), + arguments(BinaryVector.packedBitVector(new byte[]{(byte) 0b10101010, (byte) 0b01010101}, (byte) 3), new BinaryVectorCodec(), BinaryVector.class) ); } @ParameterizedTest @MethodSource("provideVectorsAndCodecs") - void shouldEncodeVector(final Vector vectorToEncode, final Codec vectorCodec) throws IOException { + void shouldEncodeVector(final BinaryVector vectorToEncode, final Codec vectorCodec) throws IOException { // given BsonBinary bsonBinary = new BsonBinary(vectorToEncode); byte[] encodedVector = bsonBinary.getData(); @@ -98,7 +98,7 @@ void shouldEncodeVector(final Vector vectorToEncode, final Codec vectorC @ParameterizedTest @MethodSource("provideVectorsAndCodecs") - void shouldDecodeVector(final Vector vectorToDecode, final Codec vectorCodec) { + void shouldDecodeVector(final BinaryVector vectorToDecode, final Codec vectorCodec) { // given OutputBuffer buffer = new BasicOutputBuffer(); BsonWriter writer = new BsonBinaryWriter(buffer); @@ -111,7 +111,7 @@ void shouldDecodeVector(final Vector vectorToDecode, final Codec vectorC reader.readStartDocument(); // when - Vector decodedVector = vectorCodec.decode(reader, DecoderContext.builder().build()); + BinaryVector decodedVector = vectorCodec.decode(reader, DecoderContext.builder().build()); // then assertDoesNotThrow(reader::readEndDocument); @@ -129,7 +129,7 @@ void shouldThrowExceptionForInvalidSubType(final BsonBinarySubType subType) { reader.readStartDocument(); // when & then - Stream.of(new Float32VectorCodec(), new Int8VectorCodec(), new PackedBitVectorCodec()) + Stream.of(new Float32BinaryVectorCodec(), new Int8VectorCodec(), new PackedBitBinaryVectorCodec()) .forEach(codec -> { BsonInvalidOperationException exception = assertThrows(BsonInvalidOperationException.class, () -> codec.decode(reader, DecoderContext.builder().build())); @@ -140,11 +140,11 @@ void shouldThrowExceptionForInvalidSubType(final BsonBinarySubType subType) { @ParameterizedTest @MethodSource("provideVectorsAndCodecs") - void shouldReturnCorrectEncoderClass(final Vector vector, - final Codec codec, - final Class expectedEncoderClass) { + void shouldReturnCorrectEncoderClass(final BinaryVector vector, + final Codec codec, + final Class expectedEncoderClass) { // when - Class encoderClass = codec.getEncoderClass(); + Class encoderClass = codec.getEncoderClass(); // then assertEquals(expectedEncoderClass, encoderClass); diff --git a/bson/src/test/unit/org/bson/codecs/DocumentCodecTest.java b/bson/src/test/unit/org/bson/codecs/DocumentCodecTest.java index 67c6b561aa5..7343707d5a7 100644 --- a/bson/src/test/unit/org/bson/codecs/DocumentCodecTest.java +++ b/bson/src/test/unit/org/bson/codecs/DocumentCodecTest.java @@ -23,7 +23,7 @@ import org.bson.BsonObjectId; import org.bson.ByteBufNIO; import org.bson.Document; -import org.bson.Vector; +import org.bson.BinaryVector; import org.bson.io.BasicOutputBuffer; import org.bson.io.BsonInput; import org.bson.io.ByteBufferBsonInput; @@ -81,9 +81,9 @@ public void testPrimitiveBSONTypeCodecs() throws IOException { doc.put("code", new Code("var i = 0")); doc.put("minkey", new MinKey()); doc.put("maxkey", new MaxKey()); - doc.put("vectorFloat", Vector.floatVector(new float[]{1.1f, 2.2f, 3.3f})); - doc.put("vectorInt8", Vector.int8Vector(new byte[]{10, 20, 30, 40})); - doc.put("vectorPackedBit", Vector.packedBitVector(new byte[]{(byte) 0b10101010, (byte) 0b01010101}, (byte) 3)); + doc.put("vectorFloat", BinaryVector.floatVector(new float[]{1.1f, 2.2f, 3.3f})); + doc.put("vectorInt8", BinaryVector.int8Vector(new byte[]{10, 20, 30, 40})); + doc.put("vectorPackedBit", BinaryVector.packedBitVector(new byte[]{(byte) 0b10101010, (byte) 0b01010101}, (byte) 3)); // doc.put("pattern", Pattern.compile("^hello")); // TODO: Pattern doesn't override equals method! doc.put("null", null); diff --git a/bson/src/test/unit/org/bson/codecs/ValueCodecProviderSpecification.groovy b/bson/src/test/unit/org/bson/codecs/ValueCodecProviderSpecification.groovy index 23c46fb7b0b..1fd738b5c5c 100644 --- a/bson/src/test/unit/org/bson/codecs/ValueCodecProviderSpecification.groovy +++ b/bson/src/test/unit/org/bson/codecs/ValueCodecProviderSpecification.groovy @@ -17,10 +17,10 @@ package org.bson.codecs import org.bson.Document -import org.bson.Float32Vector -import org.bson.Int8Vector -import org.bson.PackedBitVector -import org.bson.Vector +import org.bson.Float32BinaryVector +import org.bson.Int8BinaryVector +import org.bson.PackedBitBinaryVector +import org.bson.BinaryVector import org.bson.codecs.configuration.CodecRegistries import org.bson.types.Binary import org.bson.types.Code @@ -62,10 +62,10 @@ class ValueCodecProviderSpecification extends Specification { provider.get(Short, registry) instanceof ShortCodec provider.get(byte[], registry) instanceof ByteArrayCodec provider.get(Float, registry) instanceof FloatCodec - provider.get(Vector, registry) instanceof VectorCodec - provider.get(Float32Vector, registry) instanceof Float32VectorCodec - provider.get(Int8Vector, registry) instanceof Int8VectorCodec - provider.get(PackedBitVector, registry) instanceof PackedBitVectorCodec + provider.get(BinaryVector, registry) instanceof BinaryVectorCodec + provider.get(Float32BinaryVector, registry) instanceof Float32BinaryVectorCodec + provider.get(Int8BinaryVector, registry) instanceof Int8VectorCodec + provider.get(PackedBitBinaryVector, registry) instanceof PackedBitBinaryVectorCodec provider.get(Binary, registry) instanceof BinaryCodec provider.get(MinKey, registry) instanceof MinKeyCodec diff --git a/bson/src/test/unit/org/bson/types/ObjectIdTest.java b/bson/src/test/unit/org/bson/types/ObjectIdTest.java index 14c8241f55a..cfe04623b90 100644 --- a/bson/src/test/unit/org/bson/types/ObjectIdTest.java +++ b/bson/src/test/unit/org/bson/types/ObjectIdTest.java @@ -17,36 +17,72 @@ package org.bson.types; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.nio.Buffer; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Locale; import java.util.Random; +import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; public class ObjectIdTest { - @Test - public void testToBytes() { + + /** Calls the base method of ByteBuffer.position(int) since the override is not available in jdk8. */ + private static ByteBuffer setPosition(final ByteBuffer buf, final int pos) { + ((Buffer) buf).position(pos); + return buf; + } + + /** + * MethodSource for valid ByteBuffers that can hold an ObjectID + */ + public static List validOutputBuffers() { + List result = new ArrayList<>(); + result.add(ByteBuffer.allocate(12)); + result.add(ByteBuffer.allocate(12).order(ByteOrder.LITTLE_ENDIAN)); + result.add(ByteBuffer.allocate(24).put(new byte[12])); + result.add(ByteBuffer.allocateDirect(12)); + result.add(ByteBuffer.allocateDirect(12).order(ByteOrder.LITTLE_ENDIAN)); + return result; + } + + @MethodSource("validOutputBuffers") + @ParameterizedTest + public void testToBytes(final ByteBuffer output) { + int originalPosition = output.position(); + ByteOrder originalOrder = output.order(); byte[] expectedBytes = {81, 6, -4, -102, -68, -126, 55, 85, -127, 54, -46, -119}; + byte[] result = new byte[12]; ObjectId objectId = new ObjectId(expectedBytes); assertArrayEquals(expectedBytes, objectId.toByteArray()); - ByteBuffer buffer = ByteBuffer.allocate(12); - objectId.putToByteBuffer(buffer); - assertArrayEquals(expectedBytes, buffer.array()); + objectId.putToByteBuffer(output); + ((Buffer) output).position(output.position() - 12); + output.get(result); // read last 12 bytes leaving position intact + + assertArrayEquals(expectedBytes, result); + assertEquals(originalPosition + 12, output.position()); + assertEquals(originalOrder, output.order()); } @Test @@ -136,8 +172,64 @@ public void testTime() { } @Test - public void testDateCons() { + public void testDateConstructor() { assertEquals(new Date().getTime() / 1000, new ObjectId(new Date()).getDate().getTime() / 1000); + assertNotEquals(new ObjectId(new Date(1_000)), new ObjectId(new Date(1_000))); + assertEquals("00000001", new ObjectId(new Date(1_000)).toHexString().substring(0, 8)); + } + + @Test + public void testDateConstructorWithCounter() { + assertEquals(new ObjectId(new Date(1_000), 1), new ObjectId(new Date(1_000), 1)); + assertEquals("00000001", new ObjectId(new Date(1_000), 1).toHexString().substring(0, 8)); + assertThrows(NullPointerException.class, () -> new ObjectId(null, Integer.MAX_VALUE)); + assertThrows(IllegalArgumentException.class, () -> new ObjectId(new Date(1_000), Integer.MAX_VALUE)); + } + + @Test + public void testTimestampConstructor() { + assertEquals(1_000, new ObjectId(1_000, 1).getTimestamp()); + assertEquals(new ObjectId(1_000, 1), new ObjectId(1_000, 1)); + assertEquals("7fffffff", new ObjectId(Integer.MAX_VALUE, 1).toHexString().substring(0, 8)); + assertThrows(IllegalArgumentException.class, () -> new ObjectId(Integer.MAX_VALUE, Integer.MAX_VALUE)); + } + + /** + * MethodSource for valid ByteBuffers containing an ObjectID at the current position. + */ + public static List validInputBuffers() { + byte[] data = new byte[12]; + for (byte i = 0; i < data.length; ++i) { + data[i] = i; + } + + List result = new ArrayList<>(); + result.add(ByteBuffer.wrap(data)); + result.add(ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN)); + result.add(setPosition(ByteBuffer.allocateDirect(data.length).put(data), 0)); + result.add(setPosition(ByteBuffer.allocateDirect(data.length).put(data).order(ByteOrder.LITTLE_ENDIAN), 0)); + result.add(setPosition(ByteBuffer.allocate(2 * data.length).put(data), 0)); + result.add(setPosition(ByteBuffer.allocate(2 * data.length).put(new byte[12]).put(data), 12)); + return result; + } + + @ParameterizedTest + @MethodSource(value = "validInputBuffers") + public void testByteBufferConstructor(final ByteBuffer input) { + ByteOrder order = input.order(); + int position = input.position(); + + byte[] result = new ObjectId(input).toByteArray(); + + assertArrayEquals(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, result); + assertEquals(order, input.order()); + assertEquals(position + 12, input.position()); + } + + @Test + public void testInvalidByteBufferConstructor() { + assertThrows(IllegalArgumentException.class, () -> new ObjectId((ByteBuffer) null)); + assertThrows(IllegalArgumentException.class, () -> new ObjectId(ByteBuffer.allocate(11))); } @Test @@ -162,6 +254,23 @@ public void testCompareTo() { assertEquals(-1, first.compareTo(third)); assertEquals(1, second.compareTo(first)); assertEquals(1, third.compareTo(first)); + assertThrows(NullPointerException.class, () -> first.compareTo(null)); + } + + @Test + public void testEquals() { + Date dateOne = new Date(); + Date dateTwo = new Date(dateOne.getTime() + 10000); + ObjectId first = new ObjectId(dateOne, 0); + ObjectId second = new ObjectId(dateOne, 1); + ObjectId third = new ObjectId(dateTwo, 0); + ObjectId fourth = new ObjectId(first.toByteArray()); + assertEquals(first, first); + assertEquals(first, fourth); + assertNotEquals(first, second); + assertNotEquals(first, third); + assertNotEquals(second, third); + assertFalse(first.equals(null)); } @Test diff --git a/bson/src/test/unit/org/bson/vector/VectorGenericBsonTest.java b/bson/src/test/unit/org/bson/vector/BinaryVectorGenericBsonTest.java similarity index 87% rename from bson/src/test/unit/org/bson/vector/VectorGenericBsonTest.java rename to bson/src/test/unit/org/bson/vector/BinaryVectorGenericBsonTest.java index 64e84f6afc8..858174d7cd9 100644 --- a/bson/src/test/unit/org/bson/vector/VectorGenericBsonTest.java +++ b/bson/src/test/unit/org/bson/vector/BinaryVectorGenericBsonTest.java @@ -21,9 +21,9 @@ import org.bson.BsonDocument; import org.bson.BsonString; import org.bson.BsonValue; -import org.bson.Float32Vector; -import org.bson.PackedBitVector; -import org.bson.Vector; +import org.bson.Float32BinaryVector; +import org.bson.PackedBitBinaryVector; +import org.bson.BinaryVector; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -41,7 +41,7 @@ import static java.lang.String.format; import static org.bson.BsonHelper.decodeToDocument; import static org.bson.BsonHelper.encodeToHex; -import static org.bson.internal.vector.VectorHelper.determineVectorDType; +import static org.bson.internal.vector.BinaryVectorHelper.determineVectorDType; import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -51,7 +51,7 @@ * See * JSON-based tests that included in test resources. */ -class VectorGenericBsonTest { +class BinaryVectorGenericBsonTest { private static final List TEST_NAMES_TO_IGNORE = Arrays.asList( //NO API to set padding for floats available. @@ -91,22 +91,22 @@ private static void runInvalidTestCase(final BsonDocument testCase) { BsonArray arrayVector = testCase.getArray("vector"); byte expectedPadding = (byte) testCase.getInt32("padding").getValue(); byte dtypeByte = Byte.decode(testCase.getString("dtype_hex").getValue()); - Vector.DataType expectedDType = determineVectorDType(dtypeByte); + BinaryVector.DataType expectedDType = determineVectorDType(dtypeByte); switch (expectedDType) { case INT8: byte[] expectedVectorData = toByteArray(arrayVector); assertValidationException(assertThrows(RuntimeException.class, - () -> Vector.int8Vector(expectedVectorData))); + () -> BinaryVector.int8Vector(expectedVectorData))); break; case PACKED_BIT: byte[] expectedVectorPackedBitData = toByteArray(arrayVector); assertValidationException(assertThrows(RuntimeException.class, - () -> Vector.packedBitVector(expectedVectorPackedBitData, expectedPadding))); + () -> BinaryVector.packedBitVector(expectedVectorPackedBitData, expectedPadding))); break; case FLOAT32: float[] expectedFloatVector = toFloatArray(arrayVector); - assertValidationException(assertThrows(RuntimeException.class, () -> Vector.floatVector(expectedFloatVector))); + assertValidationException(assertThrows(RuntimeException.class, () -> BinaryVector.floatVector(expectedFloatVector))); break; default: throw new IllegalArgumentException("Unsupported vector data type: " + expectedDType); @@ -118,12 +118,12 @@ private static void runValidTestCase(final String testKey, final BsonDocument te byte dtypeByte = Byte.decode(testCase.getString("dtype_hex").getValue()); byte expectedPadding = (byte) testCase.getInt32("padding").getValue(); - Vector.DataType expectedDType = determineVectorDType(dtypeByte); + BinaryVector.DataType expectedDType = determineVectorDType(dtypeByte); String expectedCanonicalBsonHex = testCase.getString("canonical_bson").getValue().toUpperCase(); BsonArray arrayVector = testCase.getArray("vector"); BsonDocument actualDecodedDocument = decodeToDocument(expectedCanonicalBsonHex, description); - Vector actualVector = actualDecodedDocument.getBinary("vector").asVector(); + BinaryVector actualVector = actualDecodedDocument.getBinary("vector").asVector(); switch (expectedDType) { case INT8: @@ -135,14 +135,14 @@ private static void runValidTestCase(final String testKey, final BsonDocument te actualVectorData, actualVector); - assertThatVectorCreationResultsInCorrectBinary(Vector.int8Vector(expectedVectorData), + assertThatVectorCreationResultsInCorrectBinary(BinaryVector.int8Vector(expectedVectorData), testKey, actualDecodedDocument, expectedCanonicalBsonHex, description); break; case PACKED_BIT: - PackedBitVector actualPackedBitVector = actualVector.asPackedBitVector(); + PackedBitBinaryVector actualPackedBitVector = actualVector.asPackedBitVector(); byte[] expectedVectorPackedBitData = toByteArray(arrayVector); assertVectorDecoding( expectedVectorPackedBitData, @@ -150,21 +150,21 @@ private static void runValidTestCase(final String testKey, final BsonDocument te actualPackedBitVector); assertThatVectorCreationResultsInCorrectBinary( - Vector.packedBitVector(expectedVectorPackedBitData, expectedPadding), + BinaryVector.packedBitVector(expectedVectorPackedBitData, expectedPadding), testKey, actualDecodedDocument, expectedCanonicalBsonHex, description); break; case FLOAT32: - Float32Vector actualFloat32Vector = actualVector.asFloat32Vector(); + Float32BinaryVector actualFloat32Vector = actualVector.asFloat32Vector(); float[] expectedFloatVector = toFloatArray(arrayVector); assertVectorDecoding( expectedFloatVector, expectedDType, actualFloat32Vector); assertThatVectorCreationResultsInCorrectBinary( - Vector.floatVector(expectedFloatVector), + BinaryVector.floatVector(expectedFloatVector), testKey, actualDecodedDocument, expectedCanonicalBsonHex, @@ -179,7 +179,7 @@ private static void assertValidationException(final RuntimeException runtimeExce assertTrue(runtimeException instanceof IllegalArgumentException || runtimeException instanceof IllegalStateException); } - private static void assertThatVectorCreationResultsInCorrectBinary(final Vector expectedVectorData, + private static void assertThatVectorCreationResultsInCorrectBinary(final BinaryVector expectedVectorData, final String testKey, final BsonDocument actualDecodedDocument, final String expectedCanonicalBsonHex, @@ -191,18 +191,18 @@ private static void assertThatVectorCreationResultsInCorrectBinary(final Vector } private static void assertVectorDecoding(final byte[] expectedVectorData, - final Vector.DataType expectedDType, + final BinaryVector.DataType expectedDType, final byte[] actualVectorData, - final Vector actualVector) { + final BinaryVector actualVector) { Assertions.assertArrayEquals(actualVectorData, expectedVectorData, () -> "Actual: " + Arrays.toString(actualVectorData) + " != Expected:" + Arrays.toString(expectedVectorData)); assertEquals(expectedDType, actualVector.getDataType()); } private static void assertVectorDecoding(final byte[] expectedVectorData, - final Vector.DataType expectedDType, + final BinaryVector.DataType expectedDType, final byte expectedPadding, - final PackedBitVector actualVector) { + final PackedBitBinaryVector actualVector) { byte[] actualVectorData = actualVector.getData(); assertVectorDecoding( expectedVectorData, @@ -213,8 +213,8 @@ private static void assertVectorDecoding(final byte[] expectedVectorData, } private static void assertVectorDecoding(final float[] expectedVectorData, - final Vector.DataType expectedDType, - final Float32Vector actualVector) { + final BinaryVector.DataType expectedDType, + final Float32BinaryVector actualVector) { float[] actualVectorArray = actualVector.getData(); Assertions.assertArrayEquals(actualVectorArray, expectedVectorData, () -> "Actual: " + Arrays.toString(actualVectorArray) + " != Expected:" + Arrays.toString(expectedVectorData)); diff --git a/build.gradle b/build.gradle index 54679fa5d88..a516020089e 100644 --- a/build.gradle +++ b/build.gradle @@ -59,14 +59,16 @@ ext { junitBomVersion = '5.10.2' logbackVersion = '1.3.14' graalSdkVersion = '24.0.0' + reflectionsVersion = '0.9.10' gitVersion = getGitVersion() } def configDir = ext.configDir def utilProjects = project(":util").allprojects +def bomProjects = project(":bom") def coreProjects = subprojects - utilProjects -def scalaProjects = subprojects.findAll { it.name.contains('scala') } -def javaProjects = subprojects - scalaProjects +def scalaProjects = subprojects.findAll { it.name.contains('scala') } - bomProjects +def javaProjects = subprojects - scalaProjects - bomProjects def javaMainProjects = javaProjects - utilProjects def javaCodeCheckedProjects = javaMainProjects.findAll { !['driver-benchmarks', 'driver-workload-executor', 'driver-lambda'].contains(it.name) } def javaAndScalaTestedProjects = javaCodeCheckedProjects + scalaProjects @@ -75,7 +77,7 @@ configure(coreProjects) { apply plugin: 'idea' group = 'org.mongodb' - version = '5.3.0-beta0' + version = '5.4.0-alpha0' repositories { mavenLocal() @@ -128,7 +130,7 @@ configure(scalaProjects) { testImplementation('org.scalatestplus:junit-4-13_%%:3.2.9.0') testImplementation('org.scalatestplus:mockito-3-12_%%:3.2.10.0') testImplementation("ch.qos.logback:logback-classic:$logbackVersion") - testImplementation('org.reflections:reflections:0.9.10') + testImplementation("org.reflections:reflections:$reflectionsVersion") } test{ diff --git a/config/codenarc/codenarc.xml b/config/codenarc/codenarc.xml index 4a342373592..cfdd190abf6 100644 --- a/config/codenarc/codenarc.xml +++ b/config/codenarc/codenarc.xml @@ -41,6 +41,9 @@ + + + diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml index 4c083b0bce5..4ac460b0738 100644 --- a/config/detekt/detekt.yml +++ b/config/detekt/detekt.yml @@ -159,7 +159,7 @@ complexity: active: true excludes: ['**/test/**'] thresholdInFiles: 25 - thresholdInClasses: 25 + thresholdInClasses: 27 thresholdInInterfaces: 25 thresholdInObjects: 25 thresholdInEnums: 25 diff --git a/config/spotbugs/exclude.xml b/config/spotbugs/exclude.xml index 488c797a6a0..20684680865 100644 --- a/config/spotbugs/exclude.xml +++ b/config/spotbugs/exclude.xml @@ -223,6 +223,30 @@ + + + + + + + + + + + + + + + + + + + + + + + +

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy