tests: only call `SQLite.setLibraryPath` once
This commit is contained in:
parent
a01b29a6bd
commit
fbf6b9826e
|
@ -12,6 +12,7 @@ import java.net.ServerSocket;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import org.junit.jupiter.api.extension.AfterEachCallback;
|
import org.junit.jupiter.api.extension.AfterEachCallback;
|
||||||
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
|
@ -37,6 +38,8 @@ public class DynamoDbExtension implements BeforeEachCallback, AfterEachCallback
|
||||||
.writeCapacityUnits(20L)
|
.writeCapacityUnits(20L)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
private static final AtomicBoolean libraryLoaded = new AtomicBoolean();
|
||||||
|
|
||||||
private DynamoDBProxyServer server;
|
private DynamoDBProxyServer server;
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
|
@ -77,6 +80,17 @@ public class DynamoDbExtension implements BeforeEachCallback, AfterEachCallback
|
||||||
return new DynamoDbExtensionBuilder();
|
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
|
@Override
|
||||||
public void afterEach(ExtensionContext context) {
|
public void afterEach(ExtensionContext context) {
|
||||||
stopServer();
|
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
|
// 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
|
// is within v1 (https://github.com/aws/aws-sdk-java-v2/issues/982). This does support
|
||||||
// v2 clients, though.
|
// 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 serverSocket = new ServerSocket(0);
|
||||||
serverSocket.setReuseAddress(false);
|
serverSocket.setReuseAddress(false);
|
||||||
port = serverSocket.getLocalPort();
|
port = serverSocket.getLocalPort();
|
||||||
|
|
Loading…
Reference in New Issue