This is an automated email from the ASF dual-hosted git repository.

lhotari pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit e169f8d3e8cc0a0355ef9edaba5988219e296b1c
Author: Lucas Eby <[email protected]>
AuthorDate: Mon Oct 27 10:17:18 2025 -0500

    [fix][test] Made ProtobufSchemaTest.testParsingInfoProperty 
order-independent (#24807)
    
    (cherry picked from commit 2dc4dcb07ae2115aed3e9b36f327f2e46c04551a)
---
 .../client/impl/schema/ProtobufSchemaTest.java     | 49 +++++++++++++++++++++-
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git 
a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/ProtobufSchemaTest.java
 
b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/ProtobufSchemaTest.java
index 2544fcd136b..5acdd5b1b1c 100644
--- 
a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/ProtobufSchemaTest.java
+++ 
b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/ProtobufSchemaTest.java
@@ -19,11 +19,19 @@
 package org.apache.pulsar.client.impl.schema;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufAllocator;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.avro.Schema;
 import org.apache.pulsar.common.schema.SchemaType;
@@ -68,6 +76,38 @@ public class ProtobufSchemaTest {
             + 
"\"externalMessage\\\",\\\"type\\\":\\\"MESSAGE\\\",\\\"label\\\":\\\"LABEL_OPTIONAL\\\",\\\"definition"
             + "\\\":null}]\"}";
 
+    private static final ObjectMapper MAPPER = new ObjectMapper();
+
+    private static ObjectNode normalizeAllProps(Map<String, String> props, 
String specialKey)
+            throws JsonProcessingException {
+        ObjectNode out = MAPPER.createObjectNode();
+
+        props.forEach((k, v) -> {
+            if (specialKey.equals(k)) {
+                try {
+                    // Store the special key's stringified json data as a json 
array
+                    ArrayNode arr = (ArrayNode) MAPPER.readTree(v);
+
+                    // sort deterministically by (number, name)
+                    List<JsonNode> items = new ArrayList<>();
+                    arr.forEach(items::add);
+                    items.sort(Comparator
+                        .comparing((JsonNode n) -> n.path("number").asInt())
+                        .thenComparing(n -> n.path("name").asText()));
+                    ArrayNode sorted = MAPPER.createArrayNode();
+                    items.forEach(sorted::add);
+                    out.set(k, sorted);
+                } catch (Exception e) {
+                    // If it's not valid JSON for some reason, store as raw 
string
+                    out.put(k, v);
+                }
+            } else {
+                out.put(k, v);
+            }
+        });
+        return out;
+    }
+
     @Test
     public void testEncodeAndDecode() {
         Function.FunctionDetails functionDetails = 
Function.FunctionDetails.newBuilder().setName(NAME).build();
@@ -120,9 +160,14 @@ public class ProtobufSchemaTest {
         ProtobufSchema<org.apache.pulsar.client.schema.proto.Test.TestMessage> 
protobufSchema =
                 
ProtobufSchema.of(org.apache.pulsar.client.schema.proto.Test.TestMessage.class);
 
-        Assert.assertEquals(new ObjectMapper().writeValueAsString(
-                protobufSchema.getSchemaInfo().getProperties()), 
EXPECTED_PARSING_INFO);
+        Map<String, String> actualProps   = 
protobufSchema.getSchemaInfo().getProperties();
+        Map<String, String> expectedProps = MAPPER.readValue(
+                EXPECTED_PARSING_INFO, new TypeReference<Map<String, 
String>>() {});
+
+        ObjectNode normActual   = normalizeAllProps(actualProps, 
"__PARSING_INFO__");
+        ObjectNode normExpected = normalizeAllProps(expectedProps, 
"__PARSING_INFO__");
 
+        Assert.assertEquals(normActual, normExpected);
     }
 
     @Test

Reply via email to