Note that there are some explanatory texts on larger screens.

plurals
  1. POParallelize test execution in a @Rule
    primarykey
    data
    text
    <p>I want to reuse some integration tests for load testing purposes. I implemented a rule which is parameterized by an annotation:</p> <pre><code>@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Parallel { int invocations() default 1; int rampUpTime() default 0; } </code></pre> <p>In my rule implementation the annotation is evaluated and a statement is set up, which has a evaluate method like that:</p> <pre><code>@Override public void evaluate() throws Throwable { ScheduledExecutorService exe = Executors.newScheduledThreadPool(invocations); for (int i = 0; i &lt; invocations; i++) { ScheduledFuture&lt;?&gt; scheduledFuture = exe.schedule(new Runnable() { @Override public void run() { try { invocated++; // Request test = Request.method(description.getTestClass(), description.getMethodName()); // new JUnitCore().run(test); statement.evaluate(); } catch (Throwable e) { e.printStackTrace(); } } }, i * rampUpTime, this.timeUnit); futures.add(scheduledFuture); } } </code></pre> <p>So, the <code>evaluate</code> call gets wrapped in a <code>Runnable()</code> and scheduled as described in the annotation. The thing is: In my rule, only the scheduling takes place, the runner doesn´t know (or care) about all the runables which only run as long as it takes to set up the whole test suite. So I´m trying to add the calls to <code>evalute()</code> to the test runner. First try was to use <code>JUnitCore.run(...)</code> which of course ends in a recursion.</p> <p>Next try was to collect all the futures and wait for them to finish. This works fine on a per test basis, but I want to execute a whole test suite in parallel. And also, in my test report, I only see the test being executed once.</p> <p>So then I thought I use a parameterized suite with a context (an object which collects all the futures from all tests) as parameter, but I didn´t found a way to promote this context object to the tests, each test has to have its own parameters.</p> <p>I´m now asking for a way to add multiple executions from my rule to the test runner which is executing it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload