-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to DockerKafkaEnvironment (#440)
... and: * added a public `start()` and `close()` method for when not using with JUnit. * added simple test for `DockerKafkaEnvironment` * removed a deprecated method. * deprecated `SchemaRegistryContainer.withKafka` as its not used, not needed and the `KafkaContainer` parameter is deprecated in the next version of TestContainers. * fix a few warnings. Co-authored-by: Andy Coates <[email protected]>
- Loading branch information
1 parent
b4bf7ec
commit 368807a
Showing
4 changed files
with
114 additions
and
48 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
62 changes: 62 additions & 0 deletions
62
kafka-test/src/test/java/io/specmesh/kafka/DockerKafkaEnvironmentTest.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,62 @@ | ||
/* | ||
* Copyright 2023 SpecMesh Contributors (https://github.com/specmesh) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.specmesh.kafka; | ||
|
||
import java.time.Duration; | ||
import java.util.function.Consumer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class DockerKafkaEnvironmentTest { | ||
|
||
private static final int STARTUP_ATTEMPTS = 1; | ||
private static final Duration STARTUP_DURATION = Duration.ofSeconds(15); | ||
|
||
@Test | ||
void shouldWorkWithoutSasl() { | ||
assertStarts(builder -> {}); | ||
} | ||
|
||
@Test | ||
void shouldWorkWithSasl() { | ||
assertStarts( | ||
builder -> builder.withSaslAuthentication("admin", "admin-secret").withKafkaAcls()); | ||
} | ||
|
||
private void assertStarts(final Consumer<DockerKafkaEnvironment.Builder> customizer) { | ||
final DockerKafkaEnvironment.Builder builder = | ||
DockerKafkaEnvironment.builder() | ||
.withContainerStartUpAttempts(STARTUP_ATTEMPTS) | ||
.withContainerStartUpTimeout(STARTUP_DURATION); | ||
|
||
customizer.accept(builder); | ||
|
||
try (DockerKafkaEnvironment kafkaEnvironment = builder.build()) { | ||
try { | ||
// When: | ||
kafkaEnvironment.start(); | ||
|
||
// Then: did not throw | ||
} catch (Exception e) { | ||
System.out.println("----------Kafka Logs---------------"); | ||
System.out.println(kafkaEnvironment.kafkaLogs()); | ||
System.out.println("----------Schema Registry Logs---------------"); | ||
System.out.println(kafkaEnvironment.schemaRegistryLogs()); | ||
throw e; | ||
} | ||
} | ||
} | ||
} |