Skip to content
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

Test against GraalVM native image technology #1338

Merged
merged 8 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
20 changes: 20 additions & 0 deletions .evergreen/.evg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,15 @@ functions:
params:
file: src/results.json

"run graalvm native image app":
- command: shell.exec
type: test
params:
working_dir: "src"
script: |
${PREPARE_SHELL}
MONGODB_URI="${MONGODB_URI}" JAVA_VERSION="${JAVA_VERSION}" .evergreen/run-graalvm-native-image-app.sh

# Anchors

pre:
Expand Down Expand Up @@ -1641,6 +1650,10 @@ tasks:
VERSION: latest
TOPOLOGY: replica_set
- func: run socks5 tests
- name: "graalvm-native-image-app"
commands:
- func: "bootstrap mongo-orchestration"
- func: "run graalvm native image app"
axes:
- id: version
display_name: MongoDB Version
Expand Down Expand Up @@ -2286,3 +2299,10 @@ buildvariants:
tasks:
- name: testazurekms_task_group
batchtime: 20160 # Use a batchtime of 14 days as suggested by the CSFLE test README

- matrix_name: "graalvm-native-image-app"
matrix_spec: { version: [ "7.0" ], topology: [ "replicaset" ], auth: [ "noauth" ], ssl: [ "nossl" ],
jdk: [ "jdk21" ], os: [ "linux" ] }
display_name: "GraalVM native image app: ${version} ${topology} ${auth} ${ssl} ${jdk} ${os}"
tasks:
- name: "graalvm-native-image-app"
3 changes: 3 additions & 0 deletions .evergreen/javaConfig.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export JDK8="/opt/java/jdk8"
export JDK11="/opt/java/jdk11"
export JDK17="/opt/java/jdk17"
export JDK21="/opt/java/jdk21"
# note that `JDK21_GRAALVM` is used in `run-graalvm-native-image-app.sh`
# by dynamically constructing the variable name
export JDK21_GRAALVM="/opt/java/jdk21-graalce"

if [ -d "$JDK17" ]; then
export JAVA_HOME=$JDK17
Expand Down
25 changes: 25 additions & 0 deletions .evergreen/run-graalvm-native-image-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Supported/used environment variables:
# MONGODB_URI The connection string to use, including credentials and topology info.
# JAVA_VERSION The Java SE version for Gradle toolchain.

set -o errexit

RELATIVE_DIR_PATH="$(dirname "${BASH_SOURCE[0]:-$0}")"
source "${RELATIVE_DIR_PATH}/javaConfig.bash"

echo "MONGODB_URI: ${MONGODB_URI}"
echo "JAVA_HOME: ${JAVA_HOME}"
readonly JDK_GRAALVM_VAR_NAME="JDK${JAVA_VERSION}_GRAALVM"
readonly JDK_GRAALVM="${!JDK_GRAALVM_VAR_NAME}"
echo "The JDK distribution for running Gradle is"
echo "$("${JAVA_HOME}"/bin/java --version)"
echo "The Java SE version for the Gradle toolchain is ${JAVA_VERSION}"
echo "The GraalVM JDK distribution expected to be found at \`${JDK_GRAALVM}\` by the Gradle toolchain functionality is"
echo "$("${JDK_GRAALVM}"/bin/java --version)"
echo "The Gradle version is"
./gradlew --version

echo "Building and running the GraalVM native image app"
./gradlew -PjavaVersion=${JAVA_VERSION} -Dorg.mongodb.test.uri=${MONGODB_URI} :graalvm-native-image-app:nativeRun
Copy link
Member Author

@stIncMale stIncMale Mar 20, 2024

Choose a reason for hiding this comment

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

Note how we only build and run the application, but do not collect reachability metadata - we use that from graalvm-native-image-app/src/main/resources/META-INF/native-image, which I collected on my computer (see graalvm-native-image-app/readme.md), and also manually added entries for shared libraries for OSes/ISAs different from mine. This means there is a chance we will be able to shovel this metadata in the right JARs and then build and run using only what we have in the JARs. I created JAVA-5381.

Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ public static void main(final String[] args) {
}});
}};

MongoClientSettings commonClientSettings = (
args.length == 0
? MongoClientSettings.builder()
: MongoClientSettings.builder().applyConnectionString(new ConnectionString(args[0])))
.build();
String keyVaultNamespace = "admin.datakeys";
ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder()
.keyVaultMongoClientSettings(MongoClientSettings.builder()
.applyConnectionString(new ConnectionString("mongodb://localhost"))
.build())
.keyVaultMongoClientSettings(commonClientSettings)
.keyVaultNamespace(keyVaultNamespace)
.kmsProviders(kmsProviders)
.build();
Expand Down Expand Up @@ -107,7 +110,7 @@ public static void main(final String[] args) {
+ "}"));
}}).build();

MongoClientSettings clientSettings = MongoClientSettings.builder()
MongoClientSettings clientSettings = MongoClientSettings.builder(commonClientSettings)
.autoEncryptionSettings(autoEncryptionSettings)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ public static void main(final String[] args) {
}};

MongoNamespace keyVaultNamespace = new MongoNamespace("encryption.testKeyVault");

MongoClientSettings clientSettings = MongoClientSettings.builder().build();
MongoClient mongoClient = MongoClients.create(clientSettings);
MongoClientSettings commonClientSettings = (
args.length == 0
? MongoClientSettings.builder()
: MongoClientSettings.builder().applyConnectionString(new ConnectionString(args[0])))
.build();
MongoClient mongoClient = MongoClients.create(commonClientSettings);

// Set up the key vault for this example
MongoCollection<Document> keyVaultCollection = mongoClient.getDatabase(keyVaultNamespace.getDatabaseName())
Expand All @@ -96,9 +99,7 @@ public static void main(final String[] args) {

// Create the ClientEncryption instance
ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder()
.keyVaultMongoClientSettings(MongoClientSettings.builder()
.applyConnectionString(new ConnectionString("mongodb://localhost"))
.build())
.keyVaultMongoClientSettings(commonClientSettings)
.keyVaultNamespace(keyVaultNamespace.getFullName())
.kmsProviders(kmsProviders)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ public static void main(final String[] args) {
}};

MongoNamespace keyVaultNamespace = new MongoNamespace("encryption.testKeyVault");

MongoClientSettings clientSettings = MongoClientSettings.builder()
MongoClientSettings commonClientSettings = (
args.length == 0
? MongoClientSettings.builder()
: MongoClientSettings.builder().applyConnectionString(new ConnectionString(args[0])))
.build();
MongoClientSettings clientSettings = MongoClientSettings.builder(commonClientSettings)
.autoEncryptionSettings(AutoEncryptionSettings.builder()
.keyVaultNamespace(keyVaultNamespace.getFullName())
.kmsProviders(kmsProviders)
Expand Down Expand Up @@ -102,9 +106,7 @@ public static void main(final String[] args) {

// Create the ClientEncryption instance
ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder()
.keyVaultMongoClientSettings(MongoClientSettings.builder()
.applyConnectionString(new ConnectionString("mongodb://localhost"))
.build())
.keyVaultMongoClientSettings(commonClientSettings)
.keyVaultNamespace(keyVaultNamespace.getFullName())
.kmsProviders(kmsProviders)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package reactivestreams.tour;

import com.mongodb.AutoEncryptionSettings;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.result.InsertOneResult;
import com.mongodb.reactivestreams.client.MongoClient;
Expand Down Expand Up @@ -64,7 +65,10 @@ public static void main(final String[] args) {
.kmsProviders(kmsProviders)
.build();

MongoClientSettings clientSettings = MongoClientSettings.builder()
MongoClientSettings clientSettings = (
args.length == 0
? MongoClientSettings.builder()
: MongoClientSettings.builder().applyConnectionString(new ConnectionString(args[0])))
.autoEncryptionSettings(autoEncryptionSettings)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package documentation;

import com.mongodb.ClientSessionOptions;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.ReadConcern;
import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
Expand All @@ -42,8 +44,13 @@ public final class CausalConsistencyExamples {
* @param args takes an optional single argument for the connection string
*/
public static void main(final String[] args) {
setupDatabase();
MongoClient client = MongoClients.create();
MongoClientSettings clientSettings = (
args.length == 0
? MongoClientSettings.builder()
: MongoClientSettings.builder().applyConnectionString(new ConnectionString(args[0])))
.build();
setupDatabase(clientSettings);
MongoClient client = MongoClients.create(clientSettings);

// Start Causal Consistency Example 1
// Example 1: Use a causally consistent session to ensure that the update occurs before the insert.
Expand Down Expand Up @@ -81,8 +88,8 @@ public static void main(final String[] args) {
// End Causal Consistency Example 2
}

private static void setupDatabase() {
MongoClient client = MongoClients.create();
private static void setupDatabase(final MongoClientSettings clientSettings) {
MongoClient client = MongoClients.create(clientSettings);
client.getDatabase("test").drop();

MongoDatabase database = client.getDatabase("test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ public static void main(final String[] args) {
put("key", localMasterKey);
}});
}};

MongoClientSettings commonClientSettings = (
args.length == 0
? MongoClientSettings.builder()
: MongoClientSettings.builder().applyConnectionString(new ConnectionString(args[0])))
.build();
String keyVaultNamespace = "encryption.__keyVault";
ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder()
.keyVaultMongoClientSettings(MongoClientSettings.builder()
.applyConnectionString(new ConnectionString("mongodb://localhost"))
.build())
.keyVaultMongoClientSettings(commonClientSettings)
.keyVaultNamespace(keyVaultNamespace)
.kmsProviders(kmsProviders)
.build();
Expand Down Expand Up @@ -99,7 +101,7 @@ public static void main(final String[] args) {
+ "}"));
}}).build();

MongoClientSettings clientSettings = MongoClientSettings.builder()
MongoClientSettings clientSettings = MongoClientSettings.builder(commonClientSettings)
.autoEncryptionSettings(autoEncryptionSettings)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ public static void main(final String[] args) {
put("key", localMasterKey);
}});
}};

MongoClientSettings clientSettings = MongoClientSettings.builder().build();
MongoClient mongoClient = MongoClients.create(clientSettings);
MongoClientSettings commonClientSettings = (
args.length == 0
? MongoClientSettings.builder()
: MongoClientSettings.builder().applyConnectionString(new ConnectionString(args[0])))
.build();
MongoClient mongoClient = MongoClients.create(commonClientSettings);

// Set up the key vault for this example
MongoNamespace keyVaultNamespace = new MongoNamespace("encryption.testKeyVault");
Expand All @@ -81,9 +84,7 @@ public static void main(final String[] args) {

// Create the ClientEncryption instance
ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder()
.keyVaultMongoClientSettings(MongoClientSettings.builder()
.applyConnectionString(new ConnectionString("mongodb://localhost"))
.build())
.keyVaultMongoClientSettings(commonClientSettings)
.keyVaultNamespace(keyVaultNamespace.getFullName())
.kmsProviders(kmsProviders)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ public static void main(final String[] args) {
}};

MongoNamespace keyVaultNamespace = new MongoNamespace("encryption.testKeyVault");

MongoClientSettings clientSettings = MongoClientSettings.builder()
MongoClientSettings commonClientSettings = (
args.length == 0
? MongoClientSettings.builder()
: MongoClientSettings.builder().applyConnectionString(new ConnectionString(args[0])))
.build();
MongoClientSettings clientSettings = MongoClientSettings.builder(commonClientSettings)
.autoEncryptionSettings(AutoEncryptionSettings.builder()
.keyVaultNamespace(keyVaultNamespace.getFullName())
.kmsProviders(kmsProviders)
Expand All @@ -87,9 +91,7 @@ public static void main(final String[] args) {

// Create the ClientEncryption instance
ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder()
.keyVaultMongoClientSettings(MongoClientSettings.builder()
.applyConnectionString(new ConnectionString("mongodb://localhost"))
.build())
.keyVaultMongoClientSettings(commonClientSettings)
.keyVaultNamespace(keyVaultNamespace.getFullName())
.kmsProviders(kmsProviders)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package tour;

import com.mongodb.AutoEncryptionSettings;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
Expand Down Expand Up @@ -59,7 +60,10 @@ public static void main(final String[] args) {
.kmsProviders(kmsProviders)
.build();

MongoClientSettings clientSettings = MongoClientSettings.builder()
MongoClientSettings clientSettings = (
args.length == 0
? MongoClientSettings.builder()
: MongoClientSettings.builder().applyConnectionString(new ConnectionString(args[0])))
.autoEncryptionSettings(autoEncryptionSettings)
.build();

Expand Down
Loading