-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
JAVA-5771 Add search integration tests #1616
Conversation
driver-core:test --tests AggregatesSearchIntegrationTest --tests AggregatesVectorSearchIntegrationTest | ||
driver-core:test --tests AggregatesSearchIntegrationTest \ | ||
--tests AggregatesBinaryVectorSearchIntegrationTest \ | ||
--tests AggregatesSearchTest \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes the missing Binary
in AggregatesBinaryVectorSearchIntegrationTest
. The tests were not previously being run.
* @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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
protected CollectionHelper<Document> getCollectionHelper() { | ||
return new CollectionHelper<>(new DocumentCodec(), getNamespace()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above removals are old (several years) dead code.
@@ -59,34 +71,15 @@ public static synchronized MongoDatabase getDefaultDatabase() { | |||
} | |||
|
|||
public static String getDefaultDatabaseName() { | |||
return DEFAULT_DATABASE_NAME; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has the same value as ClusterFixture
return; | ||
} | ||
if (defaultDatabase != null) { | ||
defaultDatabase.drop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactoring just moves the logic close to where it is used.
I do not really understand why we use a shutdownHook here, when elsewhere we rely on @AfterEach/All
to clear resources. Perhaps we should either be using something that registers resources for shutdown with a shutdown hook, or just not using a shutdown hook at all.
.findAny().orElse(null); | ||
} | ||
|
||
static void waitForIndex(final MongoCollection<Document> collection, final String indexName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does duplicate functionality from the other test - it copies what I used in LangChain4j, and handles FAILED. I did not merge both, because that would require moving the other test to sync
. I do not mind doing this, if that seems best.
.evergreen/.evg.yml
Outdated
|
||
- 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I 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.
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
||
public class AggregatesSearchTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s use the FunctionalTest or IntegrationTest suffix here. This makes it easier to distinguish tests by their nature when searching or troubleshooting failures in Evergreen. We don't have particular convention but it seems that test classes without any suffix other than Test
are usually unit tests. This also seems to align with the pattern that has been followed lately.
Also, should we make it abstract and share between sync and async for better coverage? What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have renamed to FunctionalTest, but I am unsure - the root dir is called functional test. It seems that we could do a better job with naming and organizing our tests - the com.mongodb.client directory has many unorganized tests, and there are various inconsistencies with test naming (I clicked around and opened AbstractClientSideEncryptionDeadlockTest, and it is not a unit test).
As an aside, I think we should prefer not creating abstract classes, but instead write a single sync class, which we extend, with just the one getMongoClient override.
In this case, I do not think we are testing anything specific to the async side (that is, builders cannot possibly produce different results based on whether they are used from sync or async). Since the test is a usage test, I wonder if we should write it (and many other tests) using the actual async mongo client (instead of the wrapper), since the point of writing this in driver-sync
rather than core is to see the interface "in context"? I am not sure about undertaking that in this PR, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree - we should establish a more structured and consistent approach to organizing tests. This is something worth deciding on.
Regarding avoiding abstract test classes, that makes sense to me. In practice, we already follow a similar pattern by overriding sync components with blocking async implementations.
As for the last point, I agree - this PR might not be the best place to make that change.
} | ||
|
||
@Nullable | ||
private static Document indexRecord( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i initially thought this method also indexes some record. I suggest we rename to find...()
:
private static Document indexRecord( | |
private static Document findSearchIndex( |
|
||
static void waitForIndex(final MongoCollection<Document> collection, final String indexName) { | ||
long startTime = System.nanoTime(); | ||
long timeoutNanos = TimeUnit.SECONDS.toNanos(20); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use around around a minute here? I remember that it was taking more then 40 seconds sometimes for index to be created when BinaryVectorSearchIntegrationTests
was executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try with 20, and if it is failing, we can report the issue and update. This is supposed to be a near-empty database.
* limitations under the License. | ||
*/ | ||
|
||
package com.mongodb.client.model.mql; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this package is the best fit for Atlas Search tests, as it seems to contain tests for the MQL API
. Should we consider using the com.mongodb.client.model.search
package, similar to driver-core?
@@ -121,6 +121,9 @@ | |||
import static org.junit.jupiter.params.provider.Arguments.arguments; | |||
|
|||
/** | |||
* Use this class when needing to test against MFLIX specifically. Otherwise, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] It might be more noticeable if placed right above public class AggregatesSearchIntegrationTest
.
# Conflicts: # driver-core/src/main/com/mongodb/client/model/search/SearchOperator.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Current system failure, though renamed, has a base status of system failure, see example. Merging. |
JAVA-5771
This adds AggregatesSearchTest, containing integration tests for the $search stage API.
Other files are simple refactoring (moving the atlas tests together in evg, renaming tasks and functions having the same name, etc.), unless otherwise noted.