Skip to content

Commit

Permalink
Apicurio#3613 fix Serialization error with reflective enum and qualif…
Browse files Browse the repository at this point in the history
…iedREcor… (Apicurio#3616)

* Apicurio#3613 fix Serialization error with reflective enum and qualifiedREcordIdStrategy

* Apicurio#3613 switch to class parameter in test
  • Loading branch information
sunmeplz authored Aug 30, 2023
1 parent 2755e83 commit a8d4614
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
5 changes: 5 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.nio.ByteBuffer;
import java.util.Arrays;
Expand Down Expand Up @@ -399,15 +401,24 @@ public void testAvroUsingHeaders() throws Exception {
}
}

@Test
public void testAvroReflect() throws Exception {
@ParameterizedTest
@ValueSource(
classes = {
io.apicurio.registry.serde.strategy.TopicIdStrategy.class,
io.apicurio.registry.serde.avro.strategy.QualifiedRecordIdStrategy.class,
io.apicurio.registry.serde.avro.strategy.RecordIdStrategy.class,
io.apicurio.registry.serde.avro.strategy.TopicRecordIdStrategy.class
}
)
public void testAvroReflect(Class<?> artifactResolverStrategyClass) throws Exception {
try (AvroKafkaSerializer<Tester> serializer = new AvroKafkaSerializer<Tester>(restClient);
AvroKafkaDeserializer<Tester> deserializer = new AvroKafkaDeserializer<Tester>(restClient)) {

Map<String, String> config = new HashMap<>();
config.put(SerdeConfig.AUTO_REGISTER_ARTIFACT, "true");
config.put(SerdeConfig.ENABLE_HEADERS, "false");
config.put(AvroKafkaSerdeConfig.AVRO_DATUM_PROVIDER, ReflectAvroDatumProvider.class.getName());
config.put(SchemaResolverConfig.ARTIFACT_RESOLVER_STRATEGY, artifactResolverStrategyClass.getName());
serializer.configure(config, false);

config = new HashMap<>();
Expand All @@ -416,7 +427,7 @@ public void testAvroReflect() throws Exception {

String artifactId = generateArtifactId();

Tester tester = new Tester("Apicurio");
Tester tester = new Tester("Apicurio", Tester.TesterState.ONLINE);
byte[] bytes = serializer.serialize(artifactId, tester);

waitForSchema(globalId -> restClient.getContentByGlobalId(globalId) != null, bytes);
Expand Down
29 changes: 19 additions & 10 deletions app/src/test/java/io/apicurio/registry/support/Tester.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
public class Tester {

private String name;
private TesterState state;

public Tester() {
}

public Tester(String name) {
public Tester(String name, TesterState state) {
this.name = name;
this.state = state;
}

public String getName() {
return name;
}
Expand All @@ -40,20 +41,28 @@ public void setName(String name) {
this.name = name;
}

public TesterState getState() {
return state;
}

public void setState(TesterState state) {
this.state = state;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Tester tester = (Tester) o;
return name.equals(tester.name);
return Objects.equals(name, tester.name) && state == tester.state;
}

@Override
public int hashCode() {
return Objects.hash(name);
return Objects.hash(name, state);
}

public enum TesterState {
ONLINE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class QualifiedRecordIdStrategy implements ArtifactReferenceResolverStrat
*/
@Override
public io.apicurio.registry.resolver.strategy.ArtifactReference artifactReference(Record<Object> data, ParsedSchema<Schema> parsedSchema) {
if (parsedSchema != null && parsedSchema.getParsedSchema() != null && parsedSchema.getParsedSchema().getType() == Schema.Type.RECORD) {
if (parsedSchema != null && parsedSchema.getParsedSchema() != null && (parsedSchema.getParsedSchema().getType() == Schema.Type.RECORD || parsedSchema.getParsedSchema().getType() == Schema.Type.ENUM)) {
return ArtifactReference.builder()
.groupId(null)
.artifactId(parsedSchema.getParsedSchema().getFullName())
Expand Down

0 comments on commit a8d4614

Please sign in to comment.