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

Enable reWriteBatchedInserts Postgres JDBC driver option in tests #917

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

import alpine.Config;
import alpine.common.logging.Logger;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.NewTopic;
import org.dependencytrack.event.kafka.KafkaTopics;

import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -92,6 +92,7 @@ public void contextInitialized(final ServletContextEvent event) {
final Class<?> postgresContainerClass = Class.forName("org.testcontainers.containers.PostgreSQLContainer");
final Constructor<?> postgresContainerConstructor = postgresContainerClass.getDeclaredConstructor(String.class);
postgresContainer = (AutoCloseable) postgresContainerConstructor.newInstance(getProperty(DEV_SERVICES_IMAGE_POSTGRES));
postgresContainerClass.getMethod("withUrlParam", String.class, String.class).invoke(postgresContainer, "reWriteBatchedInserts", "true");

// TODO: Detect when Apache Kafka is requested vs. when Kafka is requested,
// and pick the corresponding Testcontainers class accordingly.
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ alpine.database.mode=external
alpine.database.port=9092

# Specifies the JDBC URL to use when connecting to the database.
# For best performance, set the `reWriteBatchedInserts` query parameter to `true`.
#
# @category: Database
# @example: jdbc:postgresql://localhost:5432/dtrack
# @example: jdbc:postgresql://localhost:5432/dtrack?reWriteBatchedInserts=true
# @type: string
# @required
alpine.database.url=
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/org/dependencytrack/PostgresTestContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public PostgresTestContainer() {
withPassword("dtrack");
withDatabaseName("dtrack");
withLabel("owner", "hyades-apiserver");
withUrlParam("reWriteBatchedInserts", "true");

// Uncomment this to see queries executed by Postgres:
// withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(PostgresTestContainer.class)));
// withCommand("-c log_statement=all");

// NB: Container reuse won't be active unless either:
// - The environment variable TESTCONTAINERS_REUSE_ENABLE=true is set
Expand Down
Loading