forked from debezium/debezium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DBZ-3369 Add Schema Registry Lifecycle Manager to test Protobuf conve…
…rters
- Loading branch information
Showing
8 changed files
with
201 additions
and
3 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
20 changes: 20 additions & 0 deletions
20
...ium-server-core/src/test/java/io/debezium/server/DebeziumServerSchemaRegistryProfile.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,20 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.debezium.server; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import io.debezium.testing.testcontainers.SchemaRegistryTestResourceLifecycleManager; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
|
||
public class DebeziumServerSchemaRegistryProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public List<TestResourceEntry> testResources() { | ||
return Collections.singletonList(new TestResourceEntry(SchemaRegistryTestResourceLifecycleManager.class)); | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...zium-server-core/src/test/java/io/debezium/server/DebeziumServerWithSchemaRegistryIT.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,65 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.debezium.server; | ||
|
||
import java.time.Duration; | ||
|
||
import javax.enterprise.event.Observes; | ||
import javax.inject.Inject; | ||
|
||
import org.awaitility.Awaitility; | ||
import org.fest.assertions.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; | ||
|
||
import io.debezium.server.events.ConnectorCompletedEvent; | ||
import io.debezium.server.events.ConnectorStartedEvent; | ||
import io.debezium.testing.testcontainers.PostgresTestResourceLifecycleManager; | ||
import io.debezium.util.Testing; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(PostgresTestResourceLifecycleManager.class) | ||
@TestProfile(DebeziumServerSchemaRegistryProfile.class) | ||
@EnabledIfSystemProperty(named = "debezium.format.key", matches = "protobuf") | ||
@EnabledIfSystemProperty(named = "debezium.format.value", matches = "protobuf") | ||
public class DebeziumServerWithSchemaRegistryIT { | ||
|
||
private static final int MESSAGE_COUNT = 4; | ||
@Inject | ||
DebeziumServer server; | ||
|
||
{ | ||
Testing.Files.delete(TestConfigSource.OFFSET_STORE_PATH); | ||
} | ||
|
||
void setupDependencies(@Observes ConnectorStartedEvent event) { | ||
if (!TestConfigSource.isItTest()) { | ||
return; | ||
} | ||
|
||
} | ||
|
||
void connectorCompleted(@Observes ConnectorCompletedEvent event) throws Exception { | ||
if (!event.isSuccess()) { | ||
throw (Exception) event.getError().get(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testPostgresWithProtobuf() throws Exception { | ||
Testing.Print.enable(); | ||
final TestConsumer testConsumer = (TestConsumer) server.getConsumer(); | ||
Awaitility.await().atMost(Duration.ofSeconds(TestConfigSource.waitForSeconds())) | ||
.until(() -> (testConsumer.getValues().size() >= MESSAGE_COUNT)); | ||
Assertions.assertThat(testConsumer.getValues().size()).isEqualTo(MESSAGE_COUNT); | ||
Assertions.assertThat(testConsumer.getValues().get(0)).isInstanceOf(byte[].class); | ||
Assertions.assertThat(testConsumer.getValues().get(0)).isNotNull(); | ||
Assertions.assertThat(testConsumer.getValues().get(0).equals(0)); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
...tcontainers/src/main/java/io/debezium/testing/testcontainers/SchemaRegistryContainer.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,35 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.debezium.testing.testcontainers; | ||
|
||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.KafkaContainer; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
public class SchemaRegistryContainer extends GenericContainer<SchemaRegistryContainer> { | ||
|
||
private static final String SCHEMA_REGISTRY_DOCKER_IMAGE_NAME = "confluentinc/cp-schema-registry:6.0.2"; | ||
private static final DockerImageName SCHEMA_REGISTRY_DOCKER_IMAGE = DockerImageName.parse(SCHEMA_REGISTRY_DOCKER_IMAGE_NAME); | ||
private static final Integer SCHEMA_REGISTRY_EXPOSED_PORT = 8081; | ||
|
||
SchemaRegistryContainer() { | ||
super(SCHEMA_REGISTRY_DOCKER_IMAGE); | ||
addExposedPorts(SCHEMA_REGISTRY_EXPOSED_PORT); | ||
} | ||
|
||
public SchemaRegistryContainer withKafka(KafkaContainer kafkaContainer) { | ||
return withKafka(kafkaContainer.getNetwork(), kafkaContainer.getNetworkAliases().get(0) + ":9092"); | ||
} | ||
|
||
public SchemaRegistryContainer withKafka(Network network, String bootstrapServers) { | ||
withNetwork(network); | ||
withEnv("SCHEMA_REGISTRY_HOST_NAME", "schema-registry"); | ||
withEnv("SCHEMA_REGISTRY_LISTENERS", "http://0.0.0.0:8081"); | ||
withEnv("SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS", "PLAINTEXT://" + bootstrapServers); | ||
return self(); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...n/java/io/debezium/testing/testcontainers/SchemaRegistryTestResourceLifecycleManager.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,64 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.debezium.testing.testcontainers; | ||
|
||
import java.time.Duration; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.stream.Stream; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.KafkaContainer; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.lifecycle.Startables; | ||
|
||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
|
||
public class SchemaRegistryTestResourceLifecycleManager implements QuarkusTestResourceLifecycleManager { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(SchemaRegistryTestResourceLifecycleManager.class); | ||
|
||
private static final Network network = Network.newNetwork(); | ||
private static final Integer PORT = 8081; | ||
|
||
public static KafkaContainer kafkaContainer = new KafkaContainer() | ||
.withNetwork(network); | ||
|
||
private static final SchemaRegistryContainer schemaRegistryContainer = new SchemaRegistryContainer() | ||
.withNetwork(network) | ||
.withKafka(kafkaContainer) | ||
.withLogConsumer(new Slf4jLogConsumer(LOGGER)) | ||
.dependsOn(kafkaContainer) | ||
.withStartupTimeout(Duration.ofSeconds(90)); | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
Startables.deepStart(Stream.of(kafkaContainer, schemaRegistryContainer)).join(); | ||
|
||
Map<String, String> params = new ConcurrentHashMap<>(); | ||
params.put("debezium.format.schema.registry.url", getSchemaRegistryUrl()); | ||
|
||
return params; | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
try { | ||
if (schemaRegistryContainer != null) { | ||
schemaRegistryContainer.stop(); | ||
} | ||
} | ||
catch (Exception e) { | ||
// ignored | ||
} | ||
} | ||
|
||
private static String getSchemaRegistryUrl() { | ||
return "http://" + schemaRegistryContainer.getHost() + ":" + schemaRegistryContainer.getMappedPort(PORT); | ||
} | ||
} |