From 20596a395850a78fef45005454156e91b9e3735b Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Mon, 18 Sep 2023 21:04:16 -0500 Subject: [PATCH] [WFCORE-6498] Correct the LayersTest handling of alias modules --- .../base/org/jboss/as/server/main/module.xml | 3 +- .../org/jboss/as/test/layers/LayersTest.java | 18 ++++++++-- .../java/org/jboss/as/test/layers/Result.java | 12 ++++++- .../org/jboss/as/test/layers/Scanner.java | 34 +++++++------------ 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/core-feature-pack/common/src/main/resources/modules/system/layers/base/org/jboss/as/server/main/module.xml b/core-feature-pack/common/src/main/resources/modules/system/layers/base/org/jboss/as/server/main/module.xml index ce6cf48ee08..c85ba7b5e2f 100644 --- a/core-feature-pack/common/src/main/resources/modules/system/layers/base/org/jboss/as/server/main/module.xml +++ b/core-feature-pack/common/src/main/resources/modules/system/layers/base/org/jboss/as/server/main/module.xml @@ -28,14 +28,13 @@ + - - diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/layers/LayersTest.java b/testsuite/shared/src/main/java/org/jboss/as/test/layers/LayersTest.java index 3e9971626c2..0b7f72085f1 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/layers/LayersTest.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/layers/LayersTest.java @@ -123,9 +123,11 @@ public static void testLayersModuleUse(Set unused, ScanContext scanConte appendResult(k, layers.get(k), builder, reference); } + // The only modules that are expected to be not provisioned are the un-used ones. // If more are not provisioned, then we are missing some modules. - String missingRequired = listModules(deltaModules, m -> !unused.contains(m)); + final Set referenceAliases = reference.getAliases(); // don't require callers to include alias modules in 'unused' + String missingRequired = listModules(deltaModules, m -> !unused.contains(m) && !referenceAliases.contains(m)); if (!missingRequired.isEmpty()) { String error = "Some expected modules have not been provisioned in " + ALL_LAYERS; builder.append("#!!!!!ERROR ").append(error).append("\n"); @@ -198,11 +200,18 @@ public static void testUnreferencedModules(Set unreferenced, ScanContext // Check that the reference has no more un-referenced modules than the expected ones. Set allUnReferenced = new HashSet<>(unreferenced); final Set refUnreferenced = reference.getNotReferenced(); - String invalidUnref = listModules(refUnreferenced, m -> !allUnReferenced.contains(m)); + final Set referenceAliases = reference.getAliases(); // don't require callers to include alias modules in 'unreferenced' + String invalidUnref = listModules(refUnreferenced, m -> !allUnReferenced.contains(m) && !referenceAliases.contains(m)); if (!invalidUnref.isEmpty()) { appendExceptionMsg(exceptionBuilder, "Some unreferenced modules are unexpected " + invalidUnref, empty); } + // Check that alias modules are not referenced + String referencedAlias = listModules(referenceAliases, m -> !refUnreferenced.contains(m)); + if (!referencedAlias.isEmpty()) { + appendExceptionMsg(exceptionBuilder, "Some alias modules are referenced " + referencedAlias, empty); + } + if (VALIDATE_INPUTS) { // Confirm that 'unreferenced' modules actually exist in the reference installation @@ -463,6 +472,11 @@ private static Set appendResult(String title, Result result, StringBuild notReferenced.append(s).append(","); } builder.append("unreferenced_modules=").append(notReferenced).append("\n"); + StringBuilder aliases = new StringBuilder(); + for (String s : result.getAliases()) { + aliases.append(s).append(","); + } + builder.append("alias_modules=").append(aliases).append("\n"); builder.append("num_unresolved=").append(optionals.size()).append("\n"); } for (Map.Entry> entry : optionals.entrySet()) { diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/layers/Result.java b/testsuite/shared/src/main/java/org/jboss/as/test/layers/Result.java index 554eb60ebff..b128a418a93 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/layers/Result.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/layers/Result.java @@ -60,13 +60,16 @@ public String getModule() { private final Map> unresolvedOptional; private final Set modules; private final Set notReferenced; + private final Set aliases; private final List extensions; - Result(long size, Set modules, Map> unresolvedOptional, Set notReferenced, List extensions) { + Result(long size, Set modules, Map> unresolvedOptional, Set notReferenced, + Set aliases, List extensions) { this.size = size; this.modules = modules; this.unresolvedOptional = unresolvedOptional; this.notReferenced = notReferenced; + this.aliases = aliases; this.extensions = extensions; } @@ -98,6 +101,13 @@ public Set getNotReferenced() { return notReferenced; } + /** + * @return the aliases + */ + public Set getAliases() { + return aliases; + } + /** * @return the extensions */ diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/layers/Scanner.java b/testsuite/shared/src/main/java/org/jboss/as/test/layers/Scanner.java index ef45e89126b..a46f3ae166c 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/layers/Scanner.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/layers/Scanner.java @@ -41,7 +41,7 @@ public static Result scan(Path homePath, Path configFile) throws Exception { Map> optionalDependencies = new TreeMap<>(); List size = new ArrayList<>(); size.add((long) 0); - Files.walkFileTree(homePath, new SimpleFileVisitor() { + Files.walkFileTree(homePath, new SimpleFileVisitor<>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { size.set(0, size.get(0) + attrs.size()); @@ -50,7 +50,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { }); Map> modulesReference = new HashMap<>(); Set modules = new HashSet<>(); - Files.walkFileTree(modulePath, new SimpleFileVisitor() { + Set aliases = new HashSet<>(); + Files.walkFileTree(modulePath, new SimpleFileVisitor<>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { @@ -63,13 +64,13 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) Document document = documentBuilder.parse(file.toFile()); Element elemAlias = (Element) document.getElementsByTagName("module-alias").item(0); if (elemAlias != null) { + // Track both the alias and the target, with the alias treated as a ref to target String moduleName = elemAlias.getAttribute("name"); + aliases.add(moduleName); + modules.add(moduleName); + modulesReference.computeIfAbsent(moduleName, k -> new HashSet<>()); String target = elemAlias.getAttribute("target-name"); - Set referencing = modulesReference.get(target); - if (referencing == null) { - referencing = new HashSet<>(); - modulesReference.put(target, referencing); - } + Set referencing = modulesReference.computeIfAbsent(target, k -> new HashSet<>()); referencing.add(moduleName); return FileVisitResult.CONTINUE; } @@ -93,11 +94,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) optionals.add(mod); } } - Set referencing = modulesReference.get(mod); - if (referencing == null) { - referencing = new HashSet<>(); - modulesReference.put(mod, referencing); - } + Set referencing = modulesReference.computeIfAbsent(mod, k -> new HashSet<>()); referencing.add(moduleName); } } @@ -112,8 +109,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) } @Override - public FileVisitResult postVisitDirectory(Path dir, IOException e) - throws IOException { + public FileVisitResult postVisitDirectory(Path dir, IOException e) { return FileVisitResult.CONTINUE; } } @@ -123,11 +119,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e) for (Map.Entry> entry : optionalDependencies.entrySet()) { for (String opt : entry.getValue()) { if (!modules.contains(opt)) { - Set roots = missing.get(opt); - if (roots == null) { - roots = new TreeSet<>(); - missing.put(opt, roots); - } + Set roots = missing.computeIfAbsent(opt, k -> new TreeSet<>()); roots.add(entry.getKey()); } } @@ -198,7 +190,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e) extensionResults.add(new Result.ExtensionResult(ex, extSize.get(0) / 1024, deps, unresolved)); } - return new Result(size.get(0) / 1024, modules, missing, allNotReferenced, extensionResults); + return new Result(size.get(0) / 1024, modules, missing, allNotReferenced, aliases, extensionResults); } private static Set retrieveExtensionModules(Path conf) throws Exception { @@ -240,7 +232,7 @@ private static void getDependencies(Path modulePath, String module, Set return; } // Add content size. - Files.walkFileTree(path.getParent(), new SimpleFileVisitor() { + Files.walkFileTree(path.getParent(), new SimpleFileVisitor<>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { size.set(0, size.get(0) + attrs.size());