Thoppan / powermock

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

Unit Test initialization Error when unit testing MongoDB Java Driver #277

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a class that uses MongoDB Java Driver v2.1
2. Create a unit test for class that uses MongoDB
3. Run unit test

What is the expected output? What do you see instead?
Test execution successful

What version of the product are you using? On what operating system?
Linux, powermock-mockito-1.4

Please provide any additional information below.
I've attached an eclipse project that I was able to reproduce the issue with.

Stack Trace.
java.lang.LinkageError: loader constraint violation: loader (instance of 
org/powermock/core/classloader/MockClassLoader) previously initiated loading 
for a different type with name "javax/management/MBeanServer"
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:466)
    at org.powermock.core.classloader.MockClassLoader.loadUnmockedClass(MockClassLoader.java:190)
    at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:148)
    at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:65)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at com.mongodb.DBPortPool$Holder.get(DBPortPool.java:58)
    at com.mongodb.DBTCPConnector._set(DBTCPConnector.java:458)
    at com.mongodb.DBTCPConnector.<init>(DBTCPConnector.java:46)
    at com.mongodb.Mongo.<init>(Mongo.java:137)
    at com.mongodb.Mongo.<init>(Mongo.java:123)
    at com.mongodb.Mongo.<init>(Mongo.java:113)

Original issue reported on code.google.com by kevin.ki...@gmail.com on 3 Sep 2010 at 12:40

Attachments:

GoogleCodeExporter commented 9 years ago
I've seen several reports of this kind lately. It could be a Javassist issue 
actually and in that case we'll have to wait until the next version of 
Javassist to be released and hope that they've fixed it. It would be of great 
interest for us if you could try to run the code in PowerMock 1.3.9 with 
Javassist 3.13 and see if it makes any difference? It could also be a problem 
that MongoDB instantiates classes using reflection with a different 
classloader. You could try to make use of the @PowerMockIgnore annotation to 
see if you can get around it. For example try using 
@PowerMockIgnore("javax.management.MBeanServer").

Original comment by johan.ha...@gmail.com on 12 Sep 2010 at 2:51

GoogleCodeExporter commented 9 years ago
should some one familiar with powermock and Javassist fix it? We all bocked at 
this issue.
Thank you very much.

Original comment by yishi...@gmail.com on 8 Oct 2010 at 3:09

GoogleCodeExporter commented 9 years ago
Hmm I think I was a bit fast blaming Javassist. I think it must be an error in 
the MockClassloader. Could you try using @PowerMockIgnore("javax.management.*")?

Original comment by johan.ha...@gmail.com on 8 Oct 2010 at 5:42

GoogleCodeExporter commented 9 years ago
I have found the same problem and [@PowerMockIgnore("javax.management.*")] 
solves it.

Original comment by Cesar.Al...@gmail.com on 28 Oct 2010 at 5:42

GoogleCodeExporter commented 9 years ago
Thanks a lot for sharing!

Original comment by johan.ha...@gmail.com on 28 Oct 2010 at 6:40

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 15 Nov 2010 at 7:48

GoogleCodeExporter commented 9 years ago
Thanks, my problem is solved with @PowerMockIgnore("javax.management.*")

Original comment by ranjith1...@gmail.com on 28 Sep 2012 at 4:49

GoogleCodeExporter commented 9 years ago
Yeah.  I also found that this worked to fix the same issue: 
@PowerMockIgnore("javax.management.*").

Although note that in Scala, the syntax is slightly different for all of the 
class annotations:

@RunWith(classOf[PowerMockRunner])
@PrepareForTest(Array(classOf[Broker]))
@PowerMockIgnore(Array("javax.management.*"))

Original comment by aram.ope...@gmail.com on 1 Nov 2012 at 2:11

GoogleCodeExporter commented 9 years ago
I have a similar problem. The difference for me is that it is causing an error 
in a logback-classic class. The result is that my tests still run and pass, but 
errors are reported.

`@PowerMockIgnore("javax.management.*")` with my other test class annotations 
fixes it for me too!

I'll attach my error log in case it is helpful for anyone here.

Original comment by StatueOf...@gmail.com on 14 Jan 2015 at 12:47

Attachments:

GoogleCodeExporter commented 9 years ago
Is my error, from https://code.google.com/p/powermock/issues/detail?id=277#c9
A separate issue? Should I make a new ticket for it?

Original comment by StatueOf...@gmail.com on 14 Jan 2015 at 1:06