mloayzagahona / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

Test mechanism failure, failed to clean up state under Eclipse PDE #309

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run a JUnit test case with @PowerMockRunner as Eclipse PDE plugin test.

What is the expected output? What do you see instead?
Expected to see test run successfully. Test ran, but post test failure from 
PowerMock clean up.

What version of the product are you using? On what operating system?
PowerMock 1.4.7
EasyMock 3.0
Eclipse 3.5
Windows XP
Java 1.6

Please provide any additional information below.
Stack trace is attached.

Key lines in the trace:
java.lang.RuntimeException: Failed to clean up state
        at org.powermock.api.easymock.PowerMock$EasyMockStateCleaner.invokeReportLastControlFromSystemCL(PowerMock.java:2310)
        at org.powermock.api.easymock.PowerMock$EasyMockStateCleaner.run(PowerMock.java:2298)
        at org.powermock.core.MockRepository.clear(MockRepository.java:125)
        at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
...
org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(WorkbenchTestable.java:7
1)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: org.easymock.internal.LastControl
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at org.powermock.api.easymock.PowerMock$EasyMockStateCleaner.invokeReportLastControlFromSystemCL(PowerMock.java:2304)
        ... 30 more

I suspect that the OSGi class loading framework is not compatible with the 
technique being used in test finish method to clean up EasyMock state.

Original issue reported on code.google.com by dmeibu...@gmail.com on 25 Jan 2011 at 6:34

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for reporting. Could you please attach a small example that demonstrates 
the issue? Otherwise it's hard to debug and to know when it's fixed (I don't 
even have Eclipse anymore).

Original comment by johan.ha...@gmail.com on 10 Feb 2011 at 7:07

GoogleCodeExporter commented 9 years ago
I can reproduce the problem with running powermock with maven/tycho, which 
spawns a new OSGi runtime for the tests. 

Original comment by sesam...@googlemail.com on 7 Apr 2011 at 10:57

GoogleCodeExporter commented 9 years ago
The problem is that in an OSGI envoronment the LastControl.class and the 
MocksControl.class are not loaded by the current or the system class loader, 
but by the class loader of the bundle the classes are into. It may help to use:

...
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final Class<?> lastControlClassBySystemCL = 
Class.forName(LastControl.class.getName(), true, classLoader);
                final Class<?> mocksControlClassBySystemCL = Class.forName(MocksControl.class.getName(), true, classLoader);
...

Original comment by sesam...@googlemail.com on 7 Apr 2011 at 11:11

GoogleCodeExporter commented 9 years ago
It might help but it's hard for me to verify it without help. If I commit it to 
trunk could you build PowerMock from source (it's easy, mvn clean install will 
work) and give it a try in your project?

Original comment by johan.ha...@gmail.com on 7 Apr 2011 at 11:29

GoogleCodeExporter commented 9 years ago
I'd forgotten this was our blocker for upgrading version of PowerMock. If you 
commit changes, I can test it. I have a trunk checkout already and have built 
many times before.

Original comment by dmeibu...@gmail.com on 7 Apr 2011 at 1:03

GoogleCodeExporter commented 9 years ago
Awesome. I'll try to find time to try it out it later this evening.

Original comment by johan.ha...@gmail.com on 7 Apr 2011 at 1:18

GoogleCodeExporter commented 9 years ago
I've committed the changes to trunk now. Please verify if it solves the problem 
for you.

Original comment by johan.ha...@gmail.com on 7 Apr 2011 at 8:29

GoogleCodeExporter commented 9 years ago
I have the same issue when running a test through an Ant-script. Instead of 
building successful it says "build failed" with a similar stack trace (due to 
PowerMock clean up).

I made my 1st PowerMock-built from the trunk, replaced the 1.4.8.jar with the 
newly built jar and ran the Ant-script again. Now the script runs successfully, 
so problem is solved (for me).

Original comment by roel.de.nijs@gmail.com on 11 Apr 2011 at 11:23

GoogleCodeExporter commented 9 years ago
Great! Thanks for helping out.

Original comment by johan.ha...@gmail.com on 11 Apr 2011 at 11:54

GoogleCodeExporter commented 9 years ago
I'm closing the issue now.

Original comment by johan.ha...@gmail.com on 11 Apr 2011 at 8:26