From d6f890c7b9167d764064e58cbe541c86fe377d39 Mon Sep 17 00:00:00 2001
From: Chris Eager <79161849+eager-signal@users.noreply.github.com>
Date: Mon, 11 Nov 2024 16:50:47 -0600
Subject: [PATCH] Use AmazonDynamoDBLocal instead of DynamoDBProxyServer
---
pom.xml | 29 +------
service/pom.xml | 15 ----
.../LocalWhisperServerService.java | 2 -
.../WhisperServerServiceTest.java | 48 ++++++------
.../configuration/LocalDynamoDbFactory.java | 3 +-
.../storage/DynamoDbExtension.java | 75 ++-----------------
6 files changed, 31 insertions(+), 141 deletions(-)
diff --git a/pom.xml b/pom.xml
index 31950bc3f..06c8f94a6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,7 +43,7 @@
2.17.0
4.0.10
1.1.13
-
+
2.2.1
26.50.0
1.61.1
@@ -482,33 +482,6 @@
org.apache.maven.plugins
maven-dependency-plugin
3.7.1
-
-
- copy
- test-compile
-
- copy-dependencies
-
-
- test
- so,dll,dylib
- ${project.build.directory}/lib
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
-
- sqlite4java.library.path
- ${project.build.directory}/lib
-
-
-
diff --git a/service/pom.xml b/service/pom.xml
index 60fd98ad9..27d2f57a2 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -13,7 +13,6 @@
9.4.1
5.1.0
- 1.0.392
v3-rev20241016-2.0.0
3.2.0
@@ -435,13 +434,6 @@
test
-
- com.almworks.sqlite4java
- sqlite4java
- ${sqlite4java.version}
- test
-
-
io.projectreactor
reactor-core
@@ -480,13 +472,6 @@
DynamoDBLocal
test
-
- io.github.ganadist.sqlite4java
- libsqlite4java-osx-aarch64
- ${sqlite4java.version}
- dylib
- test
-
com.google.auth
diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/LocalWhisperServerService.java b/service/src/test/java/org/whispersystems/textsecuregcm/LocalWhisperServerService.java
index 5d06c5b7b..d89e8523c 100644
--- a/service/src/test/java/org/whispersystems/textsecuregcm/LocalWhisperServerService.java
+++ b/service/src/test/java/org/whispersystems/textsecuregcm/LocalWhisperServerService.java
@@ -26,8 +26,6 @@ public class LocalWhisperServerService {
System.setProperty("secrets.bundle.filename",
Resources.getResource("config/test-secrets-bundle.yml").getPath());
- System.setProperty("sqlite.dir", "service/target/lib");
- System.setProperty("aws.region", "local-test-region");
final String config = Optional.ofNullable(System.getenv(SIGNAL_SERVER_CONFIG_ENV_VAR))
.orElse(Resources.getResource("config/test.yml").getPath());
diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/WhisperServerServiceTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/WhisperServerServiceTest.java
index 6ed4cc231..5fbff4bac 100644
--- a/service/src/test/java/org/whispersystems/textsecuregcm/WhisperServerServiceTest.java
+++ b/service/src/test/java/org/whispersystems/textsecuregcm/WhisperServerServiceTest.java
@@ -45,8 +45,6 @@ class WhisperServerServiceTest {
static {
System.setProperty("secrets.bundle.filename",
Resources.getResource("config/test-secrets-bundle.yml").getPath());
- // needed for AppConfigDataClient initialization
- System.setProperty("aws.region", "local-test-region");
}
private static final DropwizardAppExtension EXTENSION = new DropwizardAppExtension<>(
@@ -57,7 +55,6 @@ class WhisperServerServiceTest {
@AfterAll
static void teardown() {
System.clearProperty("secrets.bundle.filename");
- System.clearProperty("aws.region");
}
@BeforeEach
@@ -140,36 +137,35 @@ class WhisperServerServiceTest {
final AwsCredentialsProvider awsCredentialsProvider = EXTENSION.getConfiguration().getAwsCredentialsConfiguration()
.build();
- try (DynamoDbClient dynamoDbClient = EXTENSION.getConfiguration().getDynamoDbClientConfiguration()
- .buildSyncClient(awsCredentialsProvider, new NoopAwsSdkMetricPublisher())) {
+ final DynamoDbClient dynamoDbClient = EXTENSION.getConfiguration().getDynamoDbClientConfiguration()
+ .buildSyncClient(awsCredentialsProvider, new NoopAwsSdkMetricPublisher());
- final DynamoDbExtension.TableSchema numbers = DynamoDbExtensionSchema.Tables.NUMBERS;
- final AttributeValue numberAV = AttributeValues.s("+12125550001");
+ final DynamoDbExtension.TableSchema numbers = DynamoDbExtensionSchema.Tables.NUMBERS;
+ final AttributeValue numberAV = AttributeValues.s("+12125550001");
- final GetItemResponse notFoundResponse = dynamoDbClient.getItem(GetItemRequest.builder()
- .tableName(numbers.tableName())
- .key(Map.of(numbers.hashKeyName(), numberAV))
- .build());
+ final GetItemResponse notFoundResponse = dynamoDbClient.getItem(GetItemRequest.builder()
+ .tableName(numbers.tableName())
+ .key(Map.of(numbers.hashKeyName(), numberAV))
+ .build());
- assertFalse(notFoundResponse.hasItem());
+ assertFalse(notFoundResponse.hasItem());
- dynamoDbClient.putItem(PutItemRequest.builder()
- .tableName(numbers.tableName())
- .item(Map.of(numbers.hashKeyName(), numberAV))
- .build());
+ dynamoDbClient.putItem(PutItemRequest.builder()
+ .tableName(numbers.tableName())
+ .item(Map.of(numbers.hashKeyName(), numberAV))
+ .build());
- final GetItemResponse foundResponse = dynamoDbClient.getItem(GetItemRequest.builder()
- .tableName(numbers.tableName())
- .key(Map.of(numbers.hashKeyName(), numberAV))
- .build());
+ final GetItemResponse foundResponse = dynamoDbClient.getItem(GetItemRequest.builder()
+ .tableName(numbers.tableName())
+ .key(Map.of(numbers.hashKeyName(), numberAV))
+ .build());
- assertTrue(foundResponse.hasItem());
+ assertTrue(foundResponse.hasItem());
- dynamoDbClient.deleteItem(DeleteItemRequest.builder()
- .tableName(numbers.tableName())
- .key(Map.of(numbers.hashKeyName(), numberAV))
- .build());
- }
+ dynamoDbClient.deleteItem(DeleteItemRequest.builder()
+ .tableName(numbers.tableName())
+ .key(Map.of(numbers.hashKeyName(), numberAV))
+ .build());
}
}
diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/configuration/LocalDynamoDbFactory.java b/service/src/test/java/org/whispersystems/textsecuregcm/configuration/LocalDynamoDbFactory.java
index f87f70dae..3dde0e4b4 100644
--- a/service/src/test/java/org/whispersystems/textsecuregcm/configuration/LocalDynamoDbFactory.java
+++ b/service/src/test/java/org/whispersystems/textsecuregcm/configuration/LocalDynamoDbFactory.java
@@ -16,8 +16,7 @@ import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
@JsonTypeName("local")
public class LocalDynamoDbFactory implements DynamoDbClientFactory {
- private static final DynamoDbExtension EXTENSION = new DynamoDbExtension(System.getProperty("sqlite.dir"),
- DynamoDbExtensionSchema.Tables.values());
+ private static final DynamoDbExtension EXTENSION = new DynamoDbExtension(DynamoDbExtensionSchema.Tables.values());
static {
try {
diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/DynamoDbExtension.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/DynamoDbExtension.java
index 8079fc358..1d8b5c7af 100644
--- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/DynamoDbExtension.java
+++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/DynamoDbExtension.java
@@ -5,21 +5,12 @@
package org.whispersystems.textsecuregcm.storage;
-import com.almworks.sqlite4java.SQLite;
-import com.amazonaws.services.dynamodbv2.local.main.ServerRunner;
-import com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer;
-import java.net.ServerSocket;
-import java.net.URI;
-import java.time.Duration;
+import com.amazonaws.services.dynamodbv2.local.embedded.DynamoDBEmbedded;
+import com.amazonaws.services.dynamodbv2.local.shared.access.AmazonDynamoDBLocal;
import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
@@ -29,12 +20,9 @@ import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement;
import software.amazon.awssdk.services.dynamodb.model.KeyType;
import software.amazon.awssdk.services.dynamodb.model.LocalSecondaryIndex;
import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput;
-import javax.annotation.Nullable;
public class DynamoDbExtension implements BeforeEachCallback, AfterEachCallback {
- private static final String DEFAULT_LIBRARY_PATH = "target/lib";
-
public interface TableSchema {
String tableName();
String hashKeyName();
@@ -58,36 +46,15 @@ public class DynamoDbExtension implements BeforeEachCallback, AfterEachCallback
.writeCapacityUnits(20L)
.build();
- private static final AtomicBoolean libraryLoaded = new AtomicBoolean();
-
- private DynamoDBProxyServer server;
- private int port;
-
- private final String libraryPath;
+ private AmazonDynamoDBLocal embedded;
private final List schemas;
private DynamoDbClient dynamoDB2;
private DynamoDbAsyncClient dynamoAsyncDB2;
public DynamoDbExtension(TableSchema... schemas) {
- this(DEFAULT_LIBRARY_PATH, schemas);
- }
-
- public DynamoDbExtension(@Nullable final String libraryPath, TableSchema... schemas) {
- this.libraryPath = Optional.ofNullable(libraryPath).orElse(DEFAULT_LIBRARY_PATH);
this.schemas = List.of(schemas);
}
- private void loadLibrary() {
- // to avoid noise in the logs from “library already loaded” warnings, we make sure we only set it once
- if (libraryLoaded.get()) {
- return;
- }
- if (libraryLoaded.compareAndSet(false, true)) {
- // if you see a library failed to load error, you need to run mvn test-compile at least once first
- SQLite.setLibraryPath(this.libraryPath);
- }
- }
-
@Override
public void afterEach(ExtensionContext context) {
stopServer();
@@ -98,7 +65,7 @@ public class DynamoDbExtension implements BeforeEachCallback, AfterEachCallback
*/
public void stopServer() {
try {
- server.stop();
+ embedded.shutdown();
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -106,9 +73,6 @@ public class DynamoDbExtension implements BeforeEachCallback, AfterEachCallback
@Override
public void beforeEach(ExtensionContext context) throws Exception {
-
- startServer();
-
initializeClient();
createTables();
@@ -143,35 +107,10 @@ public class DynamoDbExtension implements BeforeEachCallback, AfterEachCallback
getDynamoDbClient().createTable(createTableRequest);
}
- private void startServer() throws Exception {
- loadLibrary();
- try (ServerSocket serverSocket = new ServerSocket(0)) {
- port = serverSocket.getLocalPort();
- }
- server = ServerRunner.createServerFromCommandLineArgs(
- new String[]{"-disableTelemetry", "-inMemory", "-port", String.valueOf(port)});
- server.start();
- }
-
private void initializeClient() {
- dynamoDB2 = DynamoDbClient.builder()
- .endpointOverride(URI.create("http://localhost:" + port))
- .region(Region.of("local-test-region"))
- .credentialsProvider(StaticCredentialsProvider.create(
- AwsBasicCredentials.create("accessKey", "secretKey")))
- .overrideConfiguration(builder ->
- builder.apiCallTimeout(Duration.ofSeconds(1))
- .apiCallAttemptTimeout(Duration.ofSeconds(1)))
- .build();
- dynamoAsyncDB2 = DynamoDbAsyncClient.builder()
- .endpointOverride(URI.create("http://localhost:" + port))
- .region(Region.of("local-test-region"))
- .credentialsProvider(StaticCredentialsProvider.create(
- AwsBasicCredentials.create("accessKey", "secretKey")))
- .overrideConfiguration(builder ->
- builder.apiCallTimeout(Duration.ofSeconds(1))
- .apiCallAttemptTimeout(Duration.ofSeconds(1)))
- .build();
+ embedded = DynamoDBEmbedded.create();
+ dynamoDB2 = embedded.dynamoDbClient();
+ dynamoAsyncDB2 = embedded.dynamoDbAsyncClient();
}
public DynamoDbClient getDynamoDbClient() {