8276650: GenGraphs does not produce deterministic output

Reviewed-by: iris
This commit is contained in:
Mandy Chung 2021-11-04 23:51:18 +00:00
parent 7b1916efda
commit e21b5c7b37
2 changed files with 40 additions and 39 deletions

View File

@ -333,7 +333,7 @@ public class ModuleDotGraph {
private final String name; private final String name;
private final Graph<String> graph; private final Graph<String> graph;
private final Set<ModuleDescriptor> descriptors = new TreeSet<>(); private final TreeSet<ModuleDescriptor> descriptors = new TreeSet<>();
private final List<SubGraph> subgraphs = new ArrayList<>(); private final List<SubGraph> subgraphs = new ArrayList<>();
private final Attributes attributes; private final Attributes attributes;
public DotGraphBuilder(String name, public DotGraphBuilder(String name,
@ -414,7 +414,7 @@ public class ModuleDotGraph {
.collect(toSet()); .collect(toSet());
String mn = md.name(); String mn = md.name();
edges.forEach(dn -> { edges.stream().sorted().forEach(dn -> {
String attr = ""; String attr = "";
if (dn.equals("java.base")) { if (dn.equals("java.base")) {
attr = "color=\"" + attributes.requiresMandatedColor() + "\""; attr = "color=\"" + attributes.requiresMandatedColor() + "\"";

View File

@ -37,13 +37,12 @@
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.HashSet; import java.util.ArrayList;
import java.util.Set; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.spi.ToolProvider; import java.util.spi.ToolProvider;
import java.util.stream.Collectors;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
@ -72,41 +71,43 @@ public class DotFileTest {
@DataProvider(name = "modules") @DataProvider(name = "modules")
public Object[][] modules() { public Object[][] modules() {
return new Object[][]{ return new Object[][]{
{"java.desktop", Set.of("java.datatransfer -> java.base", // the edges for each module are printed in lexicographical order
"java.desktop -> java.datatransfer", {"java.desktop", List.of("java.datatransfer -> java.base",
"java.desktop -> java.prefs", "java.desktop -> java.datatransfer",
"java.prefs -> java.xml", "java.desktop -> java.prefs",
"java.xml -> java.base" ) "java.prefs -> java.xml",
"java.xml -> java.base" )
}, },
{ "java.sql", Set.of("java.logging -> java.base", { "java.sql", List.of("java.logging -> java.base",
"java.transaction.xa -> java.base", "java.sql -> java.logging",
"java.sql -> java.logging", "java.sql -> java.transaction.xa",
"java.sql -> java.transaction.xa", "java.sql -> java.xml",
"java.sql -> java.xml", "java.transaction.xa -> java.base",
"java.xml -> java.base" ) "java.xml -> java.base" )
} }
}; };
} }
@DataProvider(name = "specVersion") @DataProvider(name = "specVersion")
public Object[][] specVersion() { public Object[][] specVersion() {
return new Object[][]{ return new Object[][]{
{"java.desktop", Set.of("java.datatransfer -> java.base", // the edges for each module are printed in lexicographical order
"java.desktop -> java.datatransfer", {"java.desktop", List.of("java.datatransfer -> java.base",
"java.desktop -> java.xml", "java.desktop -> java.datatransfer",
"java.xml -> java.base") "java.desktop -> java.xml",
"java.xml -> java.base")
}, },
{ "java.sql", Set.of("java.logging -> java.base", { "java.sql", List.of("java.logging -> java.base",
"java.transaction.xa -> java.base", "java.sql -> java.logging",
"java.sql -> java.logging", "java.sql -> java.transaction.xa",
"java.sql -> java.transaction.xa", "java.sql -> java.xml",
"java.sql -> java.xml", "java.transaction.xa -> java.base",
"java.xml -> java.base" ) "java.xml -> java.base" )
} }
}; };
} }
@Test(dataProvider = "modules") @Test(dataProvider = "modules")
public void test(String name, Set<String> edges) throws Exception { public void test(String name, List<String> edges) throws Exception {
String[] options = new String[] { String[] options = new String[] {
"-dotoutput", DOTS_DIR.toString(), "-dotoutput", DOTS_DIR.toString(),
"-s", "-m", name "-s", "-m", name
@ -115,15 +116,15 @@ public class DotFileTest {
Path path = DOTS_DIR.resolve(name + ".dot"); Path path = DOTS_DIR.resolve(name + ".dot");
assertTrue(Files.exists(path)); assertTrue(Files.exists(path));
Set<String> lines = Files.readAllLines(path).stream() List<String> lines = Files.readAllLines(path).stream()
.filter(l -> l.contains(" -> ")) .filter(l -> l.contains(" -> "))
.map(this::split) .map(this::split)
.collect(Collectors.toSet()); .toList();
assertEquals(lines, edges); assertEquals(lines, edges);
} }
@Test(dataProvider = "specVersion") @Test(dataProvider = "specVersion")
public void testAPIOnly(String name, Set<String> edges) throws Exception { public void testAPIOnly(String name, List<String> edges) throws Exception {
String[] options = new String[]{ String[] options = new String[]{
"-dotoutput", SPEC_DIR.toString(), "-dotoutput", SPEC_DIR.toString(),
"-s", "-apionly", "-s", "-apionly",
@ -133,10 +134,10 @@ public class DotFileTest {
Path path = SPEC_DIR.resolve(name + ".dot"); Path path = SPEC_DIR.resolve(name + ".dot");
assertTrue(Files.exists(path)); assertTrue(Files.exists(path));
Set<String> lines = Files.readAllLines(path).stream() List<String> lines = Files.readAllLines(path).stream()
.filter(l -> l.contains(" -> ")) .filter(l -> l.contains(" -> "))
.map(this::split) .map(this::split)
.collect(Collectors.toSet()); .toList();
assertEquals(lines, edges); assertEquals(lines, edges);
} }
@ -160,7 +161,7 @@ public class DotFileTest {
assertTrue(Files.exists(path)); assertTrue(Files.exists(path));
// package dependences // package dependences
Set<String> expected = Set.of( List<String> expected = List.of(
"org.indirect -> java.lang", "org.indirect -> java.lang",
"org.indirect -> org.unsafe", "org.indirect -> org.unsafe",
"org.safe -> java.io", "org.safe -> java.io",
@ -170,7 +171,7 @@ public class DotFileTest {
); );
Pattern pattern = Pattern.compile("(.*) -> +([^ ]*) (.*)"); Pattern pattern = Pattern.compile("(.*) -> +([^ ]*) (.*)");
Set<String> lines = new HashSet<>(); List<String> lines = new ArrayList<>();
for (String line : Files.readAllLines(path)) { for (String line : Files.readAllLines(path)) {
line = line.replace('"', ' ').replace(';', ' '); line = line.replace('"', ' ').replace(';', ' ');
Matcher pm = pattern.matcher(line); Matcher pm = pattern.matcher(line);
@ -201,15 +202,15 @@ public class DotFileTest {
assertTrue(Files.exists(path)); assertTrue(Files.exists(path));
// module dependences // module dependences
Set<String> expected = Set.of( List<String> expected = List.of(
"unsafe -> jdk.unsupported", "jdk.unsupported -> java.base",
"jdk.unsupported -> java.base" "unsafe -> jdk.unsupported"
); );
Set<String> lines = Files.readAllLines(path).stream() List<String> lines = Files.readAllLines(path).stream()
.filter(l -> l.contains(" -> ")) .filter(l -> l.contains(" -> "))
.map(this::split) .map(this::split)
.collect(Collectors.toSet()); .toList();
assertEquals(lines, expected); assertEquals(lines, expected);
} }