|
18 | 18 | */ |
19 | 19 | package org.apache.pulsar.broker.service.schema; |
20 | 20 |
|
| 21 | +import static java.nio.charset.StandardCharsets.UTF_8; |
21 | 22 | import com.fasterxml.jackson.core.JsonProcessingException; |
22 | 23 | import com.fasterxml.jackson.databind.ObjectMapper; |
23 | 24 | import com.fasterxml.jackson.module.jsonSchema.JsonSchema; |
@@ -60,6 +61,33 @@ public void testJsonSchemaBackwardsCompatibility() throws JsonProcessingExceptio |
60 | 61 | Assert.assertTrue(jsonSchemaCompatibilityCheck.isCompatible(from, to, SchemaCompatibilityStrategy.FULL)); |
61 | 62 | } |
62 | 63 |
|
| 64 | + @Test |
| 65 | + public void testSchemaWithDollarSignInRecordNameRejectsIncompatibleChange() { |
| 66 | + // Schema v1: has field1 (string) |
| 67 | + String schemaV1 = |
| 68 | + "{\"type\":\"record\",\"name\":\"Outer$Inner\",\"namespace\":\"org.example\"," |
| 69 | + + "\"fields\":[{\"name\":\"field1\",\"type\":\"string\"}]}"; |
| 70 | + // Schema v2: removed field1, added field2 without default — NOT backward compatible |
| 71 | + String schemaV2 = |
| 72 | + "{\"type\":\"record\",\"name\":\"Outer$Inner\",\"namespace\":\"org.example\"," |
| 73 | + + "\"fields\":[{\"name\":\"field2\",\"type\":\"string\"}]}"; |
| 74 | + SchemaData from = SchemaData.builder() |
| 75 | + .data(schemaV1.getBytes(UTF_8)) |
| 76 | + .type(SchemaType.JSON) |
| 77 | + .build(); |
| 78 | + SchemaData to = SchemaData.builder() |
| 79 | + .data(schemaV2.getBytes(UTF_8)) |
| 80 | + .type(SchemaType.JSON) |
| 81 | + .build(); |
| 82 | + JsonSchemaCompatibilityCheck check = new JsonSchemaCompatibilityCheck(); |
| 83 | + // Without the fix, isAvroSchema() rejects '$' and the compatibility check is |
| 84 | + // skipped entirely (falls through to "corrupted, allow overwrite"), so this |
| 85 | + // would incorrectly return true. |
| 86 | + // With the fix, isAvroSchema() recognizes these as valid Avro schemas and the |
| 87 | + // Avro compatibility check correctly detects the incompatibility. |
| 88 | + Assert.assertFalse(check.isCompatible(from, to, SchemaCompatibilityStrategy.BACKWARD)); |
| 89 | + } |
| 90 | + |
63 | 91 | @Data |
64 | 92 | private static class Foo { |
65 | 93 | private String field1; |
|
0 commit comments