Skip to content
Permalink
Browse files
8276650: GenGraphs does not produce deterministic output
Reviewed-by: iris
  • Loading branch information
Mandy Chung committed Nov 4, 2021
1 parent 7b1916e commit e21b5c7b3781430ecf568e7f5c89ef3391e06d9e
Showing 2 changed files with 40 additions and 39 deletions.
@@ -333,7 +333,7 @@ static class SubGraph {

private final String name;
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 Attributes attributes;
public DotGraphBuilder(String name,
@@ -414,7 +414,7 @@ public void printNode(PrintWriter out, ModuleDescriptor md, Set<String> edges) {
.collect(toSet());

String mn = md.name();
edges.forEach(dn -> {
edges.stream().sorted().forEach(dn -> {
String attr = "";
if (dn.equals("java.base")) {
attr = "color=\"" + attributes.requiresMandatedColor() + "\"";
@@ -37,13 +37,12 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.spi.ToolProvider;
import java.util.stream.Collectors;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
@@ -72,41 +71,43 @@ public void setup() throws Exception {
@DataProvider(name = "modules")
public Object[][] modules() {
return new Object[][]{
{"java.desktop", Set.of("java.datatransfer -> java.base",
"java.desktop -> java.datatransfer",
"java.desktop -> java.prefs",
"java.prefs -> java.xml",
"java.xml -> java.base" )
// the edges for each module are printed in lexicographical order
{"java.desktop", List.of("java.datatransfer -> java.base",
"java.desktop -> java.datatransfer",
"java.desktop -> java.prefs",
"java.prefs -> java.xml",
"java.xml -> java.base" )
},
{ "java.sql", Set.of("java.logging -> java.base",
"java.transaction.xa -> java.base",
"java.sql -> java.logging",
"java.sql -> java.transaction.xa",
"java.sql -> java.xml",
"java.xml -> java.base" )
{ "java.sql", List.of("java.logging -> java.base",
"java.sql -> java.logging",
"java.sql -> java.transaction.xa",
"java.sql -> java.xml",
"java.transaction.xa -> java.base",
"java.xml -> java.base" )
}
};
}
@DataProvider(name = "specVersion")
public Object[][] specVersion() {
return new Object[][]{
{"java.desktop", Set.of("java.datatransfer -> java.base",
"java.desktop -> java.datatransfer",
"java.desktop -> java.xml",
"java.xml -> java.base")
// the edges for each module are printed in lexicographical order
{"java.desktop", List.of("java.datatransfer -> java.base",
"java.desktop -> java.datatransfer",
"java.desktop -> java.xml",
"java.xml -> java.base")
},
{ "java.sql", Set.of("java.logging -> java.base",
"java.transaction.xa -> java.base",
"java.sql -> java.logging",
"java.sql -> java.transaction.xa",
"java.sql -> java.xml",
"java.xml -> java.base" )
{ "java.sql", List.of("java.logging -> java.base",
"java.sql -> java.logging",
"java.sql -> java.transaction.xa",
"java.sql -> java.xml",
"java.transaction.xa -> java.base",
"java.xml -> java.base" )
}
};
}

@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[] {
"-dotoutput", DOTS_DIR.toString(),
"-s", "-m", name
@@ -115,15 +116,15 @@ public void test(String name, Set<String> edges) throws Exception {

Path path = DOTS_DIR.resolve(name + ".dot");
assertTrue(Files.exists(path));
Set<String> lines = Files.readAllLines(path).stream()
List<String> lines = Files.readAllLines(path).stream()
.filter(l -> l.contains(" -> "))
.map(this::split)
.collect(Collectors.toSet());
.toList();
assertEquals(lines, edges);
}

@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[]{
"-dotoutput", SPEC_DIR.toString(),
"-s", "-apionly",
@@ -133,10 +134,10 @@ public void testAPIOnly(String name, Set<String> edges) throws Exception {

Path path = SPEC_DIR.resolve(name + ".dot");
assertTrue(Files.exists(path));
Set<String> lines = Files.readAllLines(path).stream()
List<String> lines = Files.readAllLines(path).stream()
.filter(l -> l.contains(" -> "))
.map(this::split)
.collect(Collectors.toSet());
.toList();
assertEquals(lines, edges);
}

@@ -160,7 +161,7 @@ public void testModularJar() throws Exception {
assertTrue(Files.exists(path));

// package dependences
Set<String> expected = Set.of(
List<String> expected = List.of(
"org.indirect -> java.lang",
"org.indirect -> org.unsafe",
"org.safe -> java.io",
@@ -170,7 +171,7 @@ public void testModularJar() throws Exception {
);

Pattern pattern = Pattern.compile("(.*) -> +([^ ]*) (.*)");
Set<String> lines = new HashSet<>();
List<String> lines = new ArrayList<>();
for (String line : Files.readAllLines(path)) {
line = line.replace('"', ' ').replace(';', ' ');
Matcher pm = pattern.matcher(line);
@@ -201,15 +202,15 @@ public void testModuleSummary() throws Exception {
assertTrue(Files.exists(path));

// module dependences
Set<String> expected = Set.of(
"unsafe -> jdk.unsupported",
"jdk.unsupported -> java.base"
List<String> expected = List.of(
"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(" -> "))
.map(this::split)
.collect(Collectors.toSet());
.toList();
assertEquals(lines, expected);
}

1 comment on commit e21b5c7

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on e21b5c7 Nov 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.