-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set Ccompat url as default registry url when Confluent serde is on th…
…e classpath.
- Loading branch information
Showing
11 changed files
with
207 additions
and
147 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
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
11 changes: 11 additions & 0 deletions
11
...s/kafka-avro-apicurio2/src/main/java/io/quarkus/it/kafka/avro/InjectAvroKafkaCreator.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,11 @@ | ||
package io.quarkus.it.kafka.avro; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ ElementType.FIELD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface InjectAvroKafkaCreator { | ||
} |
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
50 changes: 0 additions & 50 deletions
50
...-avro-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaAndSchemaRegistryTestResource.java
This file was deleted.
Oops, something went wrong.
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
86 changes: 7 additions & 79 deletions
86
integration-tests/kafka-avro-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaAvroTest.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 |
---|---|---|
@@ -1,90 +1,18 @@ | ||
package io.quarkus.it.kafka; | ||
|
||
import java.time.Duration; | ||
|
||
import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.apache.kafka.clients.producer.ProducerRecord; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import javax.inject.Inject; | ||
|
||
import io.quarkus.it.kafka.avro.AvroKafkaCreator; | ||
import io.quarkus.it.kafka.avro.Pet; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.RestAssured; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(KafkaAndSchemaRegistryTestResource.class) | ||
public class KafkaAvroTest { | ||
|
||
private static final String CONFLUENT_PATH = "/avro/confluent"; | ||
private static final String APICURIO_PATH = "/avro/apicurio"; | ||
|
||
@Test | ||
public void testConfluentAvroProducer() { | ||
KafkaConsumer<Integer, Pet> consumer = AvroKafkaCreator.createConfluentConsumer( | ||
KafkaAndSchemaRegistryTestResource.getBootstrapServers(), | ||
KafkaAndSchemaRegistryTestResource.getConfluentSchemaRegistryUrl(), | ||
"test-avro-confluent", | ||
"test-avro-confluent-producer"); | ||
testAvroProducer(consumer, CONFLUENT_PATH); | ||
} | ||
public class KafkaAvroTest extends KafkaAvroTestBase { | ||
|
||
@Test | ||
public void testConfluentAvroConsumer() { | ||
KafkaProducer<Integer, Pet> producer = AvroKafkaCreator.createConfluentProducer( | ||
KafkaAndSchemaRegistryTestResource.getBootstrapServers(), | ||
KafkaAndSchemaRegistryTestResource.getConfluentSchemaRegistryUrl(), | ||
"test-avro-confluent-test"); | ||
testAvroConsumer(producer, CONFLUENT_PATH, "test-avro-confluent-consumer"); | ||
} | ||
|
||
@Test | ||
public void testApicurioAvroProducer() { | ||
KafkaConsumer<Integer, Pet> consumer = AvroKafkaCreator.createApicurioConsumer( | ||
KafkaAndSchemaRegistryTestResource.getBootstrapServers(), | ||
KafkaAndSchemaRegistryTestResource.getApicurioSchemaRegistryUrl(), | ||
"test-avro-apicurio", | ||
"test-avro-apicurio-producer"); | ||
testAvroProducer(consumer, APICURIO_PATH); | ||
} | ||
|
||
@Test | ||
public void testApicurioAvroConsumer() { | ||
KafkaProducer<Integer, Pet> producer = AvroKafkaCreator.createApicurioProducer( | ||
KafkaAndSchemaRegistryTestResource.getBootstrapServers(), | ||
KafkaAndSchemaRegistryTestResource.getApicurioSchemaRegistryUrl(), | ||
"test-avro-apicurio-test"); | ||
testAvroConsumer(producer, APICURIO_PATH, "test-avro-apicurio-consumer"); | ||
} | ||
|
||
private void testAvroProducer(KafkaConsumer<Integer, Pet> consumer, String path) { | ||
RestAssured.given() | ||
.header("content-type", "application/json") | ||
.body("{\"name\":\"neo\", \"color\":\"tricolor\"}") | ||
.post(path); | ||
ConsumerRecord<Integer, Pet> records = consumer.poll(Duration.ofMillis(20000)).iterator().next(); | ||
Assertions.assertEquals(records.key(), (Integer) 0); | ||
Pet pet = records.value(); | ||
Assertions.assertEquals("neo", pet.getName()); | ||
Assertions.assertEquals("tricolor", pet.getColor()); | ||
consumer.close(); | ||
} | ||
|
||
private void testAvroConsumer(KafkaProducer<Integer, Pet> producer, String path, String topic) { | ||
producer.send(new ProducerRecord<>(topic, 1, createPet())); | ||
Pet retrieved = RestAssured.when().get(path).as(Pet.class); | ||
Assertions.assertEquals("neo", retrieved.getName()); | ||
Assertions.assertEquals("white", retrieved.getColor()); | ||
producer.close(); | ||
} | ||
@Inject | ||
AvroKafkaCreator creator; | ||
|
||
private Pet createPet() { | ||
Pet pet = new Pet(); | ||
pet.setName("neo"); | ||
pet.setColor("white"); | ||
return pet; | ||
@Override | ||
AvroKafkaCreator creator() { | ||
return creator; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...ation-tests/kafka-avro-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaAvroTestBase.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,83 @@ | ||
package io.quarkus.it.kafka; | ||
|
||
import java.time.Duration; | ||
|
||
import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.apache.kafka.clients.producer.ProducerRecord; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.it.kafka.avro.AvroKafkaCreator; | ||
import io.quarkus.it.kafka.avro.Pet; | ||
import io.restassured.RestAssured; | ||
|
||
public abstract class KafkaAvroTestBase { | ||
|
||
static final String CONFLUENT_PATH = "/avro/confluent"; | ||
static final String APICURIO_PATH = "/avro/apicurio"; | ||
|
||
abstract AvroKafkaCreator creator(); | ||
|
||
@Test | ||
public void testCcompat() { | ||
Assertions.assertTrue(creator().getApicurioRegistryUrl().endsWith("/apis/ccompat/v6")); | ||
} | ||
|
||
@Test | ||
public void testConfluentAvroProducer() { | ||
KafkaConsumer<Integer, Pet> consumer = creator().createConfluentConsumer( | ||
"test-avro-confluent", | ||
"test-avro-confluent-producer"); | ||
testAvroProducer(consumer, CONFLUENT_PATH); | ||
} | ||
|
||
@Test | ||
public void testConfluentAvroConsumer() { | ||
KafkaProducer<Integer, Pet> producer = creator().createConfluentProducer("test-avro-confluent-test"); | ||
testAvroConsumer(producer, CONFLUENT_PATH, "test-avro-confluent-consumer"); | ||
} | ||
|
||
@Test | ||
public void testApicurioAvroProducer() { | ||
KafkaConsumer<Integer, Pet> consumer = creator().createApicurioConsumer( | ||
"test-avro-apicurio", | ||
"test-avro-apicurio-producer"); | ||
testAvroProducer(consumer, APICURIO_PATH); | ||
} | ||
|
||
@Test | ||
public void testApicurioAvroConsumer() { | ||
KafkaProducer<Integer, Pet> producer = creator().createApicurioProducer("test-avro-apicurio-test"); | ||
testAvroConsumer(producer, APICURIO_PATH, "test-avro-apicurio-consumer"); | ||
} | ||
|
||
protected void testAvroProducer(KafkaConsumer<Integer, Pet> consumer, String path) { | ||
RestAssured.given() | ||
.header("content-type", "application/json") | ||
.body("{\"name\":\"neo\", \"color\":\"tricolor\"}") | ||
.post(path); | ||
ConsumerRecord<Integer, Pet> records = consumer.poll(Duration.ofMillis(20000)).iterator().next(); | ||
Assertions.assertEquals(records.key(), (Integer) 0); | ||
Pet pet = records.value(); | ||
Assertions.assertEquals("neo", pet.getName()); | ||
Assertions.assertEquals("tricolor", pet.getColor()); | ||
consumer.close(); | ||
} | ||
|
||
protected void testAvroConsumer(KafkaProducer<Integer, Pet> producer, String path, String topic) { | ||
producer.send(new ProducerRecord<>(topic, 1, createPet())); | ||
Pet retrieved = RestAssured.when().get(path).as(Pet.class); | ||
Assertions.assertEquals("neo", retrieved.getName()); | ||
Assertions.assertEquals("white", retrieved.getColor()); | ||
producer.close(); | ||
} | ||
|
||
private Pet createPet() { | ||
Pet pet = new Pet(); | ||
pet.setName("neo"); | ||
pet.setColor("white"); | ||
return pet; | ||
} | ||
} |
Oops, something went wrong.