Skip to content

Commit

Permalink
Run tests against Atlas serverless instance (mongodb#763)
Browse files Browse the repository at this point in the history
Skip tests as necessary

JAVA-3987
  • Loading branch information
jyemin authored and ispringer committed May 16, 2023
1 parent 9abedbb commit 7f9619d
Show file tree
Hide file tree
Showing 37 changed files with 192 additions and 25 deletions.
52 changes: 52 additions & 0 deletions .evergreen/.evg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,40 @@ functions:
params:
file: lb-expansion.yml

"run serverless":
- command: shell.exec
params:
shell: "bash"
script: |
${PREPARE_SHELL}
set +o xtrace
SERVERLESS_DRIVERS_GROUP=${SERVERLESS_DRIVERS_GROUP} \
SERVERLESS_API_PUBLIC_KEY=${SERVERLESS_API_PUBLIC_KEY} \
SERVERLESS_API_PRIVATE_KEY=${SERVERLESS_API_PRIVATE_KEY} \
bash ${DRIVERS_TOOLS}/.evergreen/serverless/create-instance.sh
- command: expansions.update
params:
file: serverless-expansion.yml

"stop load-balancer":
- command: shell.exec
params:
script: |
cd ${DRIVERS_TOOLS}/.evergreen
DRIVERS_TOOLS=${DRIVERS_TOOLS} bash ${DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh stop
"stop serverless":
- command: shell.exec
params:
script: |
${PREPARE_SHELL}
set +o xtrace
SERVERLESS_DRIVERS_GROUP=${SERVERLESS_DRIVERS_GROUP} \
SERVERLESS_API_PUBLIC_KEY=${SERVERLESS_API_PUBLIC_KEY} \
SERVERLESS_API_PRIVATE_KEY=${SERVERLESS_API_PRIVATE_KEY} \
SERVERLESS_INSTANCE_NAME=${SERVERLESS_INSTANCE_NAME} \
bash ${DRIVERS_TOOLS}/.evergreen/serverless/delete-instance.sh
"run tests":
- command: shell.exec
type: test
Expand Down Expand Up @@ -290,6 +317,19 @@ functions:
MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}" \
.evergreen/run-load-balancer-tests.sh
"run serverless tests":
- command: shell.exec
type: test
params:
working_dir: "src"
script: |
${PREPARE_SHELL}
JDK="${JDK}" \
MONGODB_URI="${MONGODB_URI}" \
SERVERLESS_ATLAS_USER="${SERVERLESS_ATLAS_USER}" \
SERVERLESS_ATLAS_PASSWORD="${SERVERLESS_ATLAS_PASSWORD}" \
.evergreen/run-serverless-tests.sh
"run reactive streams tck tests":
- command: shell.exec
type: test
Expand Down Expand Up @@ -726,6 +766,7 @@ post:
- func: "upload working dir logs"
- func: "upload test results"
- func: "stop load-balancer"
- func: "stop serverless"
- func: "cleanup"

tasks:
Expand All @@ -749,6 +790,11 @@ tasks:
- func: "run load-balancer"
- func: "run load-balancer tests"

- name: serverless-test
commands:
- func: "run serverless"
- func: "run serverless tests"

- name: "scala-tests"
commands:
- func: "bootstrap mongo-orchestration"
Expand Down Expand Up @@ -1489,6 +1535,12 @@ buildvariants:
tasks:
- name: "load-balancer-test"

- matrix_name: "tests-serverless"
matrix_spec: { jdk: ["jdk11"], os: "ubuntu" }
display_name: "Serverless"
tasks:
- name: "serverless-test"

- matrix_name: "tests-slow"
matrix_spec: { auth: "noauth", ssl: "*", jdk: "jdk8", version: ["4.2"], topology: "*", os: "linux" }
display_name: "Slow: ${version} ${topology} ${ssl} ${jdk} ${os} "
Expand Down
34 changes: 34 additions & 0 deletions .evergreen/run-serverless-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Don't trace since the URI contains a password that shouldn't show up in the logs
set -o errexit # Exit the script with error if any of the commands fail

# Supported/used environment variables:
# JDK Set the version of java to be used. Java versions can be set from the java toolchain /opt/java
# MONGODB_URI The URI, without credentials
# SERVERLESS_ATLAS_USER
# SERVERLESS_ATLAS_PASSWORD
# Support arguments:
# Pass as many MongoDB URIS as arguments to this script as required

JDK=${JDK:-jdk8}

############################################
# Main Program #
############################################

echo "Running serverless tests with ${JDK}"

export JAVA_HOME="/opt/java/jdk11"

MONGODB_URI_SINGLE_HOST=${MONGODB_URI%%,*}
SINGLE_HOST=${MONGODB_URI_SINGLE_HOST:10}

MONGODB_URI_FINAL="mongodb://${SERVERLESS_ATLAS_USER}:${SERVERLESS_ATLAS_PASSWORD}@${SINGLE_HOST}/?tls=true"

echo ${MONGODB_URI_FINAL}

./gradlew -version

./gradlew -PjdkHome=/opt/java/${JDK} -Dorg.mongodb.test.uri=${MONGODB_URI_FINAL} -Dorg.mongodb.test.serverless=true \
--stacktrace --info --continue driver-sync:test
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public final class ClusterFixture {
public static final String MONGODB_URI_SYSTEM_PROPERTY_NAME = "org.mongodb.test.uri";
public static final String MONGODB_API_VERSION = "org.mongodb.test.api.version";
public static final String MONGODB_TRANSACTION_URI_SYSTEM_PROPERTY_NAME = "org.mongodb.test.transaction.uri";
public static final String SERVERLESS_TEST_SYSTEM_PROPERTY_NAME = "org.mongodb.test.serverless";
public static final String DATA_LAKE_TEST_SYSTEM_PROPERTY_NAME = "org.mongodb.test.data.lake";
private static final String MONGODB_OCSP_SHOULD_SUCCEED = "org.mongodb.test.ocsp.tls.should.succeed";
private static final String DEFAULT_DATABASE_NAME = "JavaDriverTest";
Expand Down Expand Up @@ -220,6 +221,10 @@ public static synchronized ConnectionString getMultiMongosConnectionString() {
return getConnectionStringFromSystemProperty(MONGODB_TRANSACTION_URI_SYSTEM_PROPERTY_NAME);
}

public static boolean isServerlessTest() {
return System.getProperty(SERVERLESS_TEST_SYSTEM_PROPERTY_NAME, "").equals("true");
}

public static synchronized boolean isDataLakeTest() {
String isDataLakeSystemProperty = System.getProperty(DATA_LAKE_TEST_SYSTEM_PROPERTY_NAME);
return isDataLakeSystemProperty != null && isDataLakeSystemProperty.equals("true");
Expand Down Expand Up @@ -499,6 +504,10 @@ public static boolean isAuthenticated() {
return getConnectionString().getCredential() != null;
}

public static boolean isClientSideEncryptionTest() {
return !System.getProperty("org.mongodb.test.awsAccessKeyId", "").isEmpty();
}

public static void enableMaxTimeFailPoint() {
configureFailPoint(BsonDocument.parse("{configureFailPoint: 'maxTimeAlwaysTimeOut', mode: 'alwaysOn'}"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.mongodb.connection.ServerVersion;
import org.bson.BsonArray;
import org.bson.BsonDocument;
import org.bson.BsonString;
import org.bson.BsonValue;

import java.util.List;
Expand All @@ -43,6 +44,10 @@ public static boolean skipTest(final BsonDocument testDocument, final BsonDocume
}

private static boolean canRunTest(final BsonDocument document, final ServerVersion serverVersion) {
if ((!serverlessMatches(document.getString("serverless", new BsonString("allow")).getValue()))) {
return false;
}

if (document.containsKey("minServerVersion")
&& serverVersion.compareTo(getMinServerVersionForField("minServerVersion", document)) < 0) {
return false;
Expand All @@ -51,9 +56,8 @@ private static boolean canRunTest(final BsonDocument document, final ServerVersi
&& serverVersion.compareTo(getMaxServerVersionForField("maxServerVersion", document)) > 0) {
return false;
}
if (document.containsKey("topology")) {
BsonArray topologyTypes = document.getArray("topology");
return topologyMatches(topologyTypes);
if (document.containsKey("topology") && !topologyMatches(document.getArray("topology"))) {
return false;
}

if (document.containsKey("runOn")) {
Expand All @@ -69,8 +73,8 @@ private static boolean canRunTest(final BsonDocument document, final ServerVersi
&& serverVersion.compareTo(getMaxServerVersionForField("ignore_if_server_version_greater_than", document)) > 0) {
return false;
}
if (document.containsKey("ignore_if_topology_type")) {
return !topologyMatches(document.getArray("ignore_if_topology_type"));
if (document.containsKey("ignore_if_topology_type") && topologyMatches(document.getArray("ignore_if_topology_type"))) {
return false;
}

return true;
Expand Down Expand Up @@ -105,6 +109,19 @@ public static boolean topologyMatches(final BsonArray topologyTypes) {
return false;
}

public static boolean serverlessMatches(final String serverlessRequirement) {
switch (serverlessRequirement) {
case "require":
return ClusterFixture.isServerlessTest();
case "forbid":
return !ClusterFixture.isServerlessTest();
case "allow":
return true;
default:
throw new UnsupportedOperationException("Unsupported serverless requirement value: " + serverlessRequirement);
}
}

public static ServerVersion getMinServerVersionForField(final String fieldName, final BsonDocument document) {
return getMinServerVersion(document.getString(fieldName).getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "Aggregate with collation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}
],
"minServerVersion": "2.6",
"serverless": "forbid",
"tests": [
{
"description": "Aggregate with $out",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "Count documents with collation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "Distinct with a collation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "Find with a collation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "BulkWrite with delete operations and collation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "DeleteMany when many documents match with collation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "DeleteOne when many documents matches with collation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "FindOneAndDelete when one document matches with collation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "FindOneAndReplace when one document matches with collation returning the document after modification",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "FindOneAndUpdate when many documents match with collation returning the document before modification",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "ReplaceOne when one document matches with collation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "UpdateMany when many documents match with collation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}
],
"minServerVersion": "3.4",
"serverless": "forbid",
"tests": [
{
"description": "UpdateOne when one document matches with collation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.Map;

import static com.mongodb.ClusterFixture.TIMEOUT_DURATION;
import static com.mongodb.ClusterFixture.isClientSideEncryptionTest;
import static com.mongodb.ClusterFixture.serverVersionAtLeast;
import static com.mongodb.reactivestreams.client.Fixture.getMongoClient;
import static com.mongodb.reactivestreams.client.Fixture.getMongoClientBuilderFromConnectionString;
Expand All @@ -66,9 +67,7 @@ public ClientSideEncryptionExternalKeyVaultTest(final boolean withExternalKeyVau
@Before
public void setUp() throws Throwable {
assumeTrue(serverVersionAtLeast(4, 2));
assumeTrue("Encryption test with external keyVault is disabled",
System.getProperty("org.mongodb.test.awsAccessKeyId") != null
&& !System.getProperty("org.mongodb.test.awsAccessKeyId").isEmpty());
assumeTrue("Encryption test with external keyVault is disabled", isClientSideEncryptionTest());

/* Step 1: get unencrypted client and recreate keys collection */
MongoClient client = getMongoClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Map;

import static com.mongodb.ClusterFixture.TIMEOUT_DURATION;
import static com.mongodb.ClusterFixture.isClientSideEncryptionTest;
import static com.mongodb.ClusterFixture.isStandalone;
import static com.mongodb.ClusterFixture.serverVersionAtLeast;
import static com.mongodb.reactivestreams.client.Fixture.getDefaultDatabaseName;
Expand Down Expand Up @@ -73,6 +74,7 @@ public ClientSideEncryptionSessionTest(final boolean useTransaction) {
@Before
public void setUp() throws Throwable {
assumeTrue(serverVersionAtLeast(4, 2));
assumeTrue(isClientSideEncryptionTest());
assumeFalse(isStandalone());

/* Step 1: get unencrypted client and recreate keys collection */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Map;

import static com.mongodb.ClusterFixture.TIMEOUT_DURATION;
import static com.mongodb.ClusterFixture.isClientSideEncryptionTest;
import static com.mongodb.ClusterFixture.serverVersionAtLeast;
import static com.mongodb.reactivestreams.client.Fixture.getMongoClient;
import static com.mongodb.reactivestreams.client.Fixture.getMongoClientBuilderFromConnectionString;
Expand All @@ -45,9 +46,7 @@ public class ClientSideEncryptionViewAreProhibitedTest {
@Before
public void setUp() {
assumeTrue(serverVersionAtLeast(4, 2));
assumeTrue("Encryption test with external keyVault is disabled",
System.getProperty("org.mongodb.test.awsAccessKeyId") != null
&& !System.getProperty("org.mongodb.test.awsAccessKeyId").isEmpty());
assumeTrue("Encryption test with external keyVault is disabled", isClientSideEncryptionTest());

MongoClient client = getMongoClient();

Expand Down

0 comments on commit 7f9619d

Please sign in to comment.