-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
only import necessary classes when discovering tests from classpath
The JUnit platform API makes it necessary for ArchUnit to provide an implementation to discover test classes from the classpath (e.g. because the discovery request contains a package selector). Since ArchUnit itself is perfectly suited for this and does not demand any third party dependency we simply use the `ClassFileImporter` for this. However, so far we have used the current `ArchConfiguration` of the user, which by default e.g. resolves all further dependencies from the classpath. This is unnecessary overhead and can substantially slow down the discovery process if the test classes e.g. have some framework dependencies like the Spring framework. We will now switch the `ArchConfiguration` for the discovery process. However, the global nature of `ArchConfiguration` does not make this completely trivial. E.g. if the user has another import in progress in another thread we do not want to affect this import by suddenly switching the user's configuration in the middle. To isolate this configuration change I have added a possibility to override the `ArchConfiguration` thread locally. I.e. the discovery process will only affect the current thread when changing the configuration and only during the scope of a fixed lambda. Afterwards the thread local configuration is cleaned up. This way we should never affect any other import of a user, since the scope of configuration change is tailored exactly to the discovery process and cleaned up afterwards. Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
- Loading branch information
1 parent
9592a43
commit f818be3
Showing
9 changed files
with
389 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...t/junit5/engine/src/test/java/com/tngtech/archunit/junit/internal/testutil/LogCaptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.tngtech.archunit.junit.internal.testutil; | ||
|
||
import java.util.List; | ||
|
||
import com.tngtech.archunit.testutil.TestLogRecorder; | ||
import com.tngtech.archunit.testutil.TestLogRecorder.RecordedLogEvent; | ||
import org.apache.logging.log4j.Level; | ||
|
||
public class LogCaptor { | ||
private final TestLogRecorder logRecorder = new TestLogRecorder(); | ||
|
||
public void watch(Class<?> loggerClass, Level level) { | ||
logRecorder.record(loggerClass, level); | ||
} | ||
|
||
public void cleanUp() { | ||
logRecorder.reset(); | ||
} | ||
|
||
public List<RecordedLogEvent> getEvents(Level level) { | ||
return logRecorder.getEvents(level); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...5/engine/src/test/java/com/tngtech/archunit/junit/internal/testutil/TestLogExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.tngtech.archunit.junit.internal.testutil; | ||
|
||
import org.junit.jupiter.api.extension.AfterEachCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.ParameterContext; | ||
import org.junit.jupiter.api.extension.ParameterResolutionException; | ||
import org.junit.jupiter.api.extension.ParameterResolver; | ||
|
||
public class TestLogExtension implements ParameterResolver, AfterEachCallback { | ||
private final LogCaptor logCaptor = new LogCaptor(); | ||
|
||
@Override | ||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { | ||
return LogCaptor.class.equals(parameterContext.getParameter().getType()); | ||
} | ||
|
||
@Override | ||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { | ||
return logCaptor; | ||
} | ||
|
||
@Override | ||
public void afterEach(ExtensionContext context) { | ||
logCaptor.cleanUp(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.