-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate
MirrorVulnerabilityProcessor
from Kafka Streams to Parallel…
… Consumer Depends on #552 Relates to DependencyTrack/hyades#346 Relates to DependencyTrack/hyades#901 Relates to DependencyTrack/hyades#907 Signed-off-by: nscuro <nscuro@protonmail.com>
- Loading branch information
Showing
6 changed files
with
120 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/test/java/org/dependencytrack/event/kafka/processor/AbstractProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.dependencytrack.event.kafka.processor; | ||
|
||
import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
import org.apache.kafka.common.header.Headers; | ||
import org.apache.kafka.common.header.internals.RecordHeaders; | ||
import org.apache.kafka.common.record.TimestampType; | ||
import org.dependencytrack.AbstractPostgresEnabledTest; | ||
|
||
import java.time.Instant; | ||
import java.util.Optional; | ||
|
||
import static java.util.Objects.requireNonNullElseGet; | ||
|
||
abstract class AbstractProcessorTest extends AbstractPostgresEnabledTest { | ||
|
||
static <K, V> ConsumerRecordBuilder<K, V> aConsumerRecord(final K key, final V value) { | ||
return new ConsumerRecordBuilder<>(key, value); | ||
} | ||
|
||
static final class ConsumerRecordBuilder<K, V> { | ||
|
||
private final K key; | ||
private final V value; | ||
private Instant timestamp; | ||
private Headers headers; | ||
|
||
private ConsumerRecordBuilder(final K key, final V value) { | ||
this.key = key; | ||
this.value = value; | ||
} | ||
|
||
ConsumerRecordBuilder<K, V> withTimestamp(final Instant timestamp) { | ||
this.timestamp = timestamp; | ||
return this; | ||
} | ||
|
||
ConsumerRecordBuilder<K, V> withHeaders(final Headers headers) { | ||
this.headers = headers; | ||
return this; | ||
} | ||
|
||
ConsumerRecord<K, V> build() { | ||
final Instant timestamp = requireNonNullElseGet(this.timestamp, Instant::now); | ||
final Headers headers = requireNonNullElseGet(this.headers, RecordHeaders::new); | ||
return new ConsumerRecord<>( | ||
"topicName", | ||
/* partition */ 0, | ||
/* offset */ 1, | ||
timestamp.toEpochMilli(), TimestampType.CREATE_TIME, | ||
/* serializedKeySize */ -1, | ||
/* serializedValueSize */ -1, | ||
this.key, this.value, | ||
headers, | ||
/* leaderEpoch */ Optional.empty()); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters