Skip to content

Commit 6cd7690

Browse files
committed
feat: DH-22264, DH-22265: add KafkaTools integration test
This adds KafkaTools integration testing via TestContainers. There are four different Kafka images we are testing against: `cp-kafka`, `kafka`, `kafka-native`, and `redpanda`. This includes a test case for DH-22265 / deephaven#7887
1 parent cf130f0 commit 6cd7690

14 files changed

Lines changed: 638 additions & 4 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
id 'io.deephaven.project.register'
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
io.deephaven.project.ProjectType=DOCKER_REGISTRY
2+
# Even though the image is expected to be bumped from latest, we should correlate that with the specific version number
3+
# for easier reference.
4+
# 8.2.0
5+
deephaven.registry.imageName=confluentinc/cp-kafka:latest
6+
deephaven.registry.imageId=confluentinc/cp-kafka@sha256:acbbf674f2ed40e5d0a8ca51beb0f00692c866fc22b5ce06f8cadbdc54cd4436
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
id 'io.deephaven.project.register'
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
io.deephaven.project.ProjectType=DOCKER_REGISTRY
2+
# Even though the image is expected to be bumped from latest, we should correlate that with the specific version number
3+
# for easier reference.
4+
# 4.2.0
5+
deephaven.registry.imageName=apache/kafka-native:latest
6+
deephaven.registry.imageId=apache/kafka-native@sha256:777f2dddec6970003f1f27922a8c317d87140567b0537e801d35669ad9a81faf

docker/registry/kafka/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
id 'io.deephaven.project.register'
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
io.deephaven.project.ProjectType=DOCKER_REGISTRY
2+
# Even though the image is expected to be bumped from latest, we should correlate that with the specific version number
3+
# for easier reference.
4+
# 4.2.0
5+
deephaven.registry.imageName=apache/kafka:latest
6+
deephaven.registry.imageId=apache/kafka@sha256:9516fb7634bad307d17c33b589fde9023003b0cb761374f500002b980a3149b9
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
id 'io.deephaven.project.register'
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
io.deephaven.project.ProjectType=DOCKER_REGISTRY
2+
# Even though the image is expected to be bumped from latest, we should correlate that with the specific version number
3+
# for easier reference.
4+
# v26.1.2
5+
deephaven.registry.imageName=docker.redpanda.com/redpandadata/redpanda:latest
6+
deephaven.registry.imageId=docker.redpanda.com/redpandadata/redpanda@sha256:65a7a93449f113a2941e0e8a9cd7eb1ed3ba153547b6b2b47f11796e9f754345

extensions/kafka/build.gradle

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ plugins {
33
id 'io.deephaven.project.register'
44
}
55

6+
evaluationDependsOn Docker.registryProject('cp-kafka')
7+
evaluationDependsOn Docker.registryProject('kafka')
8+
evaluationDependsOn Docker.registryProject('kafka-native')
9+
evaluationDependsOn Docker.registryProject('redpanda')
10+
611
description 'Kafka: Integrating Engine tables with Kafka'
712

813
dependencies {
@@ -40,8 +45,17 @@ dependencies {
4045
compileOnly project(':util-immutables')
4146
annotationProcessor libs.immutables.value
4247

48+
testImplementation libs.testcontainers
49+
testImplementation libs.testcontainers.kafka
50+
testImplementation libs.testcontainers.redpanda
51+
52+
testImplementation project(':engine-test-utils')
53+
54+
testImplementation project(':extensions-json-jackson')
55+
4356
testImplementation platform(libs.junit.bom)
4457
testImplementation libs.junit.jupiter
58+
testImplementation libs.junit.jupiter.params
4559
testRuntimeOnly libs.junit.jupiter.engine
4660
testRuntimeOnly libs.junit.platform.launcher
4761

@@ -54,5 +68,28 @@ dependencies {
5468
}
5569

5670
test {
57-
useJUnitPlatform()
71+
useJUnitPlatform {
72+
excludeTags("testcontainers")
73+
}
74+
}
75+
76+
tasks.register('testOutOfBand', Test) {
77+
useJUnitPlatform {
78+
includeTags("testcontainers")
79+
}
80+
81+
dependsOn Docker.registryTask(project, 'cp-kafka')
82+
systemProperty 'testcontainers.cp-kafka.image', Docker.localImageName('cp-kafka')
83+
84+
dependsOn Docker.registryTask(project, 'kafka')
85+
systemProperty 'testcontainers.kafka.image', Docker.localImageName('kafka')
86+
87+
dependsOn Docker.registryTask(project, 'kafka-native')
88+
systemProperty 'testcontainers.kafka-native.image', Docker.localImageName('kafka-native')
89+
90+
dependsOn Docker.registryTask(project, 'redpanda')
91+
systemProperty 'testcontainers.redpanda.image', Docker.localImageName('redpanda')
92+
93+
// Kafka client logging is very verbose; tune it down to only log warn or more severe
94+
systemProperty 'org.slf4j.simpleLogger.log.org.apache.kafka', 'warn'
5895
}

extensions/kafka/src/main/java/io/deephaven/kafka/KafkaTools.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
import org.immutables.value.Value.Parameter;
114114
import org.jetbrains.annotations.NotNull;
115115
import org.jetbrains.annotations.Nullable;
116+
import org.jetbrains.annotations.VisibleForTesting;
116117

117118
import java.util.ArrayList;
118119
import java.util.Arrays;
@@ -1034,7 +1035,20 @@ public static Table consumeToTable(
10341035
@NotNull final Consume.KeyOrValueSpec keySpec,
10351036
@NotNull final Consume.KeyOrValueSpec valueSpec,
10361037
@NotNull final TableType tableType) {
1037-
final MutableObject<Table> resultHolder = new MutableObject<>();
1038+
return consumeToTableAndAdapter(kafkaProperties, topic, partitionFilter, partitionToInitialOffset, keySpec,
1039+
valueSpec, tableType).table();
1040+
}
1041+
1042+
@VisibleForTesting
1043+
static TableAndAdapter consumeToTableAndAdapter(
1044+
@NotNull final Properties kafkaProperties,
1045+
@NotNull final String topic,
1046+
@NotNull final IntPredicate partitionFilter,
1047+
@NotNull final IntToLongFunction partitionToInitialOffset,
1048+
@NotNull final Consume.KeyOrValueSpec keySpec,
1049+
@NotNull final Consume.KeyOrValueSpec valueSpec,
1050+
@NotNull final TableType tableType) {
1051+
final MutableObject<TableAndAdapter> resultHolder = new MutableObject<>();
10381052
final ExecutionContext enclosingExecutionContext = ExecutionContext.getContext();
10391053
final LivenessManager enclosingLivenessManager = LivenessScopeStack.peek();
10401054

@@ -1052,14 +1066,35 @@ public static Table consumeToTable(
10521066
final Table blinkTable = streamToBlinkTableAdapter.table();
10531067
final Table result = tableType.walk(new BlinkTableOperation(blinkTable));
10541068
enclosingLivenessManager.manage(result);
1055-
resultHolder.setValue(result);
1069+
// Note: not adding streamToBlinkTableAdapter to liveness manager; liveness is expected to be
1070+
// retained through the result table. This is only relevant for testing.
1071+
resultHolder.setValue(new TableAndAdapter(result, streamToBlinkTableAdapter));
10561072
}
10571073
};
10581074

10591075
consume(kafkaProperties, topic, partitionFilter,
10601076
InitialOffsetLookup.adapt(partitionToInitialOffset), keySpec, valueSpec,
10611077
StreamConsumerRegistrarProvider.single(registrar), null);
1062-
return resultHolder.getValue();
1078+
return resultHolder.get();
1079+
}
1080+
1081+
@VisibleForTesting
1082+
static class TableAndAdapter {
1083+
private final Table table;
1084+
private final StreamToBlinkTableAdapter adapter;
1085+
1086+
private TableAndAdapter(Table table, StreamToBlinkTableAdapter adapter) {
1087+
this.table = Objects.requireNonNull(table);
1088+
this.adapter = Objects.requireNonNull(adapter);
1089+
}
1090+
1091+
public Table table() {
1092+
return table;
1093+
}
1094+
1095+
public StreamToBlinkTableAdapter adapter() {
1096+
return adapter;
1097+
}
10631098
}
10641099

10651100
/**

0 commit comments

Comments
 (0)