This is an automated email from the ASF dual-hosted git repository. opwvhk pushed a commit to branch branch-1.12 in repository https://gitbox.apache.org/repos/asf/avro.git
commit 1f3cc1fbd5ea7eb7fc7d19b62c84405f34ba28b9 Author: Oscar Westra van Holthe - Kind <[email protected]> AuthorDate: Fri Jun 13 12:11:21 2025 +0200 Fix tests --- .../org/apache/avro/generic/PrimitivesArrays.java | 12 ++++++------ .../avro/TestReadingWritingDataInEvolvedSchemas.java | 19 +++++++++---------- .../avro/TestSchemaCompatibilityEnumDefaults.java | 3 ++- .../src/test/java/org/apache/avro/TestUnionError.java | 3 ++- lang/java/idl/src/test/idl/output/simple.avpr | 4 ++-- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lang/java/avro/src/main/java/org/apache/avro/generic/PrimitivesArrays.java b/lang/java/avro/src/main/java/org/apache/avro/generic/PrimitivesArrays.java index 6107ad382d..d23d46ae9e 100644 --- a/lang/java/avro/src/main/java/org/apache/avro/generic/PrimitivesArrays.java +++ b/lang/java/avro/src/main/java/org/apache/avro/generic/PrimitivesArrays.java @@ -97,7 +97,7 @@ public class PrimitivesArrays { /** * Direct primitive int access. - * + * * @param i : index. * @return value at index. */ @@ -204,7 +204,7 @@ public class PrimitivesArrays { /** * Direct primitive int access. - * + * * @param i : index. * @return value at index. */ @@ -318,7 +318,7 @@ public class PrimitivesArrays { /** * Direct primitive int access. - * + * * @param i : index. * @return value at index. */ @@ -479,7 +479,7 @@ public class PrimitivesArrays { /** * Direct primitive int access. - * + * * @param i : index. * @return value at index. */ @@ -586,7 +586,7 @@ public class PrimitivesArrays { /** * Direct primitive int access. - * + * * @param i : index. * @return value at index. */ @@ -601,7 +601,7 @@ public class PrimitivesArrays { if (o == null) { return; } - this.add(location, o.floatValue()); + this.add(location, o.doubleValue()); } public void add(int location, double o) { diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestReadingWritingDataInEvolvedSchemas.java b/lang/java/avro/src/test/java/org/apache/avro/TestReadingWritingDataInEvolvedSchemas.java index 89fedc75ca..492371e3af 100644 --- a/lang/java/avro/src/test/java/org/apache/avro/TestReadingWritingDataInEvolvedSchemas.java +++ b/lang/java/avro/src/test/java/org/apache/avro/TestReadingWritingDataInEvolvedSchemas.java @@ -17,17 +17,14 @@ */ package org.apache.avro; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collection; -import java.util.stream.Stream; import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericData.EnumSymbol; @@ -234,7 +231,7 @@ public class TestReadingWritingDataInEvolvedSchemas { byte[] encoded = encodeGenericBlob(record, encoderType); AvroTypeException exception = Assertions.assertThrows(AvroTypeException.class, () -> decodeGenericBlob(FLOAT_RECORD, writer, encoded, encoderType)); - Assertions.assertEquals("Found double, expecting float", exception.getMessage()); + Assertions.assertEquals("Field \"fieldA\" content mismatch: Found double, expecting float", exception.getMessage()); } @ParameterizedTest @@ -245,7 +242,7 @@ public class TestReadingWritingDataInEvolvedSchemas { byte[] encoded = encodeGenericBlob(record, encoderType); AvroTypeException exception = Assertions.assertThrows(AvroTypeException.class, () -> decodeGenericBlob(LONG_RECORD, writer, encoded, encoderType)); - Assertions.assertEquals("Found float, expecting long", exception.getMessage()); + Assertions.assertEquals("Field \"fieldA\" content mismatch: Found float, expecting long", exception.getMessage()); } @ParameterizedTest @@ -256,7 +253,7 @@ public class TestReadingWritingDataInEvolvedSchemas { byte[] encoded = encodeGenericBlob(record, encoderType); AvroTypeException exception = Assertions.assertThrows(AvroTypeException.class, () -> decodeGenericBlob(INT_RECORD, writer, encoded, encoderType)); - Assertions.assertEquals("Found long, expecting int", exception.getMessage()); + Assertions.assertEquals("Field \"fieldA\" content mismatch: Found long, expecting int", exception.getMessage()); } @ParameterizedTest @@ -344,7 +341,7 @@ public class TestReadingWritingDataInEvolvedSchemas { AvroTypeException exception = Assertions.assertThrows(AvroTypeException.class, () -> decodeGenericBlob(ENUM_AB_RECORD, writer, encoded, encoderType)); - Assertions.assertEquals("No match for C", exception.getMessage()); + Assertions.assertEquals("Field \"fieldA\" content mismatch: No match for C", exception.getMessage()); } @ParameterizedTest @@ -438,7 +435,9 @@ public class TestReadingWritingDataInEvolvedSchemas { if (blob == null) { return null; } - GenericDatumReader<Record> reader = new GenericDatumReader<>(); + GenericData model = GenericData.get(); + model.setFastReaderEnabled(false); + GenericDatumReader<Record> reader = new GenericDatumReader<>(null, null, model); reader.setExpected(expectedSchema); reader.setSchema(schemaOfBlob); Decoder decoder = encoderType == EncoderType.BINARY ? DecoderFactory.get().binaryDecoder(blob, null) diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityEnumDefaults.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityEnumDefaults.java index 82ec27d01b..3bc5cdb531 100644 --- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityEnumDefaults.java +++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityEnumDefaults.java @@ -127,7 +127,8 @@ public class TestSchemaCompatibilityEnumDefaults { byte[] bytes = baos.toByteArray(); Decoder decoder = DecoderFactory.get().resolvingDecoder(writerSchema, readerSchema, DecoderFactory.get().binaryDecoder(bytes, null)); - DatumReader<Object> datumReader = new GenericDatumReader<>(readerSchema); + GenericData model = GenericData.get().setFastReaderEnabled(false); + DatumReader<Object> datumReader = new GenericDatumReader<>(readerSchema, readerSchema, model); return (GenericRecord) datumReader.read(null, decoder); } diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestUnionError.java b/lang/java/avro/src/test/java/org/apache/avro/TestUnionError.java index 9d398d635f..414b2ad99d 100644 --- a/lang/java/avro/src/test/java/org/apache/avro/TestUnionError.java +++ b/lang/java/avro/src/test/java/org/apache/avro/TestUnionError.java @@ -77,7 +77,8 @@ public class TestUnionError { InputStream ins = new ByteArrayInputStream(outs.toByteArray()); BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(ins, null); - GenericDatumReader<GenericRecord> datumReader = new GenericDatumReader<>(writerSchema, readerSchema); + GenericData model = GenericData.get().setFastReaderEnabled(false); + GenericDatumReader<GenericRecord> datumReader = new GenericDatumReader<>(writerSchema, readerSchema, model); AvroTypeException avroException = assertThrows(AvroTypeException.class, () -> datumReader.read(null, decoder)); assertEquals("Field \"c\" content mismatch: Found B, expecting union[A, float]", avroException.getMessage()); } diff --git a/lang/java/idl/src/test/idl/output/simple.avpr b/lang/java/idl/src/test/idl/output/simple.avpr index edcb68536e..004e32480d 100644 --- a/lang/java/idl/src/test/idl/output/simple.avpr +++ b/lang/java/idl/src/test/idl/output/simple.avpr @@ -80,11 +80,11 @@ "default": null }, { "name": "numbers", - "type": {"type: array", "items": "int"}, + "type": {"type": "array", "items": "int"}, "default": [] }, { "name": "dictionary", - "type": {"type: map", "items": "string"}, + "type": {"type": "map", "values": "string"}, "default": {} }], "my-property" : {
