Skip to content

Commit bf02a1b

Browse files
authored
[SCB-2893]-Fixes flaky tests in TestSchemaToProtoGenerator (#4635)
1 parent 27552d2 commit bf02a1b

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/schema/SchemaToProtoGenerator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.nio.charset.StandardCharsets;
2323
import java.util.ArrayList;
2424
import java.util.Collections;
25+
import java.util.Comparator;
2526
import java.util.HashMap;
2627
import java.util.HashSet;
2728
import java.util.List;
@@ -354,8 +355,10 @@ public void createMessage(Schema<?> schema) {
354355
messages.add(schema.getName());
355356

356357
appendLine(msgStringBuilder, "message %s {", schema.getName());
358+
List<Map.Entry<String, Schema>> sortedProperties = new ArrayList<>(schema.getProperties().entrySet());
359+
sortedProperties.sort(Comparator.comparing(Map.Entry::getKey));
357360
int tag = 1;
358-
for (Entry<String, Schema> entry : schema.getProperties().entrySet()) {
361+
for (Entry<String, Schema> entry : sortedProperties) {
359362
Schema property = entry.getValue();
360363
String propertyType = findSchemaType(property);
361364

common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/schema/TestSchemaToProtoGenerator.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ public void test_springmvc_model_schema_correct() {
154154
package test.model;
155155
156156
message Model {
157-
string name = 1;
158-
sint32 age = 2;
157+
sint32 age = 1;
158+
string name = 2;
159159
}
160160
161161
//@WrapProperty
@@ -175,8 +175,8 @@ public void test_springmvc_model_schema_correct() {
175175
package test.model;
176176
177177
message Model {
178-
string name = 1;
179-
sint32 age = 2;
178+
sint32 age = 1;
179+
string name = 2;
180180
}
181181
182182
//@WrapProperty
@@ -220,15 +220,15 @@ public void testNestedModelCorrect() {
220220
}
221221
222222
message DeptInfo {
223-
string name = 1;
224-
string code = 2;
223+
string code = 1;
224+
string name = 2;
225225
repeated ScoreInfo scores = 3;
226226
}
227227
228228
message UserInfo {
229-
repeated DeptInfo subDeptInfos = 1;
230-
repeated MapString extraInfos = 2;
231-
repeated ListListString nestedLists = 3;
229+
repeated MapString extraInfos = 1;
230+
repeated ListListString nestedLists = 2;
231+
repeated DeptInfo subDeptInfos = 3;
232232
}
233233
234234
//@WrapProperty
@@ -267,8 +267,8 @@ public void testListMapTypeCorrect() {
267267
}
268268
269269
message DeptInfo {
270-
string name = 1;
271-
string code = 2;
270+
string code = 1;
271+
string name = 2;
272272
repeated ScoreInfo scores = 3;
273273
}
274274

0 commit comments

Comments
 (0)