diff --git a/extensions-core/avro-extensions/pom.xml b/extensions-core/avro-extensions/pom.xml
index fcabcd7c9da..1c2dddb9902 100644
--- a/extensions-core/avro-extensions/pom.xml
+++ b/extensions-core/avro-extensions/pom.xml
@@ -254,6 +254,11 @@
mockito-core
test
+
+ org.hamcrest
+ hamcrest-core
+ test
+
org.apache.druid
druid-core
diff --git a/extensions-core/avro-extensions/src/main/java/org/apache/druid/data/input/avro/SchemaRegistryBasedAvroBytesDecoder.java b/extensions-core/avro-extensions/src/main/java/org/apache/druid/data/input/avro/SchemaRegistryBasedAvroBytesDecoder.java
index f7006cb02c2..05c5c9fec2f 100644
--- a/extensions-core/avro-extensions/src/main/java/org/apache/druid/data/input/avro/SchemaRegistryBasedAvroBytesDecoder.java
+++ b/extensions-core/avro-extensions/src/main/java/org/apache/druid/data/input/avro/SchemaRegistryBasedAvroBytesDecoder.java
@@ -140,17 +140,17 @@ public class SchemaRegistryBasedAvroBytesDecoder implements AvroBytesDecoder
schema = parsedSchema instanceof AvroSchema ? ((AvroSchema) parsedSchema).rawSchema() : null;
}
catch (IOException | RestClientException ex) {
- throw new ParseException(null, "Failed to get Avro schema: %s", id);
+ throw new ParseException(null, ex, "Failed to fetch Avro schema from registry: %s", id);
}
if (schema == null) {
- throw new ParseException(null, "Failed to find Avro schema: %s", id);
+ throw new ParseException(null, "No Avro schema in registry: %s", id);
}
DatumReader reader = new GenericDatumReader<>(schema);
try {
return reader.read(null, DecoderFactory.get().binaryDecoder(bytes.array(), offset, length, null));
}
catch (Exception e) {
- throw new ParseException(null, e, "Fail to decode Avro message for schema: %s!", id);
+ throw new ParseException(null, e, "Failed to decode Avro message for schema: %s", id);
}
}
diff --git a/extensions-core/avro-extensions/src/test/java/org/apache/druid/data/input/avro/SchemaRegistryBasedAvroBytesDecoderTest.java b/extensions-core/avro-extensions/src/test/java/org/apache/druid/data/input/avro/SchemaRegistryBasedAvroBytesDecoderTest.java
index 9348e9486ae..7644b61bb10 100644
--- a/extensions-core/avro-extensions/src/test/java/org/apache/druid/data/input/avro/SchemaRegistryBasedAvroBytesDecoderTest.java
+++ b/extensions-core/avro-extensions/src/test/java/org/apache/druid/data/input/avro/SchemaRegistryBasedAvroBytesDecoderTest.java
@@ -35,6 +35,8 @@ import org.apache.druid.data.input.SomeAvroDatum;
import org.apache.druid.jackson.DefaultObjectMapper;
import org.apache.druid.java.util.common.parsers.ParseException;
import org.apache.druid.utils.DynamicConfigProviderUtils;
+import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -158,7 +160,7 @@ public class SchemaRegistryBasedAvroBytesDecoderTest
new SchemaRegistryBasedAvroBytesDecoder(registry).parse(bb);
}
- @Test(expected = ParseException.class)
+ @Test
public void testParseWrongId() throws Exception
{
// Given
@@ -166,7 +168,12 @@ public class SchemaRegistryBasedAvroBytesDecoderTest
ByteBuffer bb = ByteBuffer.allocate(5).put((byte) 0).putInt(1234);
bb.rewind();
// When
- new SchemaRegistryBasedAvroBytesDecoder(registry).parse(bb);
+ final ParseException e = Assert.assertThrows(
+ ParseException.class,
+ () -> new SchemaRegistryBasedAvroBytesDecoder(registry).parse(bb)
+ );
+ MatcherAssert.assertThat(e.getCause(), CoreMatchers.instanceOf(IOException.class));
+ MatcherAssert.assertThat(e.getCause().getMessage(), CoreMatchers.containsString("no pasaran"));
}
private byte[] getAvroDatum(Schema schema, GenericRecord someAvroDatum) throws IOException