Skip to content

Commit

Permalink
Add ability to control which classes are cloned
Browse files Browse the repository at this point in the history
This can interfere with other JUnit exists, such
as Pact.

Relates to quarkusio#9677
  • Loading branch information
stuartwdouglas committed May 18, 2021
1 parent 05126ae commit c9c43dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ public class TestConfig {
@ConfigItem(defaultValue = "all")
TestType type;

/**
* If a class matches this pattern then it wil be cloned into the Quarkus ClassLoader even if it
* is a parent first artifact.
*
* This is important for collections which can contain objects from the Quarkus ClassLoader, but for
* most parent first classes it will just cause problems.
*/
@ConfigItem(defaultValue = "java.*")
String classClonePattern;

@ConfigGroup
public static class Profile {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.enterprise.inject.Alternative;
Expand Down Expand Up @@ -950,8 +951,16 @@ private Object runExtensionMethod(ReflectiveInvocationContext<Method> invocation
// because the test method runs from a class loaded from the TCCL
List<Object> originalArguments = invocationContext.getArguments();
List<Object> argumentsFromTccl = new ArrayList<>();
String patternString = runningQuarkusApplication.getConfigValue("quarkus.test.class-clone-pattern", String.class)
.orElse("java.*");
Pattern clonePattern = Pattern.compile(patternString);
for (Object arg : originalArguments) {
argumentsFromTccl.add(deepClone.clone(arg));
if (arg.getClass().getClassLoader() instanceof QuarkusClassLoader
|| clonePattern.matcher(arg.getClass().getName()).matches()) {
argumentsFromTccl.add(deepClone.clone(arg));
} else {
argumentsFromTccl.add(arg);
}
}

return newMethod.invoke(actualTestInstance, argumentsFromTccl.toArray(new Object[0]));
Expand Down

0 comments on commit c9c43dd

Please sign in to comment.