From fbf6b9826e8c35b18e651796e00b7ab045ed0ef7 Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Thu, 3 Nov 2022 09:08:52 -0500 Subject: [PATCH] tests: only call `SQLite.setLibraryPath` once --- .../textsecuregcm/storage/DynamoDbExtension.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 bcf881716..36af6bf1c 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/DynamoDbExtension.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/DynamoDbExtension.java @@ -12,6 +12,7 @@ import java.net.ServerSocket; import java.net.URI; import java.util.ArrayList; import java.util.List; +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; @@ -37,6 +38,8 @@ public class DynamoDbExtension implements BeforeEachCallback, AfterEachCallback .writeCapacityUnits(20L) .build(); + private static final AtomicBoolean libraryLoaded = new AtomicBoolean(); + private DynamoDBProxyServer server; private int port; @@ -77,6 +80,17 @@ public class DynamoDbExtension implements BeforeEachCallback, AfterEachCallback return new DynamoDbExtensionBuilder(); } + private static 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("target/lib"); + } + } + @Override public void afterEach(ExtensionContext context) { stopServer(); @@ -135,7 +149,7 @@ public class DynamoDbExtension implements BeforeEachCallback, AfterEachCallback // Even though we're using AWS SDK v2, Dynamo's local implementation's canonical location // is within v1 (https://github.com/aws/aws-sdk-java-v2/issues/982). This does support // v2 clients, though. - SQLite.setLibraryPath("target/lib"); // if you see a library failed to load error, you need to run mvn test-compile at least once first + loadLibrary(); ServerSocket serverSocket = new ServerSocket(0); serverSocket.setReuseAddress(false); port = serverSocket.getLocalPort();