-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make methods running before application start public
- Loading branch information
1 parent
a725afb
commit d40198d
Showing
8 changed files
with
154 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
description = "Utils for testing your Kafka Streams Application" | ||
|
||
dependencies { | ||
api(project(":streams-bootstrap-test")) | ||
api(project(":streams-bootstrap-cli")) | ||
} |
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,3 @@ | ||
# This file is generated by the 'io.freefair.lombok' Gradle plugin | ||
config.stopBubbling = true | ||
lombok.addLombokGeneratedAnnotation = true |
38 changes: 38 additions & 0 deletions
38
...bootstrap-cli-test/src/main/java/com/bakdata/kafka/CapturingUncaughtExceptionHandler.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,38 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2025 bakdata | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.bakdata.kafka; | ||
|
||
import java.lang.Thread.UncaughtExceptionHandler; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CapturingUncaughtExceptionHandler implements UncaughtExceptionHandler { | ||
private Throwable lastException; | ||
|
||
@Override | ||
public void uncaughtException(final Thread t, final Throwable e) { | ||
this.lastException = e; | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
streams-bootstrap-cli-test/src/main/java/com/bakdata/kafka/TestApplicationHelper.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,101 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2025 bakdata | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.bakdata.kafka; | ||
|
||
import com.bakdata.fluent_kafka_streams_tests.TestTopology; | ||
import java.lang.Thread.UncaughtExceptionHandler; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.Delegate; | ||
import picocli.CommandLine; | ||
|
||
@RequiredArgsConstructor | ||
public final class TestApplicationHelper { | ||
|
||
@Delegate | ||
private final @NonNull TestTopologyFactory topologyFactory; | ||
|
||
public static TestApplicationHelper withoutSchemaRegistry() { | ||
return new TestApplicationHelper(TestTopologyFactory.withoutSchemaRegistry()); | ||
} | ||
|
||
public static TestApplicationHelper withSchemaRegistry() { | ||
return new TestApplicationHelper(TestTopologyFactory.withSchemaRegistry()); | ||
} | ||
|
||
public static TestApplicationHelper withSchemaRegistry(final String schemaRegistryUrl) { | ||
return new TestApplicationHelper(TestTopologyFactory.withSchemaRegistry(schemaRegistryUrl)); | ||
} | ||
|
||
public Thread runApplication(final KafkaStreamsApplication<? extends StreamsApp> app) { | ||
this.configure(app); | ||
new CommandLine(app); // initialize all mixins | ||
app.onApplicationStart(); | ||
final Thread thread = new Thread(app); | ||
final UncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler(); | ||
thread.setUncaughtExceptionHandler(handler); | ||
thread.start(); | ||
return thread; | ||
} | ||
|
||
public ConsumerGroupVerifier verify(final KafkaStreamsApplication<? extends StreamsApp> app) { | ||
this.configure(app); | ||
final KafkaEndpointConfig endpointConfig = app.getEndpointConfig(); | ||
final KafkaTestClient testClient = new KafkaTestClient(endpointConfig); | ||
try (final ConfiguredStreamsApp<? extends StreamsApp> configuredApp = app.createConfiguredApp()) { | ||
final String uniqueAppId = configuredApp.getUniqueAppId(); | ||
return new ConsumerGroupVerifier(uniqueAppId, testClient::admin); | ||
} | ||
} | ||
|
||
public ConfiguredStreamsApp<? extends StreamsApp> createConfiguredApp( | ||
final KafkaStreamsApplication<? extends StreamsApp> app) { | ||
this.configure(app); | ||
app.prepareRun(); | ||
return app.createConfiguredApp(); | ||
} | ||
|
||
public <K, V> TestTopology<K, V> createTopology(final KafkaStreamsApplication<? extends StreamsApp> app) { | ||
final ConfiguredStreamsApp<? extends StreamsApp> configuredApp = this.createConfiguredApp(app); | ||
return this.<K, V>createTopology(configuredApp); | ||
} | ||
|
||
public <K, V> TestTopology<K, V> createTopologyExtension(final KafkaStreamsApplication<? extends StreamsApp> app) { | ||
final ConfiguredStreamsApp<? extends StreamsApp> configuredApp = this.createConfiguredApp(app); | ||
return this.<K, V>createTopologyExtension(configuredApp); | ||
} | ||
|
||
public KafkaTestClient newTestClient(final String bootstrapServers) { | ||
return new KafkaTestClient(KafkaEndpointConfig.builder() | ||
.bootstrapServers(bootstrapServers) | ||
.schemaRegistryUrl(this.getSchemaRegistryUrl()) | ||
.build()); | ||
} | ||
|
||
public void configure(final KafkaStreamsApplication<? extends StreamsApp> app) { | ||
app.setSchemaRegistryUrl(this.getSchemaRegistryUrl()); | ||
} | ||
|
||
} |
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