Skip to content

Commit 6751833

Browse files
authored
Upgrade to the latest Avro dependency (#4990)
* Upgrade the latest Avro dependency * Fix issue in Avro content validator after Avro library upgrade * Fix broken tests after upgrading Avro dep * Code formatting
1 parent 6c8f643 commit 6751833

File tree

11 files changed

+35
-24
lines changed

11 files changed

+35
-24
lines changed

app/src/test/java/io/apicurio/registry/noprofile/ccompat/rest/v7/ConfluentClientTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
import io.confluent.kafka.serializers.protobuf.KafkaProtobufSerializerConfig;
3939
import io.quarkus.test.junit.QuarkusTest;
4040
import io.quarkus.test.junit.TestProfile;
41+
import org.apache.avro.AvroTypeException;
4142
import org.apache.avro.Schema;
42-
import org.apache.avro.SchemaParseException;
4343
import org.apache.avro.generic.GenericData;
4444
import org.apache.kafka.connect.data.SchemaAndValue;
4545
import org.apache.kafka.connect.data.Struct;
@@ -536,8 +536,8 @@ public void testRegisterInvalidSchemaBadType() throws Exception {
536536

537537
try {
538538
new org.apache.avro.Schema.Parser().parse(badSchemaString);
539-
fail("Parsing invalid schema string should fail with SchemaParseException");
540-
} catch (SchemaParseException ignored) {
539+
fail("Parsing invalid schema string should fail with AvroTypeException");
540+
} catch (AvroTypeException ignored) {
541541
}
542542

543543
try {

app/src/test/java/io/apicurio/registry/noprofile/serde/AvroSerdeTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ record = deserializer.deserialize(topic, bytes);
141141
@Test
142142
public void testAvro() throws Exception {
143143
testAvroAutoRegisterIdInBody(RecordIdStrategy.class, () -> {
144-
return restClient.groups().byGroupId("test-group-avro").artifacts().byArtifactId("myrecord3")
144+
return restClient.groups().byGroupId("test_group_avro").artifacts().byArtifactId("myrecord3")
145145
.versions().byVersionExpression("branch=latest").get();
146146
});
147147
}
@@ -150,7 +150,7 @@ public void testAvro() throws Exception {
150150
public void testAvroQualifiedRecordIdStrategy() throws Exception {
151151
testAvroAutoRegisterIdInBody(QualifiedRecordIdStrategy.class, () -> {
152152
return restClient.groups().byGroupId(GroupId.DEFAULT.getRawGroupIdWithDefaultString()).artifacts()
153-
.byArtifactId("test-group-avro.myrecord3").versions().byVersionExpression("branch=latest")
153+
.byArtifactId("test_group_avro.myrecord3").versions().byVersionExpression("branch=latest")
154154
.get();
155155
});
156156
}
@@ -159,7 +159,7 @@ private void testAvroAutoRegisterIdInBody(
159159
Class<? extends ArtifactReferenceResolverStrategy<?, ?>> strategy,
160160
Supplier<VersionMetaData> artifactFinder) throws Exception {
161161
Schema schema = new Schema.Parser().parse(
162-
"{\"type\":\"record\",\"name\":\"myrecord3\",\"namespace\":\"test-group-avro\",\"fields\":[{\"name\":\"bar\",\"type\":\"string\"}]}");
162+
"{\"type\":\"record\",\"name\":\"myrecord3\",\"namespace\":\"test_group_avro\",\"fields\":[{\"name\":\"bar\",\"type\":\"string\"}]}");
163163
try (
164164
AvroKafkaSerializer<GenericData.Record> serializer = new AvroKafkaSerializer<GenericData.Record>(
165165
restClient);

integration-tests/src/test/java/io/apicurio/tests/converters/RegistryConverterIT.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public void cleanArtifacts() throws Exception {
5252

5353
@Test
5454
public void testConfiguration() throws Exception {
55-
String groupId = TestUtils.generateGroupId();
56-
String topic = TestUtils.generateArtifactId();
55+
String groupId = "ns_" + TestUtils.generateGroupId().replace("-", "_");
56+
String topic = "topic-" + TestUtils.generateArtifactId().replace("-", "_");
5757
String recordName = "myrecord4";
5858
AvroGenericRecordSchemaFactory schemaFactory = new AvroGenericRecordSchemaFactory(groupId, recordName,
5959
List.of("bar"));
@@ -108,7 +108,7 @@ public void testAvroIntDefaultValue() throws Exception {
108108
Struct struct = new Struct(sc);
109109
struct.put("int16Test", (short) 3);
110110

111-
String subject = TestUtils.generateArtifactId();
111+
String subject = "subj_" + TestUtils.generateArtifactId().replace("-", "_");
112112

113113
byte[] bytes = converter.fromConnectData(subject, sc, struct);
114114

@@ -153,7 +153,7 @@ public void testAvroBytesDefaultValue() throws Exception {
153153

154154
struct.put("bytesTest", "testingBytes".getBytes());
155155

156-
String subject = TestUtils.generateArtifactId();
156+
String subject = "subj_" + TestUtils.generateArtifactId().replace("-", "_");
157157

158158
byte[] bytes = converter.fromConnectData(subject, sc, struct);
159159

@@ -187,7 +187,7 @@ public void testAvro() throws Exception {
187187
Struct struct = new Struct(sc);
188188
struct.put("bar", "somebar");
189189

190-
String subject = TestUtils.generateArtifactId();
190+
String subject = "subj_" + TestUtils.generateArtifactId().replace("-", "_");
191191

192192
byte[] bytes = converter.fromConnectData(subject, sc, struct);
193193

@@ -242,7 +242,7 @@ public void testConnectStruct() throws Exception {
242242
envelopeStruct.put("ts_ms", 1638362438000L); // Replace with the actual timestamp
243243
envelopeStruct.put("transaction", buildTransactionStruct());
244244

245-
String subject = TestUtils.generateArtifactId();
245+
String subject = "subj_" + TestUtils.generateArtifactId().replace("-", "_");
246246

247247
byte[] bytes = converter.fromConnectData(subject, envelopeSchema, envelopeStruct);
248248

integration-tests/src/test/java/io/apicurio/tests/serdes/apicurio/AvroSerdeIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void evolveSchemaTest(boolean reuseClients) throws Exception {
273273
String topicName = TestUtils.generateTopic();
274274
kafkaCluster.createTopic(topicName, 1, 1);
275275

276-
String recordNamespace = TestUtils.generateGroupId();
276+
String recordNamespace = TestUtils.generateAvroNS();
277277
String recordName = TestUtils.generateSubject();
278278
String schemaKey = "key1";
279279
AvroGenericRecordSchemaFactory avroSchema = new AvroGenericRecordSchemaFactory(recordNamespace,
@@ -683,7 +683,7 @@ void testFirstRequestFailsRateLimited() throws Exception {
683683

684684
mock.start();
685685
try {
686-
String topicName = TestUtils.generateSubject();
686+
String topicName = TestUtils.generateTopic();
687687
kafkaCluster.createTopic(topicName, 1, 1);
688688

689689
AvroGenericRecordSchemaFactory avroSchema = new AvroGenericRecordSchemaFactory("mygroup",

integration-tests/src/test/java/io/apicurio/tests/smokeTests/apicurio/ArtifactsIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void createAndUpdateArtifact() throws Exception {
165165
@Test
166166
void createAndDeleteMultipleArtifacts() throws Exception {
167167
LOGGER.info("Creating some artifacts...");
168-
String groupId = TestUtils.generateGroupId();
168+
String groupId = TestUtils.generateAvroNS();
169169

170170
List<VersionMetaData> artifacts = IntStream.range(0, 10).mapToObj(i -> {
171171
String artifactId = TestUtils.generateSubject();

integration-tests/src/test/java/io/apicurio/tests/smokeTests/confluent/RulesResourceConfluentIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void compatibilityGlobalRules() throws Exception {
3939

4040
ParsedSchema schema = new AvroSchema(first);
4141

42-
String schemeSubject = TestUtils.generateArtifactId();
42+
String schemeSubject = TestUtils.generateSubject();
4343
int schemaId = createArtifactViaConfluentClient(schema, schemeSubject);
4444

4545
confluentService.getSchemaById(schemaId);

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
<jandex.version>3.1.8</jandex.version>
139139

140140
<!-- Schema types -->
141-
<avro.version>1.11.3</avro.version>
141+
<avro.version>1.12.0</avro.version>
142142
<json-schema-validator.version>1.5.1</json-schema-validator.version>
143143
<wire-schema.version>4.9.9</wire-schema.version>
144144
<okhttp.version>4.12.0</okhttp.version>

schema-util/avro/src/main/java/io/apicurio/registry/rules/compatibility/AvroCompatibilityChecker.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.google.common.collect.ImmutableSet;
44
import io.apicurio.registry.content.TypedContent;
55
import io.apicurio.registry.rules.UnprocessableSchemaException;
6-
import org.apache.avro.AvroRuntimeException;
76
import org.apache.avro.Schema;
87
import org.apache.avro.SchemaCompatibility;
98
import org.apache.avro.SchemaCompatibility.Incompatibility;
@@ -43,7 +42,7 @@ protected Set<Incompatibility> isBackwardsCompatibleWith(String existing, String
4342
throw new IllegalStateException(
4443
"Got illegal compatibility result: " + result.getCompatibility());
4544
}
46-
} catch (AvroRuntimeException ex) {
45+
} catch (Exception ex) {
4746
throw new UnprocessableSchemaException(
4847
"Could not execute compatibility rule on invalid Avro schema", ex);
4948
}

schema-util/avro/src/main/java/io/apicurio/registry/rules/validity/AvroContentValidator.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.apicurio.registry.rules.RuleViolationException;
77
import io.apicurio.registry.rules.integrity.IntegrityLevel;
88
import io.apicurio.registry.types.RuleType;
9+
import org.apache.avro.AvroTypeException;
910
import org.apache.avro.Schema;
1011

1112
import java.util.Collections;
@@ -72,15 +73,17 @@ public void validateReferences(TypedContent content, List<ArtifactReference> ref
7273
}
7374
});
7475
parser.parse(content.getContent().content());
75-
} catch (Exception e) {
76-
// This is terrible, but I don't know how else to detect if the reason for the parse failure
76+
} catch (AvroTypeException e) {
77+
// This isn't great, but I don't know how else to detect if the reason for the parse failure
7778
// is because of a missing defined type or some OTHER parse exception.
78-
if (e.getMessage().contains("is not a defined name")) {
79+
if (e.getMessage().startsWith("Undefined schema")) {
7980
RuleViolation violation = new RuleViolation("Missing reference detected.", e.getMessage());
8081
throw new RuleViolationException("Missing reference detected in Avro artifact.",
8182
RuleType.INTEGRITY, IntegrityLevel.ALL_REFS_MAPPED.name(),
8283
Collections.singleton(violation));
8384
}
85+
} catch (Exception e) {
86+
// Ignore other errors
8487
}
8588
}
8689

utils/maven-plugin/src/main/java/io/apicurio/registry/maven/AvroDirectoryParser.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.apicurio.registry.rest.client.RegistryClient;
66
import io.apicurio.registry.rest.client.models.ArtifactReference;
77
import io.apicurio.registry.types.ContentTypes;
8+
import org.apache.avro.AvroTypeException;
89
import org.apache.avro.Schema;
910
import org.apache.avro.SchemaParseException;
1011
import org.slf4j.Logger;
@@ -111,7 +112,7 @@ private ParsedDirectoryWrapper<Schema> parseDirectory(File directory, File rootS
111112
processed.put(schema.getFullName(), schema);
112113
schemaContents.put(schema.getFullName(), typedSchemaContent);
113114
fileParsed = true;
114-
} catch (SchemaParseException ex) {
115+
} catch (SchemaParseException | AvroTypeException ex) {
115116
log.warn(
116117
"Error processing Avro schema with name {}. This usually means that the references are not ready yet to parse it",
117118
typeToAdd.getName());

utils/tests/src/main/java/io/apicurio/registry/utils/tests/TestUtils.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public static String generateTopic() {
254254
}
255255

256256
public static String generateTopic(String prefix) {
257-
return prefix + UUID.randomUUID().toString();
257+
return prefix + UUID.randomUUID().toString().replace("-", "_");
258258
}
259259

260260
public static String generateSubject() {
@@ -269,6 +269,14 @@ public static String generateGroupId() {
269269
return UUID.randomUUID().toString();
270270
}
271271

272+
public static String generateAvroName() {
273+
return "n_" + generateArtifactId().replace("-", "_");
274+
}
275+
276+
public static String generateAvroNS() {
277+
return "ns_" + generateArtifactId().replace("-", "_");
278+
}
279+
272280
public static CreateArtifact clientCreateArtifact(String artifactId, String artifactType, String content,
273281
String contentType) {
274282
CreateArtifact createArtifact = new CreateArtifact();

0 commit comments

Comments
 (0)