sbabcoc / JUnit-Foundation

JUnit Foundation is a lightweight collection of JUnit watchers, interfaces, and static utility classes that supplement and augment the functionality provided by the JUnit API.
Apache License 2.0
22 stars 6 forks source link

Upgrade bytebuddy dependency to support Java 11 #19

Closed yohlulz closed 5 years ago

yohlulz commented 6 years ago

Hi there,

First of all, nice work with this tool.

I tried running it against some Java 11 compiled code (using gradle) but encountered some issues:

Starting process 'Gradle Test Executor 3507'. Command: /usr/java/jdk11/bin/java -Djunit.max.retry=2 -Djunit.timeout.test=500 -Dorg.gradle.native=false -javaagent:/home/ovidiu/.gradle/caches/modules-2/files-2.1/com.nordstrom.tools/junit-foundation/6.1.4/1f6ea951c06fb8a19ba0e59408a4ca7a82e34d50/junit-foundation-6.1.4.jar -javaagent:/home/ovidiu/.gradle/caches/modules-2/files-2.1/org.jmockit/jmockit/1.28/3efdc615563d9fe2ebb29690cae1f33d1187cee6/jmockit-1.28.jar @/tmp/gradle-worker-classpath7097349747053025687txt -Xms256m -Xmx1g -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 3507'
Successfully started process 'Gradle Test Executor 3506'
Successfully started process 'Gradle Test Executor 3507'
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513)
        at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525)
Caused by: java.lang.NoSuchMethodError: net.bytebuddy.pool.TypePool$Default.ofClassPath()Lnet/bytebuddy/pool/TypePool;
        at com.nordstrom.automation.junit.LifecycleHooks.installTransformer(LifecycleHooks.java:74)
        at com.nordstrom.automation.junit.LifecycleHooks.premain(LifecycleHooks.java:64)
        ... 6 more
FATAL ERROR in native method: processing of -javaagent failed

$ less /tmp/gradle-worker-classpath7097349747053025687txt | grep -e byte -e foundation
/home/ovidiu/.gradle/caches/modules-2/files-2.1/com.nordstrom.tools/junit-foundation/6.1.4/1f6ea951c06fb8a19ba0e59408a4ca7a82e34d50/junit-foundation-6.1.4.jar
/home/ovidiu/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy/1.9.3/f32e510b239620852fc9a2387fac41fd053d6a4d/byte-buddy-1.9.3.jar
/home/ovidiu/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy-agent/1.9.3/f5b78c16cf4060664d80b6ca32d80dca4bd3d264/byte-buddy-agent-1.9.3.jar

From a quick look over the bytebuddy changes I found this one: https://github.com/raphw/byte-buddy/commit/8cc6f79e36de51b41aad0ba8043c3cdfe603f03f#diff-6e2e25e8562b392b2b4f72c4648289bd

Tried a quick fix locally (I can do a PR if needed as well) upgrade_bytebuddy.txt

Regards, Ovidiu

sbabcoc commented 5 years ago

@yohlulz -Thanks for the diffs! I could apply these myself. However, if you fork this repository and submit a PR, I'll be happy to merge the changes and publish a new release. That way, you get the contribution credit. Your choice... let me know.

sbabcoc commented 5 years ago

@yohlulz - By the way, how did you find this project?

sbabcoc commented 5 years ago

@yohlulz - I just did a bit of digging, and the name of that Byte Buddy method changed from ofClassPath to ofSystemLoader. I think this is the one to use. https://github.com/raphw/byte-buddy/commit/8cc6f79e36de51b41aad0ba8043c3cdfe603f03f

sbabcoc commented 5 years ago

Another option would be to avoid the version-specific compatibility problem with reflection. Not my first choice, but it certainly wouldn't be the only reflection code in this library.

yohlulz commented 5 years ago

I found this cool project while searching for a way to enforce a timeout for each unit test in a rather large code base. Submitted a pull request for it #20

sbabcoc commented 5 years ago

@yohlulz Thanks! I've made substantial changes over the last month, based on insights gained from the Report Portal project. I re-implemented the JUnit 4 agent and discovered I hadn't properly handled parameterized tests or parallel execution. I think I have both of these working now, and I'm very happy with the improvements.