Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Cannot instrument static methods #5

Open
CappCorp opened this issue Apr 15, 2015 · 4 comments
Open

Cannot instrument static methods #5

CappCorp opened this issue Apr 15, 2015 · 4 comments

Comments

@CappCorp
Copy link

Hi,

I tried getting information regarding this but could not find any. It seems I cannot instrument static methods to test them with thread weaver.

Here is a basic example of what I try to achieve:

public class DoClass {
    public static void doTheThing() {
        System.out.println("do");
    }
}
public class DoClassTest {
    @ThreadedBefore
    public void before() {}

    @ThreadedMain
    public void mainThread() {
        DoClass.doTheThing();
    }

    @ThreadedSecondary
    public void secondThread() {
        DoClass.doTheThing();
    }

    @ThreadedAfter
    public void after() {}

    @Test
    public void runThreadedTests() {
        new AnnotatedTestRunner().runTests(DoClassTest.class, DoClass.class);
    }
}

All I end up with is this nasty exception:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:71)
    at com.google.testing.threadtester.BaseThreadedTestRunner.runTests(BaseThreadedTestRunner.java:179)
    at com.google.testing.threadtester.BaseThreadedTestRunner.runTests(BaseThreadedTestRunner.java:143)
    at DoClassTest.runThreadedTests(DoClassTest.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:68)
    ... 13 more
Caused by: java.lang.IllegalArgumentException: Cannot find method public static void DoClass.doTheThing()
    at com.google.testing.threadtester.ClassInstrumentationImpl.getMethod(ClassInstrumentationImpl.java:113)
    at com.google.testing.threadtester.InterleavedRunner.getMainMethod(InterleavedRunner.java:116)
    at com.google.testing.threadtester.InterleavedRunner.doInterleave(InterleavedRunner.java:131)
    at com.google.testing.threadtester.InterleavedRunner.interleave(InterleavedRunner.java:80)
    at com.google.testing.threadtester.AnnotatedTestWrapper.runTestCases(AnnotatedTestWrapper.java:258)
    at com.google.testing.threadtester.AnnotatedTestWrapper.runTests(AnnotatedTestWrapper.java:242)
    ... 16 more

Is this a known issue ? Am I doing something wrong ?

Thanks

@CappCorp
Copy link
Author

No update on this ticket, has the project been move somewhere else or is it still supported from here ?

Thanks.

@alasdairmackintosh
Copy link

Sorry - I must have missed this the first time around.

I'm afraid there's currently no support for static methods. The logic that handles breakpoints is built around the assumption that we are invoking non-static methods on a specific object being tested. (And the logic for interleaving threads of execution is built on breakpoints, which allow us to pause one thread and run another.)

I'm not sure what would break if this assumption was removed. I will try and investigate, but it might not be feasible.

Alasdair

@CappCorp
Copy link
Author

OK, thanks for the answer.

I hope it is feasible, I tried having a look at the instrumentation but I'm really not familiar enough with that kind of procedure and could not figure out the limitations of the mechanism.

Please keep me posted on your investigation, thanks in advance :)

@CappCorp
Copy link
Author

Hello,
Any update so far ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants