-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allows to initialize/inject the Topology object without starting the Kafka streams. #3020
Comments
That is an interesting request. Could you elaborate on the use case that requires it? |
I wonder why do you need The So, we indeed need more info how to proceed. Thanks |
I do not create
The test in general looks like (simplified): @TestPropertySource(properties = {
"spring.kafka.bootstrap-servers=mock://appTopologyTest",
"spring.kafka.streams.application-id=app-test-${random.uuid}",
"spring.kafka.properties.schema.registry.url=mock://appTopologyTest",
"spring.kafka.streams.properties.schema.registry.url=mock://appTopologyTest",
"app.kafka.topic-offer-replicas=1",
"spring.kafka.streams.auto-startup=false",
"spring.kafka.listener.auto-startup=false",
"logging.level.org.springframework.kafka.core.KafkaAdmin=OFF",
"logging.level.io.confluent.kafka.serializers=WARN",
"logging.level.org.apache.kafka.clients.admin=WARN",
})
@SpringBootTest
public class AppTopologyTest {
//There is configuration for input/output topics
@Autowired
private StreamsBuilder streamsBuilder;
@Autowired
private KafkaStreamsConfiguration kafkaStreamsConfiguration;
@Autowired
private KafkaStreamsInfrastructureCustomizer infrastructureCustomizer;
@ParameterizedTest(name = "{0}")
@MethodSource
protected void testProcessing(String info, List<InputNew<?, ?>> input, Matcher<Iterable<TestRecord>> expected, TopicType out) {
//This is a tricky part I need to duplicate logic from
//https://github.com/spring-projects/spring-kafka/blob/main/spring-kafka/src/main/java/org/springframework/kafka/config/StreamsBuilderFactoryBean.java#L347
Topology topology = streamsBuilder.build(kafkaStreamsConfiguration.asProperties());
infrastructureCustomizer.configureTopology(topology);
try (TopologyTestDriver testDriver = new TopologyTestDriver(topology, kafkaStreamsConfiguration.asProperties())) {
Map<TopicType, TestInputTopic<?, ?>> inputTopics = new HashMap(10);
input.forEach(i -> send(testDriver, inputTopics, i));
TestOutputTopic outputTopic = getOutTopic(testDriver, out);
List<TestRecord> output = outputTopic.readRecordsToList();
MatcherAssert.assertThat(output, expected);
}
}
@SuppressWarnings("unused")
private static List<Arguments> testProcessing() {
int i = 1;
return List.of(
testSteps(i++, "Duplicates", OUT, MATCHER_1, IN_MSG_1, IN_MSG_1),
testSteps(i++, "Single ent", OUT, MATCHER_2, IN_MSG_3),
testSteps(i++, "Single another ent", OUT, MATCHER_3, IN_MSG_4),
testSteps(i++, "Comb", OUT, MATCHER_4, IN_MSG_1, IN_MSG_2, IN_MSG_3, IN_MSG_4),
//....
testSteps(i++, "Nothing", OUT, MATCHER_NOTHING));
}
private <K, V> void send(TopologyTestDriver testDriver, Map<TopicType, TestInputTopic<?, ?>> inputTopics, InputNew<?, ?> input) {
TestInputTopic<K, V> topic = getInputTopic(testDriver, inputTopics, input.getTopicType());
topic.pipeInput(new TestRecord(input.getKey(), input.getValue()));
}
@SafeVarargs
protected static Arguments testSteps(int iteration, String description, TopicType out,
MatcherFn matcher, Function<Integer, InputNew>... inputs) {
List<InputNew> parameters = StreamEx.of(inputs).map(input -> input.apply(iteration)).toList();
return Arguments.of(description, parameters, matcher.apply(iteration), out);
}
} |
OK.
out of the If this is a plan, we will be happy to accept such a contribution. Thanks |
Ok. Try to provide PR next week. |
Grr... Can't load the project into Eclipse due to eclipse-jdt/eclipse.jdt.core#1621 Will be fixed in the next release of Eclipse (4.31) - not sure.... |
@artembilan, @sobychacko, @foal If this is on pausing, may i handle this issue? |
Yes, please! |
@foal Thanks a lot 🙇♂️ |
#3172 |
Expected Behavior
Get the Topology from StreamsBuilderFactoryBean without starting the streams engine. Topology have to be created with properties and KafkaStreamsInfrastructureCustomizer and all futures updated if any.
It is necessary to run the tests with Kafka TopologyTestDriver.
Current Behavior
I can inject the StreamsBuilder, but I then I need to create and initialize the topology manually.
Context
Manual work around:
But of course, it aligned with current version of StreamsBuilderFactoryBean only.
The text was updated successfully, but these errors were encountered: