Skip to content

Commit

Permalink
[AVRO-2579]: Fix tests by sorting fields for deterministic order
Browse files Browse the repository at this point in the history
  • Loading branch information
contextshuffling authored and Pezhin committed Mar 1, 2020
1 parent 17be402 commit d048cf8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -728,7 +729,9 @@ private static Field[] getFields(Class<?> recordClass, boolean excludeJava) {
do {
if (excludeJava && c.getPackage() != null && c.getPackage().getName().startsWith("java."))
break; // skip java built-in classes
for (Field field : c.getDeclaredFields())
Field[] declaredFields = c.getDeclaredFields();
Arrays.sort(declaredFields, Comparator.comparing(Field::getName));
for (Field field : declaredFields)
if ((field.getModifiers() & (Modifier.TRANSIENT | Modifier.STATIC)) == 0)
if (fields.put(field.getName(), field) != null)
throw new AvroTypeException(c + " contains two fields named: " + field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1318,12 +1318,12 @@ private static class DocTest {
public void testAvroDoc() {
check(DocTest.class,
"{\"type\":\"record\",\"name\":\"DocTest\",\"namespace\":\"org.apache.avro.reflect.TestReflect\","
+ "\"doc\":\"DocTest class docs\","
+ "\"fields\":[{\"name\":\"foo\",\"type\":\"int\",\"doc\":\"Some Documentation\"},"
+ "\"doc\":\"DocTest class docs\"," + "\"fields\":["
+ "{\"name\":\"defaultTest\",\"type\":{\"type\":\"record\",\"name\":\"DefaultTest\","
+ "\"fields\":[{\"name\":\"foo\",\"type\":\"int\",\"default\":1}]},\"doc\":\"And again\"},"
+ "{\"name\":\"enums\",\"type\":{\"type\":\"enum\",\"name\":\"DocTestEnum\","
+ "\"symbols\":[\"ENUM_1\",\"ENUM_2\"]},\"doc\":\"Some other Documentation\"},"
+ "{\"name\":\"defaultTest\",\"type\":{\"type\":\"record\",\"name\":\"DefaultTest\","
+ "\"fields\":[{\"name\":\"foo\",\"type\":\"int\",\"default\":1}]},\"doc\":\"And again\"}]}");
+ "{\"name\":\"foo\",\"type\":\"int\",\"doc\":\"Some Documentation\"}" + "]}");
}

}

0 comments on commit d048cf8

Please sign in to comment.