Skip to content

Commit

Permalink
Add tests for Apicurio Registry 2.x Avro library
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek committed Apr 21, 2021
1 parent 8f3ef9f commit 10a96e4
Show file tree
Hide file tree
Showing 12 changed files with 680 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/native-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{
"category": "Messaging1",
"timeout": 100,
"test-modules": "kafka kafka-ssl kafka-sasl kafka-avro kafka-snappy kafka-streams reactive-messaging-kafka"
"test-modules": "kafka kafka-ssl kafka-sasl kafka-avro kafka-avro-apicurio2 kafka-snappy kafka-streams reactive-messaging-kafka"
},
{
"category": "Messaging2",
Expand Down
280 changes: 280 additions & 0 deletions integration-tests/kafka-avro-apicurio2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-integration-tests-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-integration-test-kafka-avro-apicurio2</artifactId>
<name>Quarkus - Integration Tests - Kafka Avro with Apicurio 2.x</name>
<description>The Apache Kafka Avro with Apicurio Registry 2.x integration tests module</description>

<!--
- This must be a separate Maven module, because adding Apicurio Registry 2.x
- libraries to the `kafka-avro` module would lead to dependency divergence.
- When we no longer care about Apicurio Registry 1.x, the `kafka-avro`
- module can be deleted, as this module is a copy and hence also includes
- the tests for Confluent schema registry.
-->

<properties>
<apicurio.version>2.0.0.Final</apicurio.version>
</properties>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-integration-test-class-transformer</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-integration-test-shared-library</artifactId>
</dependency>

<!-- JAX-RS -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>

<!-- Kafka -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kafka-client</artifactId>
</dependency>

<!-- Avro -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-avro</artifactId>
</dependency>

<!-- Confluent (Not in Maven Central) -->
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>6.1.1</version>
<exclusions>
<exclusion>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Apicurio -->
<dependency>
<groupId>io.apicurio</groupId>
<artifactId>apicurio-registry-serdes-avro-serde</artifactId>
<version>${apicurio.version}</version>
</dependency>


<!-- test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.strimzi</groupId>
<artifactId>strimzi-test-container</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>

<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-avro-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-integration-test-class-transformer-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kafka-client-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<repositories>
<repository>
<id>confluent</id>
<url>https://packages.confluent.io/maven/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate-code</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>test-kafka</id>
<activation>
<property>
<name>test-containers</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<!-- add some custom config, the rest comes from parent -->
<properties>
<quarkus.native.enable-all-security-services>true</quarkus.native.enable-all-security-services>
</properties>
</profile>
</profiles>

</project>
15 changes: 15 additions & 0 deletions integration-tests/kafka-avro-apicurio2/src/main/avro/pet.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"namespace": "io.quarkus.it.kafka.avro",
"type": "record",
"name": "Pet",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "color",
"type": "string"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package io.quarkus.it.kafka.avro;

import java.time.Duration;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

import io.vertx.core.json.JsonObject;

/**
* Endpoint to test the Avro support
*/
@Path("/avro")
public class AvroEndpoint {

@Inject
AvroKafkaCreator creator;

@GET
@Path("/confluent")
public JsonObject getConfluent() {
return get(creator.createConfluentConsumer("test-avro-confluent-consumer", "test-avro-confluent-consumer"));
}

@POST
@Path("/confluent")
public void sendConfluent(Pet pet) {
KafkaProducer<Integer, Pet> p = creator.createConfluentProducer("test-avro-confluent");
send(p, pet, "test-avro-confluent-producer");
}

@GET
@Path("/apicurio")
public JsonObject getApicurio() {
return get(creator.createApicurioConsumer("test-avro-apicurio-consumer", "test-avro-apicurio-consumer"));
}

@POST
@Path("/apicurio")
public void sendApicurio(Pet pet) {
KafkaProducer<Integer, Pet> p = creator.createApicurioProducer("test-avro-apicurio");
send(p, pet, "test-avro-apicurio-producer");
}

private JsonObject get(KafkaConsumer<Integer, Pet> consumer) {
final ConsumerRecords<Integer, Pet> records = consumer.poll(Duration.ofMillis(60000));
if (records.isEmpty()) {
return null;
}
ConsumerRecord<Integer, Pet> consumerRecord = records.iterator().next();
Pet p = consumerRecord.value();
// We cannot serialize the returned Pet directly, it contains non-serializable object such as the schema.
JsonObject result = new JsonObject();
result.put("name", p.getName());
result.put("color", p.getColor());
return result;
}

private void send(KafkaProducer<Integer, Pet> producer, Pet pet, String topic) {
producer.send(new ProducerRecord<>(topic, 0, pet));
producer.flush();
}
}
Loading

0 comments on commit 10a96e4

Please sign in to comment.