From 5afb1a19188b17b0ce3a21d31440552e524d0c06 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:43:17 +0000 Subject: [PATCH 1/4] Bump lib.testcontainers.version from 1.18.3 to 1.19.6 Bumps `lib.testcontainers.version` from 1.18.3 to 1.19.6. Updates `org.testcontainers:redpanda` from 1.18.3 to 1.19.6 - [Release notes](https://github.com/testcontainers/testcontainers-java/releases) - [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md) - [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.18.3...1.19.6) Updates `org.testcontainers:postgresql` from 1.18.3 to 1.19.6 - [Release notes](https://github.com/testcontainers/testcontainers-java/releases) - [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md) - [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.18.3...1.19.6) --- updated-dependencies: - dependency-name: org.testcontainers:redpanda dependency-type: direct:development update-type: version-update:semver-minor - dependency-name: org.testcontainers:postgresql dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f9d4b6ad1..ef3476ea0 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,7 @@ 0.5.2.8 3.2.2 3.25.3 - 1.18.3 + 1.19.6 2.2.0 1.19.0 0.4.1 From 261fbfc429b54bf24ef133214bf9f061d11d3dec Mon Sep 17 00:00:00 2001 From: nscuro Date: Fri, 23 Feb 2024 12:21:41 +0100 Subject: [PATCH 2/4] Allow Kafka Streams more time to start in tests Signed-off-by: nscuro --- .../event/kafka/streams/KafkaStreamsTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/dependencytrack/event/kafka/streams/KafkaStreamsTest.java b/src/test/java/org/dependencytrack/event/kafka/streams/KafkaStreamsTest.java index d869de591..9c773f348 100644 --- a/src/test/java/org/dependencytrack/event/kafka/streams/KafkaStreamsTest.java +++ b/src/test/java/org/dependencytrack/event/kafka/streams/KafkaStreamsTest.java @@ -20,7 +20,8 @@ import java.time.Duration; import java.util.function.Supplier; -import static org.dependencytrack.assertion.Assertions.assertConditionWithTimeout; +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; abstract class KafkaStreamsTest extends PersistenceCapableTest { @@ -75,7 +76,14 @@ public void before() throws Exception { kafkaStreams = new KafkaStreams(topologySupplier.get(), streamsConfig); kafkaStreams.start(); - assertConditionWithTimeout(() -> KafkaStreams.State.RUNNING == kafkaStreams.state(), Duration.ofSeconds(5)); + await("Kafka Streams Readiness") + .atMost(Duration.ofSeconds(15)) + .failFast(() -> assertThat(kafkaStreams.state()).isNotIn( + KafkaStreams.State.ERROR, + KafkaStreams.State.PENDING_ERROR, + KafkaStreams.State.PENDING_SHUTDOWN + )) + .untilAsserted(() -> assertThat(kafkaStreams.state()).isEqualTo(KafkaStreams.State.RUNNING)); } @After From 336bc4f6792defe012c4fae56bbf88fd783a701b Mon Sep 17 00:00:00 2001 From: nscuro Date: Fri, 23 Feb 2024 15:07:25 +0100 Subject: [PATCH 3/4] Use max poll timeout when checking for Kafka records in tests This avoids too frequent re-balances, since the underlying consumer is stopped and re-started for each iteration of the `await` assertion. Signed-off-by: nscuro --- ...fkaStreamsDelayedBomProcessedNotificationTest.java | 10 +++++++--- .../event/kafka/streams/KafkaStreamsTopologyTest.java | 11 ++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/dependencytrack/event/kafka/streams/KafkaStreamsDelayedBomProcessedNotificationTest.java b/src/test/java/org/dependencytrack/event/kafka/streams/KafkaStreamsDelayedBomProcessedNotificationTest.java index 2425564dc..6e57d3a86 100644 --- a/src/test/java/org/dependencytrack/event/kafka/streams/KafkaStreamsDelayedBomProcessedNotificationTest.java +++ b/src/test/java/org/dependencytrack/event/kafka/streams/KafkaStreamsDelayedBomProcessedNotificationTest.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; +import java.util.concurrent.TimeUnit; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -105,7 +106,8 @@ public void shouldSendBomProcessedNotification() throws Exception { assertThat(kafka.readValues(ReadKeyValues .from(KafkaTopics.NOTIFICATION_BOM.name(), String.class, Notification.class) .with(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class) - .with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, NotificationDeserializer.class)) + .with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, NotificationDeserializer.class) + .withMaxTotalPollTime(5, TimeUnit.SECONDS)) ).satisfiesExactly( notification -> { final BomConsumedOrProcessedSubject subject = @@ -132,7 +134,8 @@ public void shouldSendBomProcessedNotification() throws Exception { assertThat(kafka.readValues(ReadKeyValues .from(KafkaTopics.NOTIFICATION_PROJECT_VULN_ANALYSIS_COMPLETE.name(), String.class, Notification.class) .with(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class) - .with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, NotificationDeserializer.class)) + .with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, NotificationDeserializer.class) + .withMaxTotalPollTime(5, TimeUnit.SECONDS)) ).satisfiesExactly( notification -> { final ProjectVulnAnalysisCompleteSubject subject = @@ -203,7 +206,8 @@ public void shouldNotSendBomProcessedNotificationWhenWorkflowHasNoCompletedBomPr assertThat(kafka.readValues(ReadKeyValues .from(KafkaTopics.NOTIFICATION_PROJECT_VULN_ANALYSIS_COMPLETE.name(), String.class, Notification.class) .with(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class) - .with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, NotificationDeserializer.class)) + .with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, NotificationDeserializer.class) + .withMaxTotalPollTime(5, TimeUnit.SECONDS)) ).satisfiesExactly( notification -> { final ProjectVulnAnalysisCompleteSubject subject = diff --git a/src/test/java/org/dependencytrack/event/kafka/streams/KafkaStreamsTopologyTest.java b/src/test/java/org/dependencytrack/event/kafka/streams/KafkaStreamsTopologyTest.java index 2fd7cca2e..6241aae94 100644 --- a/src/test/java/org/dependencytrack/event/kafka/streams/KafkaStreamsTopologyTest.java +++ b/src/test/java/org/dependencytrack/event/kafka/streams/KafkaStreamsTopologyTest.java @@ -50,6 +50,7 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.TimeUnit; import java.util.function.Supplier; import static java.util.stream.Collectors.joining; @@ -241,7 +242,8 @@ public void vulnScanResultProcessingTest() throws Exception { assertThat(kafka.readValues(ReadKeyValues .from(KafkaTopics.NOTIFICATION_PROJECT_VULN_ANALYSIS_COMPLETE.name(), String.class, Notification.class) .with(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class) - .with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, NotificationDeserializer.class)) + .with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, NotificationDeserializer.class) + .withMaxTotalPollTime(5, TimeUnit.SECONDS)) ).satisfiesExactly( notification -> { final ProjectVulnAnalysisCompleteSubject subject = @@ -405,7 +407,8 @@ public void vulnScanFailureTest() throws Exception { assertThat(kafka.readValues(ReadKeyValues .from(KafkaTopics.NOTIFICATION_PROJECT_VULN_ANALYSIS_COMPLETE.name(), String.class, Notification.class) .with(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class) - .with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, NotificationDeserializer.class)) + .with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, NotificationDeserializer.class) + .withMaxTotalPollTime(5, TimeUnit.SECONDS)) ).satisfiesExactly( notification -> { final ProjectVulnAnalysisCompleteSubject subject = @@ -560,8 +563,10 @@ public void projectVulnAnalysisCompleteNotificationFailureTest() throws Exceptio // Verify that no notification was sent. final List notifications = kafka.readValues(ReadKeyValues .from(KafkaTopics.NOTIFICATION_PROJECT_VULN_ANALYSIS_COMPLETE.name(), String.class, Notification.class) + .with(ConsumerConfig.GROUP_ID_CONFIG, "foo") .with(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class) - .with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, NotificationDeserializer.class)); + .with(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, NotificationDeserializer.class) + .withMaxTotalPollTime(5, TimeUnit.SECONDS)); assertThat(notifications).isEmpty(); // Ensure that Kafka Streams did not terminate due to project not existing. From 3733639098a560146d8a93c99306c4d3435a6faf Mon Sep 17 00:00:00 2001 From: nscuro Date: Fri, 23 Feb 2024 15:08:07 +0100 Subject: [PATCH 4/4] Give `ProcessorManager` more time in tests to account for rebalances Signed-off-by: nscuro --- .../event/kafka/processor/api/ProcessorManagerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/dependencytrack/event/kafka/processor/api/ProcessorManagerTest.java b/src/test/java/org/dependencytrack/event/kafka/processor/api/ProcessorManagerTest.java index b5f47449c..139022025 100644 --- a/src/test/java/org/dependencytrack/event/kafka/processor/api/ProcessorManagerTest.java +++ b/src/test/java/org/dependencytrack/event/kafka/processor/api/ProcessorManagerTest.java @@ -128,7 +128,7 @@ public void testSingleRecordProcessorRetry() throws Exception { processorManager.startAll(); await("Record Processing") - .atMost(Duration.ofSeconds(5)) + .atMost(Duration.ofSeconds(15)) .untilAsserted(() -> assertThat(attemptsCounter).hasValue(4)); } }