Skip to content

Commit 0194182

Browse files
committed
Ignore sun packages when importing full classpath
resolves #1446 The CI build has recently often failed on `ubuntu` and `macos` with Java 8, due to `java.lang.OutOfMemoryError: GC overhead limit exceeded`. This is due to `ClassFileImporterSlowTest` importing the full classpath in some tests, which gives more than 20k classes on Java 8, which contains 7k classes in `com.sun` and 4k classes in `sun` packages that can easily be ignored. Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
1 parent 70cab88 commit 0194182

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

archunit/src/test/java/com/tngtech/archunit/core/importer/ClassFileImporterSlowTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535

3636
@Category(Slow.class)
3737
public class ClassFileImporterSlowTest {
38+
/**
39+
* Importing the full classpath may give thousands of classes in {@link sun} and (especially for Java 8) {@link com.sun} packages.
40+
* Importing those would increase the memory footprint of the test tremendously, but not give an additional benefit for the test,
41+
* so they are excluded for convenience.
42+
*/
43+
private static final ImportOption EXCLUDE_SUN_PACKAGES = l -> !l.contains("/sun/");
44+
3845
@Rule
3946
public final TransientCopyRule copyRule = new TransientCopyRule();
4047
@Rule
@@ -53,6 +60,7 @@ public void imports_the_classpath_without_archives() {
5360
assertThatTypes(classes).doNotContain(File.class); // Default does not import JDK classes
5461

5562
classes = new ClassFileImporter()
63+
.withImportOption(EXCLUDE_SUN_PACKAGES)
5664
.withImportOption(importJavaBaseOrRtAndJUnitJarAndFilesOnTheClasspath())
5765
.importClasspath();
5866

@@ -73,10 +81,12 @@ public void imports_the_classpath_using_multiple_ImportOptions() {
7381
@Test
7482
public void importing_the_default_package_equals_importing_the_classpath() {
7583
Set<String> classNamesOfDefaultPackageImport = new ClassFileImporter()
84+
.withImportOption(EXCLUDE_SUN_PACKAGES)
7685
.withImportOption(importJavaBaseOrRtAndJUnitJarAndFilesOnTheClasspath())
7786
.importPackages("")
7887
.stream().map(JavaClass::getName).collect(toSet());
7988
Set<String> classNamesOfClasspathImport = new ClassFileImporter()
89+
.withImportOption(EXCLUDE_SUN_PACKAGES)
8090
.withImportOption(importJavaBaseOrRtAndJUnitJarAndFilesOnTheClasspath())
8191
.importClasspath()
8292
.stream().map(JavaClass::getName).collect(toSet());
@@ -180,6 +190,7 @@ public void creates_JavaPackages() {
180190

181191
private JavaClasses importJavaBase() {
182192
return new ClassFileImporter()
193+
.withImportOption(EXCLUDE_SUN_PACKAGES)
183194
.withImportOption(location ->
184195
// before Java 9 packages like java.lang were in rt.jar
185196
location.contains("rt.jar") ||

0 commit comments

Comments
 (0)