jmockit / jmockit1

Advanced Java library for integration testing, mocking, faking, and code coverage
Other
465 stars 240 forks source link

Cannot use Attach API on unknown OS - jMockit via gradle on TeamCity issue #256

Closed radekkozak closed 8 years ago

radekkozak commented 8 years ago

Trying to build project with jMockit & TestNG via gradle. Locally everything is working great. Exactly the same thing going through TeamCity is somehow messed up. It seems that jMockit cannot execute properly setup method which has @BeforeClass annotation. To be fair it won't work with junit annotation either when setting things up before executing tests. Here's the part of listing that i'm mostly concerned about:

Caused by: java.lang.IllegalStateException: Cannot use Attach API on unknown OS: FreeBSD at mockit.internal.startup.AgentLoader.findVirtualMachineClassAccordingToOS(AgentLoader.java:103) at mockit.internal.startup.AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(AgentLoader.java:62) at mockit.internal.startup.AgentLoader.loadAgent(AgentLoader.java:45) at mockit.internal.startup.Startup.verifyInitialization(Startup.java:172) at mockit.MockUp.(MockUp.java:94)

[All tests] pl.greyfox.junit.AddressRetrieverTest.setUp
[18:28:36][pl.greyfox.junit.AddressRetrieverTest.setUp] null
[18:28:36]
[pl.greyfox.junit.AddressRetrieverTest.setUp] java.lang.ExceptionInInitializerError
    at pl.greyfox.junit.AddressRetrieverTest.setUp(AddressRetrieverTest.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.access$000(SuiteRunner.java:39)
    at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:400)
    at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Cannot use Attach API on unknown OS: FreeBSD
    at mockit.internal.startup.AgentLoader.findVirtualMachineClassAccordingToOS(AgentLoader.java:103)
    at mockit.internal.startup.AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(AgentLoader.java:62)
    at mockit.internal.startup.AgentLoader.loadAgent(AgentLoader.java:45)
    at mockit.internal.startup.Startup.verifyInitialization(Startup.java:172)
    at mockit.MockUp.<clinit>(MockUp.java:94)
rliesenfeld commented 8 years ago

Does it work if sun.tools.attach.BsdVirtualMachine is used when "os.name" = "FreeBSD"? I can easily make this change in AgentLoader.java (at line 96), but I won't be able to test it.

radekkozak commented 8 years ago

Yup, i hotswapped and patched AgentLoader and i can confirm adding simple || osName.startsWith("FreeBSD") at line 96 along Mac OS X option does the trick. It would be great if you could ammend this yourself in your codebase - no need for MR for such trivial change i think. I'll use my monkey patch for the time being. Let me know when it's done.

Appreciate it