Skip to content

Commit

Permalink
Enable reWriteBatchedInserts Postgres JDBC driver option in tests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nscuro authored Sep 20, 2024
1 parent 8b43f77 commit 132bc02
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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

0 comments on commit 132bc02

Please sign in to comment.