uschindler commented on a change in pull request #470: URL: https://github.com/apache/lucene/pull/470#discussion_r761789419
########## File path: lucene/distribution-tests/src/test/org/apache/lucene/distribution/TestModularLayer.java ########## @@ -108,4 +140,76 @@ public void testAllModulesHaveExpectedVersion() { .isEqualTo(luceneBuildVersion); } } + + /** Ensure SPIs are equal for the module and classpath layer. */ + @Test + public void testModularAndClasspathProvidersAreConsistent() throws IOException { + for (var module : allModules) { + TreeMap<String, TreeSet<String>> modularProviders = getModularServiceProviders(module); + TreeMap<String, TreeSet<String>> classpathProviders = getClasspathServiceProviders(module); + + // Compare services first so that the exception is shorter. + Assertions.assertThat(modularProviders.keySet()) + .as("Modular services in module: " + module.descriptor().name()) + .containsAll(classpathProviders.keySet()); + + // We're sure the services correspond to each other. Now, for each service, compare the + // providers. + for (var service : modularProviders.keySet()) { + Assertions.assertThat(modularProviders.get(service)) + .as( + "Modular providers of service " + + service + + " in module: " + + module.descriptor().name()) + .containsAll(classpathProviders.get(service)); + } + } + } + + private TreeMap<String, TreeSet<String>> getClasspathServiceProviders(ModuleReference module) + throws IOException { + TreeMap<String, TreeSet<String>> services = new TreeMap<>(); + Pattern serviceEntryPattern = Pattern.compile("META-INF/services/(?<serviceName>.+)"); + try (ModuleReader reader = module.open(); + Stream<String> entryStream = reader.list()) { + List<String> serviceProviderEntryList = + entryStream + .filter(entry -> serviceEntryPattern.matcher(entry).find()) + .collect(Collectors.toList()); + + for (String entry : serviceProviderEntryList) { + List<String> implementations; + try (InputStream is = reader.open(entry).get()) { + implementations = + Arrays.stream(new String(is.readAllBytes(), StandardCharsets.UTF_8).split("\n")) Review comment: And the trim also removes the windows `\r` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org