Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVRO-2284: fix unit test code #2366

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading