1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
|
--- a/lucene/distribution.tests/src/test/org/apache/lucene/distribution/TestModularLayer.java
+++ /dev/null
@@ -1,420 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.distribution;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.module.Configuration;
-import java.lang.module.ModuleDescriptor;
-import java.lang.module.ModuleFinder;
-import java.lang.module.ModuleReader;
-import java.lang.module.ModuleReference;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.function.Predicate;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-import org.assertj.core.api.Assertions;
-import org.assertj.core.api.Assumptions;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Sanity checks concerning the distribution's binary artifacts (modules).
- *
- * <p>We do <em>not</em> want this module to depend on any Lucene classes (including the test
- * framework) so that there is no risk of accidental classpath space pollution. This also means the
- * default {@code LuceneTestCase} configuration setup is not used (you have to annotate test for
- * JUnit, for example).
- */
-public class TestModularLayer extends AbstractLuceneDistributionTest {
- /** All Lucene modules (including the test framework), no third party modules. */
- private static Set<ModuleReference> allLuceneModules;
-
- /** {@link ModuleFinder} resolving only the core Lucene modules. */
- private static ModuleFinder allLuceneModulesFinder;
-
- /** {@link ModuleFinder} resolving Lucene core and third party dependencies. */
- private static ModuleFinder luceneCoreAndThirdPartyModulesFinder;
-
- /**
- * We accept external properties that point to the assembled set of distribution modules and to
- * their expected version. These properties are collected and passed by gradle but can be provided
- * manually (for IDE launches).
- */
- @BeforeClass
- public static void checkModulePathProvided() {
- String modulesPropertyValue = System.getProperty(DISTRIBUTION_PROPERTY);
- if (modulesPropertyValue == null) {
- throw new AssertionError(DISTRIBUTION_PROPERTY + " property is required for this test.");
- }
-
- Path modulesPath = getDistributionPath().resolve("modules");
- if (!Files.isDirectory(modulesPath)) {
- throw new AssertionError(
- DISTRIBUTION_PROPERTY
- + " property does not point to a directory where this path is present: "
- + modulesPath.toAbsolutePath());
- }
-
- Path testModulesPath = Paths.get(modulesPropertyValue).resolve("modules-test-framework");
- if (!Files.isDirectory(testModulesPath)) {
- throw new AssertionError(
- DISTRIBUTION_PROPERTY
- + " property does not point to a directory where this path is present: "
- + modulesPath.toAbsolutePath());
- }
-
- Path thirdPartyModulesPath = Paths.get(modulesPropertyValue).resolve("modules-thirdparty");
- if (!Files.isDirectory(thirdPartyModulesPath)) {
- throw new AssertionError(
- DISTRIBUTION_PROPERTY
- + " property does not point to a directory where this path is present: "
- + thirdPartyModulesPath.toAbsolutePath());
- }
-
- allLuceneModulesFinder = ModuleFinder.of(modulesPath, testModulesPath);
- allLuceneModules = allLuceneModulesFinder.findAll();
-
- luceneCoreAndThirdPartyModulesFinder = ModuleFinder.of(modulesPath, thirdPartyModulesPath);
- }
-
- @AfterClass
- public static void cleanup() {
- allLuceneModules = null;
- luceneCoreAndThirdPartyModulesFinder = null;
- allLuceneModulesFinder = null;
- }
-
- /** Make sure all published module names remain constant, even if we reorganize the build. */
- @Test
- public void testExpectedDistributionModuleNames() {
- Assertions.assertThat(
- allLuceneModules.stream().map(module -> module.descriptor().name()).sorted())
- .containsExactly(
- "org.apache.lucene.analysis.common",
- "org.apache.lucene.analysis.icu",
- "org.apache.lucene.analysis.kuromoji",
- "org.apache.lucene.analysis.morfologik",
- "org.apache.lucene.analysis.nori",
- "org.apache.lucene.analysis.opennlp",
- "org.apache.lucene.analysis.phonetic",
- "org.apache.lucene.analysis.smartcn",
- "org.apache.lucene.analysis.stempel",
- "org.apache.lucene.backward_codecs",
- "org.apache.lucene.benchmark",
- "org.apache.lucene.classification",
- "org.apache.lucene.codecs",
- "org.apache.lucene.core",
- "org.apache.lucene.demo",
- "org.apache.lucene.expressions",
- "org.apache.lucene.facet",
- "org.apache.lucene.grouping",
- "org.apache.lucene.highlighter",
- "org.apache.lucene.join",
- "org.apache.lucene.luke",
- "org.apache.lucene.memory",
- "org.apache.lucene.misc",
- "org.apache.lucene.monitor",
- "org.apache.lucene.queries",
- "org.apache.lucene.queryparser",
- "org.apache.lucene.replicator",
- "org.apache.lucene.sandbox",
- "org.apache.lucene.spatial3d",
- "org.apache.lucene.spatial_extras",
- "org.apache.lucene.suggest",
- "org.apache.lucene.test_framework");
- }
-
- /** Try to instantiate the demo classes so that we make sure their module layer is complete. */
- @Test
- public void testDemoClassesCanBeLoaded() {
- ModuleLayer bootLayer = ModuleLayer.boot();
- Assertions.assertThatNoException()
- .isThrownBy(
- () -> {
- String demoModuleId = "org.apache.lucene.demo";
-
- Configuration configuration =
- bootLayer
- .configuration()
- .resolve(
- luceneCoreAndThirdPartyModulesFinder,
- ModuleFinder.of(),
- List.of(demoModuleId));
-
- ModuleLayer layer =
- bootLayer.defineModulesWithOneLoader(
- configuration, ClassLoader.getSystemClassLoader());
-
- for (String className :
- List.of(
- "org.apache.lucene.demo.IndexFiles",
- "org.apache.lucene.demo.SearchFiles",
- "org.apache.lucene.index.CheckIndex")) {
- Assertions.assertThat(layer.findLoader(demoModuleId).loadClass(className))
- .isNotNull();
- }
- });
- }
-
- /** Checks that Lucene Core is a MR-JAR and has Panama foreign classes */
- @Test
- public void testMultiReleaseJar() {
- ModuleLayer bootLayer = ModuleLayer.boot();
- Assertions.assertThatNoException()
- .isThrownBy(
- () -> {
- String coreModuleId = "org.apache.lucene.core";
-
- Configuration configuration =
- bootLayer
- .configuration()
- .resolve(
- luceneCoreAndThirdPartyModulesFinder,
- ModuleFinder.of(),
- List.of(coreModuleId));
-
- ModuleLayer layer =
- bootLayer.defineModulesWithOneLoader(
- configuration, ClassLoader.getSystemClassLoader());
-
- ClassLoader loader = layer.findLoader(coreModuleId);
-
- final Set<Integer> jarVersions = Set.of(19, 20, 21);
- for (var v : jarVersions) {
- Assertions.assertThat(
- loader.getResource(
- "META-INF/versions/"
- + v
- + "/org/apache/lucene/store/MemorySegmentIndexInput.class"))
- .isNotNull();
- }
-
- final int runtimeVersion = Runtime.version().feature();
- if (jarVersions.contains(Integer.valueOf(runtimeVersion))) {
- Assertions.assertThat(
- loader.loadClass("org.apache.lucene.store.MemorySegmentIndexInput"))
- .isNotNull();
- }
- });
- }
-
- /** Make sure we don't publish automatic modules. */
- @Test
- public void testAllCoreModulesAreNamedModules() {
- Assertions.assertThat(allLuceneModules)
- .allSatisfy(
- module -> {
- Assertions.assertThat(module.descriptor().isAutomatic())
- .as(module.descriptor().name())
- .isFalse();
- });
- }
-
- /** Ensure all modules have the same (expected) version. */
- @Test
- public void testAllModulesHaveExpectedVersion() {
- String luceneBuildVersion = System.getProperty(VERSION_PROPERTY);
- Assumptions.assumeThat(luceneBuildVersion).isNotNull();
- for (var module : allLuceneModules) {
- Assertions.assertThat(module.descriptor().rawVersion().orElse(null))
- .as("Version of module: " + module.descriptor().name())
- .isEqualTo(luceneBuildVersion);
- }
- }
-
- /** Ensure SPIs are equal for the module and classpath layer. */
- @Test
- public void testModularAndClasspathProvidersAreConsistent() throws IOException {
- for (var module : allLuceneModules) {
- 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())
- .containsExactlyInAnyOrderElementsOf(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())
- .containsExactlyInAnyOrderElementsOf(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"))
- .map(String::trim)
- .filter(line -> !line.isBlank() && !line.startsWith("#"))
- .collect(Collectors.toList());
- }
-
- Matcher matcher = serviceEntryPattern.matcher(entry);
- if (!matcher.find()) {
- throw new AssertionError("Impossible.");
- }
- String service = matcher.group("serviceName");
- services.computeIfAbsent(service, k -> new TreeSet<>()).addAll(implementations);
- }
- }
-
- return services;
- }
-
- private static TreeMap<String, TreeSet<String>> getModularServiceProviders(
- ModuleReference module) {
- return module.descriptor().provides().stream()
- .collect(
- Collectors.toMap(
- ModuleDescriptor.Provides::service,
- provides -> new TreeSet<>(provides.providers()),
- (k, v) -> {
- throw new RuntimeException();
- },
- TreeMap::new));
- }
-
- /**
- * Ensure all exported packages in the descriptor are in sync with the module's Java classes.
- *
- * <p>This test should be progressively tuned so that certain internal packages are hidden in the
- * module layer.
- */
- @Test
- public void testAllExportedPackagesInSync() throws IOException {
- for (var module : allLuceneModules) {
- Set<String> jarPackages = getJarPackages(module, entry -> true);
- Set<ModuleDescriptor.Exports> moduleExports = new HashSet<>(module.descriptor().exports());
-
- if (module.descriptor().name().equals("org.apache.lucene.luke")) {
- jarPackages.removeIf(
- entry -> {
- // Luke's packages are not exported.
- return entry.startsWith("org.apache.lucene.luke");
- });
- }
-
- if (module.descriptor().name().equals("org.apache.lucene.core")) {
- // Internal packages should not be exported to unqualified targets.
- jarPackages.removeIf(
- entry -> {
- return entry.startsWith("org.apache.lucene.internal");
- });
-
- // Internal packages should use qualified exports.
- moduleExports.removeIf(
- export -> {
- boolean isInternal = export.source().startsWith("org.apache.lucene.internal");
- if (isInternal) {
- Assertions.assertThat(export.targets())
- .containsExactlyInAnyOrder("org.apache.lucene.test_framework");
- }
- return isInternal;
- });
- }
-
- Assertions.assertThat(moduleExports)
- .as("Exported packages in module: " + module.descriptor().name())
- .allSatisfy(
- export -> {
- Assertions.assertThat(export.targets())
- .as("We only support unqualified exports for now?")
- .isEmpty();
- })
- .map(ModuleDescriptor.Exports::source)
- .containsExactlyInAnyOrderElementsOf(jarPackages);
- }
- }
-
- /** This test ensures that all analysis modules open their resources files to core. */
- @Test
- public void testAllOpenAnalysisPackagesInSync() throws IOException {
- for (var module : allLuceneModules) {
- if (false == module.descriptor().name().startsWith("org.apache.lucene.analysis.")) {
- continue; // at moment we only want to open resources inside analysis packages
- }
-
- // We only collect resources from the JAR file which are:
- // - stopword files (*.txt)
- // - ICU break iterator rules (*.brk)
- var filter = Pattern.compile("/[^/]+\\.(txt|brk)$");
- Set<String> jarPackages = getJarPackages(module, filter.asPredicate());
- Set<ModuleDescriptor.Opens> moduleOpens = module.descriptor().opens();
-
- Assertions.assertThat(moduleOpens)
- .as("Open packages in module: " + module.descriptor().name())
- .allSatisfy(
- export -> {
- Assertions.assertThat(export.targets())
- .as("Opens should only be targeted to Lucene Core.")
- .containsExactly("org.apache.lucene.core");
- })
- .map(ModuleDescriptor.Opens::source)
- .containsExactlyInAnyOrderElementsOf(jarPackages);
- }
- }
-
- private Set<String> getJarPackages(ModuleReference module, Predicate<String> entryFilter)
- throws IOException {
- try (ModuleReader reader = module.open()) {
- return reader
- .list()
- .filter(
- entry ->
- !entry.startsWith("META-INF/")
- && !entry.equals("module-info.class")
- && !entry.endsWith("/")
- && entryFilter.test(entry))
- .map(entry -> entry.replaceAll("/[^/]+$", ""))
- .map(entry -> entry.replace('/', '.'))
- .collect(Collectors.toCollection(TreeSet::new));
- }
- }
-}
--- a/lucene/distribution.tests/src/test/org/apache/lucene/distribution/TestScripts.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.distribution;
-
-import com.carrotsearch.procfork.ForkedProcess;
-import com.carrotsearch.procfork.Launcher;
-import com.carrotsearch.procfork.ProcessBuilderLauncher;
-import com.carrotsearch.randomizedtesting.LifecycleScope;
-import com.carrotsearch.randomizedtesting.RandomizedTest;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-import java.util.concurrent.TimeUnit;
-import java.util.function.Supplier;
-import org.assertj.core.api.Assertions;
-import org.assertj.core.api.ThrowingConsumer;
-import org.junit.Test;
-
-/** Verify that scripts included in the distribution work. */
-public class TestScripts extends AbstractLuceneDistributionTest {
- @Test
- @RequiresGUI
- public void testLukeCanBeLaunched() throws Exception {
- Path distributionPath;
- if (randomBoolean()) {
- // Occasionally, be evil: put the distribution in a folder with a space inside. For Uwe.
- distributionPath = RandomizedTest.newTempDir(LifecycleScope.TEST).resolve("uh oh");
- Files.createDirectory(distributionPath);
- new Sync().sync(getDistributionPath(), distributionPath);
- } else {
- distributionPath = getDistributionPath();
- }
-
- Path currentJava =
- Paths.get(System.getProperty("java.home"), "bin", WINDOWS ? "java.exe" : "java");
- Assertions.assertThat(currentJava).exists();
-
- Path lukeScript = resolveScript(distributionPath.resolve("bin").resolve("luke"));
-
- Launcher launcher =
- new ProcessBuilderLauncher()
- .executable(lukeScript)
- // pass the same JVM which the tests are currently using; this also forces UTF-8 as
- // console
- // encoding so that we know we can safely read it.
- .envvar("LAUNCH_CMD", currentJava.toAbsolutePath().toString())
- .viaShellLauncher()
- .cwd(distributionPath)
- .args("--sanity-check");
-
- execute(
- launcher,
- 0,
- 120,
- (outputBytes) -> {
- // We know it's UTF-8 because we set file.encoding explicitly.
- var output = Files.readString(outputBytes, StandardCharsets.UTF_8);
- Assertions.assertThat(output).contains("[Vader] Hello, Luke.");
- });
- }
-
- /** The value of <code>System.getProperty("os.name")</code>. * */
- public static final String OS_NAME = System.getProperty("os.name");
-
- /** True iff running on Windows. */
- public static final boolean WINDOWS = OS_NAME.startsWith("Windows");
-
- protected Path resolveScript(Path scriptPath) {
- List<Path> candidates = new ArrayList<>();
- candidates.add(scriptPath);
-
- String fileName = scriptPath.getFileName().toString();
- if (WINDOWS) {
- candidates.add(scriptPath.resolveSibling(fileName + ".cmd"));
- candidates.add(scriptPath.resolveSibling(fileName + ".bat"));
- } else {
- candidates.add(scriptPath.resolveSibling(fileName + ".sh"));
- }
-
- return candidates.stream()
- .sequential()
- .filter(Files::exists)
- .findFirst()
- .orElseThrow(() -> new AssertionError("No script found for the base path: " + scriptPath));
- }
-
- private static Supplier<Charset> forkedProcessCharset =
- () -> {
- // The default charset for a forked java process could be computed for the current
- // platform but it adds more complexity. For now, assume it's just parseable ascii.
- return StandardCharsets.ISO_8859_1;
- };
-
- protected void execute(
- Launcher launcher,
- int expectedExitCode,
- long timeoutInSeconds,
- ThrowingConsumer<Path> processOutputConsumer)
- throws Exception {
-
- try (ForkedProcess forkedProcess = launcher.execute()) {
- String command = forkedProcess.getProcess().info().command().orElse("(unset command name)");
-
- Charset charset = forkedProcessCharset.get();
- try {
- Process p = forkedProcess.getProcess();
- if (!p.waitFor(timeoutInSeconds, TimeUnit.SECONDS)) {
- throw new AssertionError("Forked process did not terminate in the expected time");
- }
-
- int exitStatus = p.exitValue();
-
- Assertions.assertThat(exitStatus)
- .as("forked process exit status")
- .isEqualTo(expectedExitCode);
-
- processOutputConsumer.accept(forkedProcess.getProcessOutputFile());
- } catch (Throwable t) {
- logSubprocessOutput(
- command, Files.readString(forkedProcess.getProcessOutputFile(), charset));
- throw t;
- }
- }
- }
-
- protected void logSubprocessOutput(String command, String output) {
- System.out.printf(
- Locale.ROOT,
- "--- [forked subprocess output: %s] ---%n%s%n--- [end of subprocess output] ---%n",
- command,
- output);
- }
-}
--- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/spatial4j/ShapeRectRelationTestCase.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.spatial.spatial4j;
-
-import static org.locationtech.spatial4j.distance.DistanceUtils.DEGREES_TO_RADIANS;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.locationtech.spatial4j.TestLog;
-import org.locationtech.spatial4j.context.SpatialContext;
-import org.locationtech.spatial4j.shape.Circle;
-import org.locationtech.spatial4j.shape.Point;
-import org.locationtech.spatial4j.shape.RectIntersectionTestHelper;
-import org.locationtech.spatial4j.shape.Shape;
-import org.locationtech.spatial4j.shape.ShapeFactory;
-
-public abstract class ShapeRectRelationTestCase extends RandomizedShapeTestCase {
- protected static final double RADIANS_PER_DEGREE = Math.PI / 180.0;
-
- @Rule public final TestLog testLog = TestLog.instance;
-
- protected int maxRadius = 180;
-
- public ShapeRectRelationTestCase() {
- super(SpatialContext.GEO);
- }
-
- public abstract class AbstractRectIntersectionTestHelper
- extends RectIntersectionTestHelper<Shape> {
-
- public AbstractRectIntersectionTestHelper(SpatialContext ctx) {
- super(ctx);
- }
-
- // 2 times each -- should be plenty
-
- @Override
- protected int getContainsMinimum(int laps) {
- return 2;
- }
-
- @Override
- protected int getIntersectsMinimum(int laps) {
- return 2;
- }
-
- // producing "within" cases in Geo3D based on our random shapes doesn't happen often. It'd be
- // nice to increase this.
- @Override
- protected int getWithinMinimum(int laps) {
- return 2;
- }
-
- @Override
- protected int getDisjointMinimum(int laps) {
- return 2;
- }
-
- @Override
- protected int getBoundingMinimum(int laps) {
- return 2;
- }
- }
-
- @Test
- public void testGeoCircleRect() {
- new AbstractRectIntersectionTestHelper(ctx) {
-
- @Override
- protected Shape generateRandomShape(Point nearP) {
- final int circleRadius = maxRadius - random().nextInt(maxRadius); // no 0-radius
- return ctx.getShapeFactory().circle(nearP, circleRadius);
- }
-
- @Override
- protected Point randomPointInEmptyShape(Shape shape) {
- return shape.getCenter();
- }
- }.testRelateWithRectangle();
- }
-
- @Test
- public void testGeoBBoxRect() {
- new AbstractRectIntersectionTestHelper(ctx) {
-
- @Override
- protected boolean isRandomShapeRectangular() {
- return true;
- }
-
- @Override
- protected Shape generateRandomShape(Point nearP) {
- Point upperRight = randomPoint();
- Point lowerLeft = randomPoint();
- if (upperRight.getY() < lowerLeft.getY()) {
- // swap
- Point temp = upperRight;
- upperRight = lowerLeft;
- lowerLeft = temp;
- }
- return ctx.getShapeFactory().rect(lowerLeft, upperRight);
- }
-
- @Override
- protected Point randomPointInEmptyShape(Shape shape) {
- return shape.getCenter();
- }
- }.testRelateWithRectangle();
- }
-
- // very slow, and test sources are not here, so no clue how to fix
- @Test
- public void testGeoPolygonRect() {
- new AbstractRectIntersectionTestHelper(ctx) {
-
- @Override
- protected Shape generateRandomShape(Point nearP) {
- final Point centerPoint = randomPoint();
- final int maxDistance = random().nextInt(maxRadius - 20) + 20;
- final Circle pointZone = ctx.getShapeFactory().circle(centerPoint, maxDistance);
- final int vertexCount = random().nextInt(3) + 3;
- while (true) {
- ShapeFactory.PolygonBuilder builder = ctx.getShapeFactory().polygon();
- for (int i = 0; i < vertexCount; i++) {
- final Point point = randomPointIn(pointZone);
- builder.pointXY(point.getX(), point.getY());
- }
- try {
- return builder.build();
- } catch (
- @SuppressWarnings("unused")
- IllegalArgumentException e) {
- // This is what happens when we create a shape that is invalid. Although it is
- // conceivable that there are cases where
- // the exception is thrown incorrectly, we aren't going to be able to do that in this
- // random test.
- continue;
- }
- }
- }
-
- @Override
- protected Point randomPointInEmptyShape(Shape shape) {
- throw new IllegalStateException("unexpected; need to finish test code");
- }
-
- @Override
- protected int getWithinMinimum(int laps) {
- // Long/thin so lets just find 1.
- return 1;
- }
- }.testRelateWithRectangle();
- }
-
- @Test
- public void testGeoPathRect() {
- new AbstractRectIntersectionTestHelper(ctx) {
-
- @Override
- protected Shape generateRandomShape(Point nearP) {
- final Point centerPoint = randomPoint();
- final int maxDistance = random().nextInt(maxRadius - 20) + 20;
- final Circle pointZone = ctx.getShapeFactory().circle(centerPoint, maxDistance);
- final int pointCount = random().nextInt(5) + 1;
- final double width = (random().nextInt(89) + 1) * DEGREES_TO_RADIANS;
- final ShapeFactory.LineStringBuilder builder = ctx.getShapeFactory().lineString();
- while (true) {
- for (int i = 0; i < pointCount; i++) {
- final Point nextPoint = randomPointIn(pointZone);
- builder.pointXY(nextPoint.getX(), nextPoint.getY());
- }
- builder.buffer(width);
- try {
- return builder.build();
- } catch (
- @SuppressWarnings("unused")
- IllegalArgumentException e) {
- // This is what happens when we create a shape that is invalid. Although it is
- // conceivable that there are cases where
- // the exception is thrown incorrectly, we aren't going to be able to do that in this
- // random test.
- continue;
- }
- }
- }
-
- @Override
- protected Point randomPointInEmptyShape(Shape shape) {
- throw new IllegalStateException("unexpected; need to finish test code");
- }
-
- @Override
- protected int getWithinMinimum(int laps) {
- // Long/thin so lets just find 1.
- return 1;
- }
- }.testRelateWithRectangle();
- }
-}
--- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/spatial4j/TestGeo3dShapeSphereModelRectRelation.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.spatial.spatial4j;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.lucene.spatial3d.geom.GeoArea;
-import org.apache.lucene.spatial3d.geom.GeoBBox;
-import org.apache.lucene.spatial3d.geom.GeoBBoxFactory;
-import org.apache.lucene.spatial3d.geom.GeoCircle;
-import org.apache.lucene.spatial3d.geom.GeoCircleFactory;
-import org.apache.lucene.spatial3d.geom.GeoPoint;
-import org.apache.lucene.spatial3d.geom.GeoPolygonFactory;
-import org.apache.lucene.spatial3d.geom.GeoShape;
-import org.apache.lucene.spatial3d.geom.PlanetModel;
-import org.junit.Test;
-import org.locationtech.spatial4j.shape.Circle;
-import org.locationtech.spatial4j.shape.Point;
-import org.locationtech.spatial4j.shape.Rectangle;
-import org.locationtech.spatial4j.shape.SpatialRelation;
-
-public class TestGeo3dShapeSphereModelRectRelation extends ShapeRectRelationTestCase {
-
- PlanetModel planetModel = PlanetModel.SPHERE;
-
- public TestGeo3dShapeSphereModelRectRelation() {
- Geo3dSpatialContextFactory factory = new Geo3dSpatialContextFactory();
- factory.planetModel = planetModel;
- this.ctx = factory.newSpatialContext();
- }
-
- @Test
- public void testFailure1() {
- final GeoBBox rect =
- GeoBBoxFactory.makeGeoBBox(
- planetModel,
- 88 * RADIANS_PER_DEGREE,
- 30 * RADIANS_PER_DEGREE,
- -30 * RADIANS_PER_DEGREE,
- 62 * RADIANS_PER_DEGREE);
- final List<GeoPoint> points = new ArrayList<>();
- points.add(
- new GeoPoint(
- planetModel, 30.4579218227 * RADIANS_PER_DEGREE, 14.5238410082 * RADIANS_PER_DEGREE));
- points.add(
- new GeoPoint(
- planetModel, 43.684447915 * RADIANS_PER_DEGREE, 46.2210986329 * RADIANS_PER_DEGREE));
- points.add(
- new GeoPoint(
- planetModel, 66.2465299717 * RADIANS_PER_DEGREE, -29.1786158537 * RADIANS_PER_DEGREE));
- final GeoShape path = GeoPolygonFactory.makeGeoPolygon(planetModel, points);
-
- final GeoPoint point =
- new GeoPoint(
- planetModel,
- 34.2730264413182 * RADIANS_PER_DEGREE,
- 82.75500168892472 * RADIANS_PER_DEGREE);
-
- // Apparently the rectangle thinks the polygon is completely within it... "shape inside
- // rectangle"
- assertTrue(GeoArea.WITHIN == rect.getRelationship(path));
-
- // Point is within path? Apparently not...
- assertFalse(path.isWithin(point));
-
- // If it is within the path, it must be within the rectangle, and similarly visa versa
- assertFalse(rect.isWithin(point));
- }
-
- @Test
- public void testFailure2_LUCENE6475() {
- GeoCircle geo3dCircle =
- GeoCircleFactory.makeGeoCircle(
- planetModel,
- 1.6282053147165243E-4 * RADIANS_PER_DEGREE,
- -70.1600629789353 * RADIANS_PER_DEGREE,
- 86 * RADIANS_PER_DEGREE);
- Geo3dShape<GeoCircle> geo3dShape = new Geo3dShape<>(geo3dCircle, ctx);
- Rectangle rect = ctx.getShapeFactory().rect(-118, -114, -2.0, 32.0);
- assertTrue(geo3dShape.relate(rect).intersects());
- // thus the bounding box must intersect too
- assertTrue(geo3dShape.getBoundingBox().relate(rect).intersects());
- }
-
- @Test
- public void pointBearingTest() {
- double radius = 136;
- double distance = 135.97;
- double bearing = 188;
- Point p = ctx.getShapeFactory().pointXY(35, 85);
- Circle circle = ctx.getShapeFactory().circle(p, radius);
- Point bPoint = ctx.getDistCalc().pointOnBearing(p, distance, bearing, ctx, (Point) null);
-
- double d = ctx.getDistCalc().distance(p, bPoint);
- assertEquals(d, distance, 10 - 8);
-
- assertEquals(circle.relate(bPoint), SpatialRelation.CONTAINS);
- }
-}
--- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/spatial4j/TestGeo3dShapeWGS84ModelRectRelation.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.spatial.spatial4j;
-
-import com.carrotsearch.randomizedtesting.generators.RandomPicks;
-import org.apache.lucene.spatial3d.geom.GeoArea;
-import org.apache.lucene.spatial3d.geom.GeoBBox;
-import org.apache.lucene.spatial3d.geom.GeoBBoxFactory;
-import org.apache.lucene.spatial3d.geom.GeoCircle;
-import org.apache.lucene.spatial3d.geom.GeoCircleFactory;
-import org.apache.lucene.spatial3d.geom.GeoPath;
-import org.apache.lucene.spatial3d.geom.GeoPathFactory;
-import org.apache.lucene.spatial3d.geom.GeoPoint;
-import org.apache.lucene.spatial3d.geom.PlanetModel;
-import org.junit.Test;
-import org.locationtech.spatial4j.shape.Circle;
-import org.locationtech.spatial4j.shape.Point;
-import org.locationtech.spatial4j.shape.SpatialRelation;
-
-public class TestGeo3dShapeWGS84ModelRectRelation extends ShapeRectRelationTestCase {
-
- PlanetModel planetModel =
- RandomPicks.randomFrom(
- random(), new PlanetModel[] {PlanetModel.WGS84, PlanetModel.CLARKE_1866});
-
- public TestGeo3dShapeWGS84ModelRectRelation() {
- Geo3dSpatialContextFactory factory = new Geo3dSpatialContextFactory();
- factory.planetModel = planetModel;
- this.ctx = factory.newSpatialContext();
- this.maxRadius = 175;
- ((Geo3dShapeFactory) ctx.getShapeFactory()).setCircleAccuracy(1e-12);
- }
-
- @Test
- public void testFailure1() {
- final GeoBBox rect =
- GeoBBoxFactory.makeGeoBBox(
- planetModel,
- 90 * RADIANS_PER_DEGREE,
- 74 * RADIANS_PER_DEGREE,
- 40 * RADIANS_PER_DEGREE,
- 60 * RADIANS_PER_DEGREE);
- final GeoPoint[] pathPoints =
- new GeoPoint[] {
- new GeoPoint(
- planetModel, 84.4987594274 * RADIANS_PER_DEGREE, -22.8345484402 * RADIANS_PER_DEGREE)
- };
- final GeoPath path =
- GeoPathFactory.makeGeoPath(planetModel, 4 * RADIANS_PER_DEGREE, pathPoints);
- assertTrue(GeoArea.DISJOINT == rect.getRelationship(path));
- // This is what the test failure claimed...
- // assertTrue(GeoArea.CONTAINS == rect.getRelationship(path));
- // final GeoBBox bbox = getBoundingBox(path);
- // assertFalse(GeoArea.DISJOINT == rect.getRelationship(bbox));
- }
-
- @Test
- public void testFailure2() {
- final GeoBBox rect =
- GeoBBoxFactory.makeGeoBBox(
- planetModel,
- -74 * RADIANS_PER_DEGREE,
- -90 * RADIANS_PER_DEGREE,
- 0 * RADIANS_PER_DEGREE,
- 26 * RADIANS_PER_DEGREE);
- final GeoCircle circle =
- GeoCircleFactory.makeGeoCircle(
- planetModel,
- -87.3647352103 * RADIANS_PER_DEGREE,
- 52.3769709972 * RADIANS_PER_DEGREE,
- 1 * RADIANS_PER_DEGREE);
- assertTrue(GeoArea.DISJOINT == rect.getRelationship(circle));
- // This is what the test failure claimed...
- // assertTrue(GeoArea.CONTAINS == rect.getRelationship(circle));
- // final GeoBBox bbox = getBoundingBox(circle);
- // assertFalse(GeoArea.DISJOINT == rect.getRelationship(bbox));
- }
-
- @Test
- public void testFailure3() {
- /*
- [junit4] 1> S-R Rel: {}, Shape {}, Rectangle {} lap# {} [CONTAINS, Geo3dShape{planetmodel=PlanetModel: {xyScaling=1.0011188180710464, zScaling=0.9977622539852008}, shape=GeoPath: {planetmodel=PlanetModel: {xyScaling=1.0011188180710464, zScaling=0.9977622539852008}, width=1.53588974175501(87.99999999999999),
- points={[[X=0.12097657665150223, Y=-0.6754177666095532, Z=0.7265376136709238], [X=-0.3837892785614207, Y=0.4258049113530899, Z=0.8180007850434892]]}}},
- Rect(minX=4.0,maxX=36.0,minY=16.0,maxY=16.0), 6981](no slf4j subst; sorry)
- [junit4] FAILURE 0.59s | Geo3dWGS84ShapeRectRelationTest.testGeoPathRect <<<
- [junit4] > Throwable #1: java.lang.AssertionError: Geo3dShape{planetmodel=PlanetModel: {xyScaling=1.0011188180710464, zScaling=0.9977622539852008}, shape=GeoPath: {planetmodel=PlanetModel: {xyScaling=1.0011188180710464, zScaling=0.9977622539852008}, width=1.53588974175501(87.99999999999999),
- points={[[X=0.12097657665150223, Y=-0.6754177666095532, Z=0.7265376136709238], [X=-0.3837892785614207, Y=0.4258049113530899, Z=0.8180007850434892]]}}} intersect Pt(x=23.81626064835212,y=16.0)
- [junit4] > at __randomizedtesting.SeedInfo.seed([2595268DA3F13FEA:6CC30D8C83453E5D]:0)
- [junit4] > at org.apache.lucene.spatial.spatial4j.RandomizedShapeTestCase._assertIntersect(RandomizedShapeTestCase.java:168)
- [junit4] > at org.apache.lucene.spatial.spatial4j.RandomizedShapeTestCase.assertRelation(RandomizedShapeTestCase.java:153)
- [junit4] > at org.apache.lucene.spatial.spatial4j.RectIntersectionTestHelper.testRelateWithRectangle(RectIntersectionTestHelper.java:128)
- [junit4] > at org.apache.lucene.spatial.spatial4j.Geo3dWGS84ShapeRectRelationTest.testGeoPathRect(Geo3dWGS84ShapeRectRelationTest.java:265)
- */
- final GeoBBox rect =
- GeoBBoxFactory.makeGeoBBox(
- planetModel,
- 16 * RADIANS_PER_DEGREE,
- 16 * RADIANS_PER_DEGREE,
- 4 * RADIANS_PER_DEGREE,
- 36 * RADIANS_PER_DEGREE);
- final GeoPoint[] pathPoints =
- new GeoPoint[] {
- new GeoPoint(
- planetModel, 46.6369060853 * RADIANS_PER_DEGREE, -79.8452213228 * RADIANS_PER_DEGREE),
- new GeoPoint(
- planetModel, 54.9779334519 * RADIANS_PER_DEGREE, 132.029177424 * RADIANS_PER_DEGREE)
- };
- final GeoPath path =
- GeoPathFactory.makeGeoPath(planetModel, 88 * RADIANS_PER_DEGREE, pathPoints);
- System.out.println("rect=" + rect);
- // Rectangle is within path (this is wrong; it's on the other side. Should be OVERLAPS)
- assertTrue(GeoArea.OVERLAPS == rect.getRelationship(path));
- // Rectangle contains point
- // assertTrue(rect.isWithin(pt));
- // Path contains point (THIS FAILS)
- // assertTrue(path.isWithin(pt));
- // What happens: (1) The center point of the horizontal line is within the path, in fact within
- // a radius of one of the endpoints.
- // (2) The point mentioned is NOT inside either SegmentEndpoint.
- // (3) The point mentioned is NOT inside the path segment, either. (I think it should be...)
- }
-
- @Test
- public void pointBearingTest() {
- double radius = 136;
- double distance = 135.97;
- double bearing = 188;
- Point p = ctx.getShapeFactory().pointXY(35, 85);
- Circle circle = ctx.getShapeFactory().circle(p, radius);
- Point bPoint = ctx.getDistCalc().pointOnBearing(p, distance, bearing, ctx, (Point) null);
-
- double d = ctx.getDistCalc().distance(p, bPoint);
- assertEquals(d, distance, 10 - 8);
-
- assertEquals(circle.relate(bPoint), SpatialRelation.CONTAINS);
- }
-
- // very slow, test sources are not all here, no clue how to fix it
- @Nightly
- @Override
- public void testGeoCircleRect() {
- super.testGeoCircleRect();
- }
-
- // very slow, test sources are not all here, no clue how to fix it
- @Nightly
- @Override
- public void testGeoPolygonRect() {
- super.testGeoPolygonRect();
- }
-
- // very slow, test sources are not all here, no clue how to fix it
- @Nightly
- @Override
- public void testGeoPathRect() {
- super.testGeoPathRect();
- }
-}
|