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

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new bf02a1bfc [SCB-2893]-Fixes flaky tests in TestSchemaToProtoGenerator 
(#4635)
bf02a1bfc is described below

commit bf02a1bfc2dbd5582e5dadb842524251c4b0a25c
Author: Weronika Trzaska <[email protected]>
AuthorDate: Mon Dec 16 21:56:28 2024 -0600

    [SCB-2893]-Fixes flaky tests in TestSchemaToProtoGenerator (#4635)
---
 .../protobuf/schema/SchemaToProtoGenerator.java    |  5 ++++-
 .../schema/TestSchemaToProtoGenerator.java         | 22 +++++++++++-----------
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git 
a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/schema/SchemaToProtoGenerator.java
 
b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/schema/SchemaToProtoGenerator.java
index 9c2cf94d4..0220cd96b 100644
--- 
a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/schema/SchemaToProtoGenerator.java
+++ 
b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/schema/SchemaToProtoGenerator.java
@@ -22,6 +22,7 @@ import static 
org.apache.servicecomb.foundation.common.utils.StringBuilderUtils.
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -354,8 +355,10 @@ public class SchemaToProtoGenerator {
     messages.add(schema.getName());
 
     appendLine(msgStringBuilder, "message %s {", schema.getName());
+    List<Map.Entry<String, Schema>> sortedProperties = new 
ArrayList<>(schema.getProperties().entrySet());
+    sortedProperties.sort(Comparator.comparing(Map.Entry::getKey));
     int tag = 1;
-    for (Entry<String, Schema> entry : schema.getProperties().entrySet()) {
+    for (Entry<String, Schema> entry : sortedProperties) {
       Schema property = entry.getValue();
       String propertyType = findSchemaType(property);
 
diff --git 
a/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/schema/TestSchemaToProtoGenerator.java
 
b/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/schema/TestSchemaToProtoGenerator.java
index 61401180b..23ac41135 100644
--- 
a/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/schema/TestSchemaToProtoGenerator.java
+++ 
b/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/schema/TestSchemaToProtoGenerator.java
@@ -154,8 +154,8 @@ public class TestSchemaToProtoGenerator {
         package test.model;
 
         message Model {
-          string name = 1;
-          sint32 age = 2;
+          sint32 age = 1;
+          string name = 2;
         }
 
         //@WrapProperty
@@ -175,8 +175,8 @@ public class TestSchemaToProtoGenerator {
         package test.model;
 
         message Model {
-          string name = 1;
-          sint32 age = 2;
+          sint32 age = 1;
+          string name = 2;
         }
 
         //@WrapProperty
@@ -220,15 +220,15 @@ public class TestSchemaToProtoGenerator {
        }
 
        message DeptInfo {
-         string name = 1;
-         string code = 2;
+         string code = 1;
+         string name = 2;
          repeated ScoreInfo scores = 3;
        }
 
        message UserInfo {
-         repeated DeptInfo subDeptInfos = 1;
-         repeated MapString extraInfos = 2;
-         repeated ListListString nestedLists = 3;
+         repeated MapString extraInfos = 1;
+         repeated ListListString nestedLists = 2;
+         repeated DeptInfo subDeptInfos = 3;
        }
 
        //@WrapProperty
@@ -267,8 +267,8 @@ public class TestSchemaToProtoGenerator {
        }
 
        message DeptInfo {
-         string name = 1;
-         string code = 2;
+         string code = 1;
+         string name = 2;
          repeated ScoreInfo scores = 3;
        }
 

Reply via email to