Skip to content

JAVA-5771 Add search integration tests #1616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 39 additions & 37 deletions .evergreen/.evg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,19 @@ functions:
mongo --nodb setup.js aws_e2e_ecs.js
cd -

run-atlas-connectivity-test-func:
- 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

"run atlas data lake test":
- command: shell.exec
type: test
Expand Down Expand Up @@ -627,19 +640,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
Expand Down Expand Up @@ -1471,6 +1471,20 @@ tasks:
commands:
- func: "run atlas search test"

- name: "atlas-test-task"
commands:
- func: run-atlas-connectivity-test-func

- 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: "gssapi-auth-test"
commands:
- func: "run gssapi auth test"
Expand All @@ -1490,20 +1504,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"
Expand Down Expand Up @@ -1630,7 +1630,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:
Expand Down Expand Up @@ -1918,7 +1917,7 @@ axes:
batchtime: 10080 # 7 days

task_groups:
- name: test_atlas_task_group_search_indexes
- name: test-atlas-search-task-group
setup_group:
- func: fetch source
- func: prepare resources
Expand All @@ -1944,6 +1943,7 @@ task_groups:
setup_group_timeout_secs: 1800
tasks:
- test-atlas-search-index-helpers

- name: testgcpkms_task_group
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800 # 30 minutes
Expand Down Expand Up @@ -1979,6 +1979,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
Expand Down Expand Up @@ -2023,6 +2024,7 @@ task_groups:
$DRIVERS_TOOLS/.evergreen/csfle/azurekms/delete-vm.sh
tasks:
- testazurekms-task

- name: test_atlas_task_group
setup_group:
- func: fetch source
Expand Down Expand Up @@ -2295,12 +2297,6 @@ buildvariants:
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
Expand Down Expand Up @@ -2361,18 +2357,24 @@ buildvariants:
tasks:
- name: "atlas-data-lake-test"

- name: atlas-test
- name: atlas-test-variant
display_name: "Atlas test"
run_on: rhel80-small
tasks:
- name: "atlas-test"
- name: atlas-test-task

- name: atlas-search-test
display_name: "Atlas Search test"
run_on: rhel80-small
tasks:
- name: "atlas-search-test"

- name: atlas-search-variant
display_name: "Atlas Search Tests"
Copy link
Member

Choose a reason for hiding this comment

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

With the renaming "Atlas Search Index Management Tests" to "Atlas Search Tests", we will have two variants with the same name Atlas Search test and theseAtlas Search Tests. The only way to differentiate them would be by checking the tasks in Evergreen.

To make the distinction clearer at a glance, i think we should use more explicit naming. I suggest either keeping the previous name or renaming them as:

Atlas Search Test [Static Dev Cluster] – for the test using a pre-existing, always-running cluster.
Atlas Search Tests [Dynamic Cluster] – for the test that provisions a cluster, runs tests, and shuts it down.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have merged these into one "Atlas Tests" variant, and have cleaned up related evg config. The data lake test remains on ubuntu2004-small; IIRC this is to ensure docker is available.

There is a failure in test-aws-lambda-deployed, however this predates this PR. When I ran it on 0e256548e6, see patch, it failed, though it passed on that commit previously - looks like an environment change.

run_on: rhel80-small
tasks:
- name: "test-atlas-search-task-group"

- name: "reactive-streams-tck-test"
display_name: "Reactive Streams TCK tests"
run_on: rhel80-small
Expand Down
4 changes: 3 additions & 1 deletion .evergreen/run-atlas-search-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixes the missing Binary in AggregatesBinaryVectorSearchIntegrationTest. The tests were not previously being run.

Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,24 @@
import com.mongodb.annotations.Sealed;
import com.mongodb.client.model.Aggregates;
import com.mongodb.client.model.geojson.Point;

import java.util.UUID;

import org.bson.BsonBinary;
import org.bson.BsonNull;
import org.bson.BsonDocument;
import org.bson.BsonNull;
import org.bson.BsonType;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bson.types.ObjectId;

import java.time.Duration;
import java.time.Instant;
import java.util.Iterator;

import org.bson.types.ObjectId;
import java.util.UUID;

import static com.mongodb.assertions.Assertions.isTrueArgument;
import static com.mongodb.assertions.Assertions.notNull;
import static com.mongodb.internal.Iterables.concat;
import static com.mongodb.internal.client.model.Util.combineToBsonValue;
import static java.util.Collections.singleton;
import static com.mongodb.assertions.Assertions.notNull;

/**
* The core part of the {@link Aggregates#search(SearchOperator, SearchOptions) $search} pipeline stage of an aggregation pipeline.
Expand Down Expand Up @@ -463,14 +460,15 @@ static PhraseSearchOperator phrase(final Iterable<? extends SearchPath> paths, f
}

/**
* Returns a {@link SearchOperator} that performs a search using a special characters in the search string that can match any character.
* Returns a {@link SearchOperator} that performs a search using a special
* characters in the search string that can match any character.
*
* @param path The indexed field to be searched.
* @param query The string to search for.
* @param path The indexed field to be searched.
* @return The requested {@link SearchOperator}.
* @mongodb.atlas.manual atlas-search/wildcard/ wildcard operator
*/
static WildcardSearchOperator wildcard(final String query, final SearchPath path) {
static WildcardSearchOperator wildcard(final SearchPath path, final String query) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Parameter order is inconsistent. I refactored this (in a separate commit) to match at least regex, but this is already inconsistent in the API. I left a comment on the JIRA for revisiting the API.

return wildcard(singleton(notNull("query", query)), singleton(notNull("path", path)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.mongodb.annotations.Sealed;

/**
* @see SearchOperator#wildcard(String, SearchPath)
* @see SearchOperator#wildcard(SearchPath, String)
* @see SearchOperator#wildcard(Iterable, Iterable)
* @since 4.7
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import com.mongodb.client.model.SearchIndexType;
import com.mongodb.client.test.CollectionHelper;
import com.mongodb.internal.operation.SearchIndexRequest;
import org.bson.BinaryVector;
import org.bson.BsonDocument;
import org.bson.Document;
import org.bson.BinaryVector;
import org.bson.codecs.DocumentCodec;
import org.bson.conversions.Bson;
import org.junit.jupiter.api.AfterAll;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
import static org.junit.jupiter.params.provider.Arguments.arguments;

/**
* Use this class when needing to test against MFLIX specifically. Otherwise,
Copy link
Member

@vbabanin vbabanin Feb 4, 2025

Choose a reason for hiding this comment

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

[nit] It might be more noticeable if placed right above public class AggregatesSearchIntegrationTest.

* see AggregatesSearchTest.
* <p>
* These tests require the <a href="https://www.mongodb.com/docs/atlas/sample-data/">sample data</a>
* and the following Atlas Search indices:
* <table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,8 @@ void wildcard() {
.append("path", fieldPath("fieldName").toBsonValue())
),
SearchOperator.wildcard(
"term",
fieldPath("fieldName"))
fieldPath("fieldName"), "term"
)
.toBsonDocument()
),
() -> assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ object SearchOperator {
* @return The requested `SearchOperator`.
* @see [[https://www.mongodb.com/docs/atlas/atlas-search/wildcard/ wildcard operator]]
*/
def wildcard(query: String, path: SearchPath): WildcardSearchOperator = JSearchOperator.wildcard(query, path)
def wildcard(query: String, path: SearchPath): WildcardSearchOperator = JSearchOperator.wildcard(path, query)

/**
* Returns a `SearchOperator` that enables queries which use special characters in the search string that can match any character.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@

package com.mongodb.client;

import com.mongodb.MongoNamespace;
import com.mongodb.client.test.CollectionHelper;
import com.mongodb.internal.connection.ServerHelper;
import org.bson.BsonDocument;
import org.bson.BsonDocumentWrapper;
import org.bson.Document;
import org.bson.codecs.DocumentCodec;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -40,7 +37,7 @@ public class DatabaseTestCase {

@BeforeEach
public void setUp() {
client = getMongoClient();
client = getMongoClient();
database = client.getDatabase(getDefaultDatabaseName());
collection = database.getCollection(getClass().getName());
collection.drop();
Expand All @@ -58,23 +55,7 @@ public void tearDown() {
}
}

protected String getDatabaseName() {
return database.getName();
}

protected String getCollectionName() {
return collection.getNamespace().getCollectionName();
}

protected MongoNamespace getNamespace() {
return collection.getNamespace();
}

protected CollectionHelper<Document> getCollectionHelper() {
return new CollectionHelper<>(new DocumentCodec(), getNamespace());
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Above removals are old (several years) dead code.


protected BsonDocument wrap(final Document document) {
return new BsonDocumentWrapper<>(document, new DocumentCodec());
return new CollectionHelper<>(new DocumentCodec(), collection.getNamespace());
}
}
Loading