Skip @Param values

Aleksey Shipilev aleksey.shipilev at oracle.com
Mon Jul 21 18:26:47 UTC 2014


Hi Andrii,

On 07/21/2014 06:22 PM, Andrii Rodionov wrote:
> Is it possible to specify that methods, which are not using @Param values,
> should execute only once? Maybe some annotation like @SkipParam above the
> method?

The rule of thumb is: if a test references the @State bearing the
@Param, those parameters become the part of test's configuration. We
don't have an opportunity to detect which tests are actually using
parameters.

Therefore, if you want to exclude the test from parameter variation, you
have to stop referencing the relevant @State. Since in your example, the
test's enclosing class is @State, it can be done two ways:

 A) Introduce the auxiliary @State holding only @Param(<threads>), and
inject it in only those @Benchmark methods where you need it. It is
working right now, but I added the relevant test case to seal that
behavior [1].
 B) Split the class into two classes, one with @Param(<threads>), and
one without.

Having those available, I see no reason to have anything like @SkipParam.

Thanks,
-Aleksey.

[1] http://hg.openjdk.java.net/code-tools/jmh/rev/68fcb2f9aacf


More information about the jmh-dev mailing list