forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert quarkusio#40601 and disable tests enabled by quarkusio…
…#40749" This reverts commit fc3988b. It has some additional changes which re-revert part of quarkusio#40601, to reintroduce removed guards to avoid cloning things like Quarkus runtime classes. Otherwise we get test failures.
- Loading branch information
1 parent
c20fa84
commit 86e8afb
Showing
13 changed files
with
127 additions
and
352 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
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
63 changes: 0 additions & 63 deletions
63
test-framework/junit5/src/main/java/io/quarkus/test/junit/internal/CustomListConverter.java
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
test-framework/junit5/src/main/java/io/quarkus/test/junit/internal/CustomMapConverter.java
This file was deleted.
Oops, something went wrong.
55 changes: 0 additions & 55 deletions
55
...ramework/junit5/src/main/java/io/quarkus/test/junit/internal/CustomMapEntryConverter.java
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
test-framework/junit5/src/main/java/io/quarkus/test/junit/internal/CustomSetConverter.java
This file was deleted.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
...ramework/junit5/src/main/java/io/quarkus/test/junit/internal/NewSerializingDeepClone.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,113 @@ | ||
package io.quarkus.test.junit.internal; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.io.UncheckedIOException; | ||
import java.lang.reflect.Method; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
import org.jboss.marshalling.cloner.ClassCloner; | ||
import org.jboss.marshalling.cloner.ClonerConfiguration; | ||
import org.jboss.marshalling.cloner.ObjectCloner; | ||
import org.jboss.marshalling.cloner.ObjectCloners; | ||
import org.junit.jupiter.api.TestInfo; | ||
|
||
/** | ||
* A deep-clone implementation using JBoss Marshalling's fast object cloner. | ||
*/ | ||
public final class NewSerializingDeepClone implements DeepClone { | ||
private final ObjectCloner cloner; | ||
|
||
public NewSerializingDeepClone(final ClassLoader sourceLoader, final ClassLoader targetLoader) { | ||
ClonerConfiguration cc = new ClonerConfiguration(); | ||
cc.setSerializabilityChecker(clazz -> clazz != Object.class); | ||
cc.setClassCloner(new ClassCloner() { | ||
public Class<?> clone(final Class<?> original) { | ||
if (isUncloneable(original)) { | ||
return original; | ||
} | ||
try { | ||
return targetLoader.loadClass(original.getName()); | ||
} catch (ClassNotFoundException ignored) { | ||
return original; | ||
} | ||
} | ||
|
||
public Class<?> cloneProxy(final Class<?> proxyClass) { | ||
// not really supported | ||
return proxyClass; | ||
} | ||
}); | ||
cc.setCloneTable( | ||
(original, objectCloner, classCloner) -> { | ||
if (EXTRA_IDENTITY_CLASSES.contains(original.getClass())) { | ||
// avoid copying things that do not need to be copied | ||
return original; | ||
} else if (isUncloneable(original.getClass())) { | ||
if (original instanceof Supplier<?> s) { | ||
// sneaky | ||
return (Supplier<?>) () -> clone(s.get()); | ||
} else { | ||
return original; | ||
} | ||
} else if (original instanceof TestInfo info) { | ||
// copy the test info correctly | ||
return new TestInfoImpl(info.getDisplayName(), info.getTags(), | ||
info.getTestClass().map(this::cloneClass), | ||
info.getTestMethod().map(this::cloneMethod)); | ||
} else if (original == sourceLoader) { | ||
return targetLoader; | ||
} | ||
// let the default cloner handle it | ||
return null; | ||
}); | ||
cloner = ObjectCloners.getSerializingObjectClonerFactory().createCloner(cc); | ||
} | ||
|
||
private static boolean isUncloneable(Class<?> clazz) { | ||
return clazz.isHidden() && !Serializable.class.isAssignableFrom(clazz); | ||
} | ||
|
||
private Class<?> cloneClass(Class<?> clazz) { | ||
try { | ||
return (Class<?>) cloner.clone(clazz); | ||
} catch (IOException | ClassNotFoundException e) { | ||
return null; | ||
} | ||
} | ||
|
||
private Method cloneMethod(Method method) { | ||
try { | ||
Class<?> declaring = (Class<?>) cloner.clone(method.getDeclaringClass()); | ||
Class<?>[] argTypes = (Class<?>[]) cloner.clone(method.getParameterTypes()); | ||
return declaring.getDeclaredMethod(method.getName(), argTypes); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
} | ||
|
||
public Object clone(final Object objectToClone) { | ||
try { | ||
return cloner.clone(objectToClone); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} catch (ClassNotFoundException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Classes which do not need to be cloned. | ||
*/ | ||
private static final Set<Class<?>> EXTRA_IDENTITY_CLASSES = Set.of( | ||
Object.class, | ||
byte[].class, | ||
short[].class, | ||
int[].class, | ||
long[].class, | ||
char[].class, | ||
boolean[].class, | ||
float[].class, | ||
double[].class); | ||
} |
Oops, something went wrong.