java.lang.IllegalArgumentException: java_testSingleBlockRead is declared with required signature[public void no-arguments]

65 views
Skip to first unread message

Omry Yadan

unread,
May 19, 2013, 6:38:32 PM5/19/13
to junit-be...@googlegroups.com
I am trying to use persist test results with H2, as soon as I added the H2 consumer I got the following exception for each test.
needless to saym without specifying the consumers I am not having any problems.

this is my vm arguments:
-ea -Djub.consumers=CONSOLE,H2  -Djub.db.file=.benchmarks

I have the following jars in my classpath:

h2-1.3.171.jar
hamcrest-core-1.3.jar
junit-4.11.jar
junit-benchmarks-0.6.0.jar

any idea?

Dawid Weiss

unread,
May 20, 2013, 4:19:08 AM5/20/13
to junit-be...@googlegroups.com
Can you provide a stack trace?
> --
> You received this message because you are subscribed to the Google Groups
> "JUnitBenchmarks: Performance Benchmarking for JUnit4" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to junit-benchmar...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Dawid Weiss

unread,
May 20, 2013, 5:27:36 AM5/20/13
to junit-be...@googlegroups.com
I think it's the same pull request that broke things as this issue:
http://issues.carrot2.org/browse/JUNITBENCH-53

I'd appreciate if you could provide the definition of the class that
caused this (and a stack trace).

Dawid

Dawid Weiss

unread,
May 20, 2013, 5:54:19 AM5/20/13
to junit-be...@googlegroups.com
Let me know how your test class is defined and what runner it uses.
The problem you've encountered is related to the fact that new JUnit
passes a Description object which doesn't have an explicit handle to
the test method. We try to reconstruct it -- it should be a public
method on the test suite class. With certain runners that change the
test method name it may not hit the right target. I think this is the
case here.

Dawid

Omry Yadan

unread,
May 25, 2013, 9:02:14 PM5/25/13
to junit-be...@googlegroups.com
Here is my stack trace and test class


java.lang.IllegalArgumentException: java_testSingleBlockRead[0] is declared with required signature[public void no-arguments]
    at com.carrotsearch.junitbenchmarks.Result.getTestMethod(Result.java:101)
    at com.carrotsearch.junitbenchmarks.db.DbConsumer.accept(DbConsumer.java:122)
    at com.carrotsearch.junitbenchmarks.BenchmarkStatement.evaluate(BenchmarkStatement.java:349)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runners.Suite.runChild(Suite.java:127)
    at org.junit.runners.Suite.runChild(Suite.java:26)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    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:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NoSuchMethodException: com.banana.memory.malloc.Benchmark.java_testSingleBlockRead[0]()
    at java.lang.Class.getMethod(Class.java:1622)
    at com.carrotsearch.junitbenchmarks.Result.getTestMethod(Result.java:99)
    ... 26 more



package com.banana.memory.malloc;

import static org.junit.Assert.assertEquals;

@RunWith(value = Parameterized.class)
public class Benchmark {

  final int TOTAL_ALLOCATION_SIZE = 1 * 1024 * 1024;
  int BLOCK_SIZE = 16;
  final int NUM_BLOCKS = TOTAL_ALLOCATION_SIZE / BLOCK_SIZE;
  int VAR_SIZE_ALLOCATION = -1;

  IMemAllocator m_treeIntAllocator;
  ChainedAllocator m_chainedIntAllocator;

  @Rule
  public TestRule benchmarkRun = new BenchmarkRule();

  public Benchmark(int blockSize, int varSizeAllocationSize) {
    BLOCK_SIZE = blockSize;
    VAR_SIZE_ALLOCATION = varSizeAllocationSize;
  }

  @Parameters
  public static Collection<Object[]> data() {
    //@formatter:off
    Object[][] data = new Object[][] {
        {16, 256},
    };
    return Arrays.asList(data);
  }
  //@formatter:on

  @Before
  public void init() {
    m_treeIntAllocator = new TreeAllocator(NUM_BLOCKS, BLOCK_SIZE);
    m_treeIntAllocator.setDebug(true);
    m_treeIntAllocator.setInitializer(new MemSetInitializer(-1));
    m_chainedIntAllocator = new ChainedAllocator(NUM_BLOCKS, BLOCK_SIZE);
    m_chainedIntAllocator.setDebug(true);
    m_chainedIntAllocator.setInitializer(new MemSetInitializer(-1));
  }

  @After
  public void cleanup() {
    m_treeIntAllocator.clear();
    m_chainedIntAllocator.clear();
  }

  @Test
  public void java_testSingleBlockRead() {
    @SuppressWarnings("unused")
    long sum = 0;
    for (int i = 0; i < NUM_BLOCKS; i++) {
      int arr[] = new int[VAR_SIZE_ALLOCATION];
      for (int j = 0; j < VAR_SIZE_ALLOCATION; j++) {
        sum += arr[j];
      }
      arr = null; // "free"
    }
  }

  @Test
  public void java_testSingleBlockWrite() {
    for (int i = 0; i < NUM_BLOCKS; i++) {
      int arr[] = new int[VAR_SIZE_ALLOCATION];
      for (int j = 0; j < VAR_SIZE_ALLOCATION; j++) {
        arr[j] = j;
      }
      arr = null; // "free"
    }
  }

  @Test
  public void TreeIntAllocator_testSingleBlockRead() {
    intAllocIntRead(m_treeIntAllocator);
  }

  @Test
  public void ChainedIntAllocator_testSingleBlockRead() {
    intAllocIntRead(m_chainedIntAllocator);
  }

  @Test
  public void TreeIntAllocator_testSingleBlockWrite() {
    intAllocIntWrite(m_treeIntAllocator);
  }

  @Test
  public void ChainedIntAllocator_testSingleBlockWrite() {
    intAllocIntWrite(m_chainedIntAllocator);
  }

  @Test
  public void TreeIntAllocator_testSingleBlockArrayRead() {
    intAllocArrayRead(m_treeIntAllocator);
  }

  @Test
  public void ChainedIntAllocator_testSingleBlockArrayRead() {
    intAllocArrayRead(m_chainedIntAllocator);
  }

  @Test
  public void TreeIntAllocator_testSingleBlockArrayWrite() {
    intAllocArrayWrite(m_treeIntAllocator);
  }

  @Test
  public void ChainedIntAllocator_testSingleBlockArrayWrite() {
    intAllocArrayWrite(m_chainedIntAllocator);
  }

  public void intAllocIntRead(IMemAllocator allocator) {
    assertEquals(0, allocator.usedBlocks());
    @SuppressWarnings("unused")
    long sum = 0;
    for (int i = 0; i < allocator.maxBlocks(); i++) {
      int pointer = allocator.malloc(VAR_SIZE_ALLOCATION);
      for (int j = 0; j < allocator.blockSize(); j++) {
        sum += allocator.getInt(pointer, j);
      }
      allocator.free(pointer);
    }
  }

  public void intAllocIntWrite(IMemAllocator allocator) {
    assertEquals(0, allocator.usedBlocks());
    @SuppressWarnings("unused")
    long sum = 0;
    for (int i = 0; i < allocator.maxBlocks(); i++) {
      int pointer = allocator.malloc(VAR_SIZE_ALLOCATION);
      for (int j = 0; j < allocator.blockSize(); j++) {
        allocator.setInt(pointer, j, j);
      }
      allocator.free(pointer);
    }
  }

  public void intAllocArrayRead(IMemAllocator allocator) {
    assertEquals(0, allocator.usedBlocks());
    int block[] = new int[VAR_SIZE_ALLOCATION];
    for (int i = 0; i < allocator.maxBlocks(); i++) {
      int pointer = allocator.malloc(VAR_SIZE_ALLOCATION);
      for (int j = 0; j < allocator.blockSize(); j++) {
        allocator.getInts(pointer, 0, block, 0, VAR_SIZE_ALLOCATION);
      }
      allocator.free(pointer);
    }
  }

  public void intAllocArrayWrite(IMemAllocator allocator) {
    assertEquals(0, allocator.usedBlocks());
    int block[] = new int[VAR_SIZE_ALLOCATION];
    for (int i = 0; i < allocator.maxBlocks(); i++) {
      int pointer = allocator.malloc(VAR_SIZE_ALLOCATION);
      for (int j = 0; j < allocator.blockSize(); j++) {
        allocator.setInts(pointer, 0, block, 0, VAR_SIZE_ALLOCATION);
      }
      allocator.free(pointer);

Dawid Weiss

unread,
May 28, 2013, 5:42:20 PM5/28/13
to junit-be...@googlegroups.com
Hi. Apologies for belated answer.

The problem is in JUnit itself. What happens is a Rule has access to a
"Description" which describes the current test but this encapsulation
does *not* expose the actual framework's method which needs to be
available for the H2 consumer. So we do this:

return getTestClass().getMethod(getTestMethodName());

In most cases it works because the test's name matches the test
method. Alas, the parameterized runner changes method names by
appending parameters (I think) so it no longer hits the target.

Sorry, this is unfixable. You have an option of not using
Parameterized runner or switching back to junit-benchmark 0.4.0 (I
think) which still used @MethodRule.

Dawid
Reply all
Reply to author
Forward
0 new messages