Skip to content

Commit

Permalink
AVRO-2284: fix unit test code (#2366)
Browse files Browse the repository at this point in the history
  • Loading branch information
clesaec committed Jul 24, 2023
1 parent c9a5d34 commit 55c3937
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,18 @@ public class TestReadingWritingDataInEvolvedSchemas {
.fields() //
.name(FIELD_A).type().unionOf().stringType().and().bytesType().endUnion().noDefault() //
.endRecord();

private static final Schema ENUM_AB = SchemaBuilder.enumeration("Enum1").symbols("A", "B");

private static final Schema ENUM_AB_RECORD = SchemaBuilder.record(RECORD_A) //
.fields() //
.name(FIELD_A).type().enumeration("Enum1").symbols("A", "B").noDefault() //
.name(FIELD_A).type(ENUM_AB).noDefault() //
.endRecord();

private static final Schema ENUM_ABC = SchemaBuilder.enumeration("Enum1").symbols("A", "B", "C");
private static final Schema ENUM_ABC_RECORD = SchemaBuilder.record(RECORD_A) //
.fields() //
.name(FIELD_A).type().enumeration("Enum1").symbols("A", "B", "C").noDefault() //
.name(FIELD_A).type(ENUM_ABC).noDefault() //
.endRecord();
private static final Schema UNION_INT_RECORD = SchemaBuilder.record(RECORD_A) //
.fields() //
Expand Down Expand Up @@ -310,7 +315,7 @@ public void utf8BytesWrittenWithUnionSchemaIsConvertedToStringSchema() throws Ex
@Test
public void enumRecordCanBeReadWithExtendedEnumSchema() throws Exception {
Schema writer = ENUM_AB_RECORD;
Record record = defaultRecordWithSchema(writer, FIELD_A, new EnumSymbol(writer, "A"));
Record record = defaultRecordWithSchema(writer, FIELD_A, new EnumSymbol(ENUM_AB, "A"));
byte[] encoded = encodeGenericBlob(record);
Record decoded = decodeGenericBlob(ENUM_ABC_RECORD, writer, encoded);
assertEquals("A", decoded.get(FIELD_A).toString());
Expand All @@ -319,7 +324,7 @@ public void enumRecordCanBeReadWithExtendedEnumSchema() throws Exception {
@Test
public void enumRecordWithExtendedSchemaCanBeReadWithOriginalEnumSchemaIfOnlyOldValues() throws Exception {
Schema writer = ENUM_ABC_RECORD;
Record record = defaultRecordWithSchema(writer, FIELD_A, new EnumSymbol(writer, "A"));
Record record = defaultRecordWithSchema(writer, FIELD_A, new EnumSymbol(ENUM_ABC, "A"));
byte[] encoded = encodeGenericBlob(record);
Record decoded = decodeGenericBlob(ENUM_AB_RECORD, writer, encoded);
assertEquals("A", decoded.get(FIELD_A).toString());
Expand All @@ -330,7 +335,7 @@ public void enumRecordWithExtendedSchemaCanNotBeReadIfNewValuesAreUsed() throws
expectedException.expect(AvroTypeException.class);
expectedException.expectMessage("No match for C");
Schema writer = ENUM_ABC_RECORD;
Record record = defaultRecordWithSchema(writer, FIELD_A, new EnumSymbol(writer, "C"));
Record record = defaultRecordWithSchema(writer, FIELD_A, new EnumSymbol(ENUM_ABC, "C"));
byte[] encoded = encodeGenericBlob(record);
decodeGenericBlob(ENUM_AB_RECORD, writer, encoded);
}
Expand Down

0 comments on commit 55c3937

Please sign in to comment.