Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is It possible to use EasyMock with Junitperf? #201

Open
salma-yasser opened this issue Jul 22, 2017 · 2 comments
Open

Is It possible to use EasyMock with Junitperf? #201

salma-yasser opened this issue Jul 22, 2017 · 2 comments

Comments

@salma-yasser
Copy link

I am currently working on open source project which have junit test cases (Junit 4) using EasyMock. When I use ContiPerf for testing performance with many threads , I get this exception:

org.databene.contiperf.PerfTestExecutionError: java.util.ConcurrentModificationException
at org.databene.contiperf.util.ContiPerfUtil.executionError(ContiPerfUtil.java:58)
at org.databene.contiperf.junit.JUnitInvoker.invoke(JUnitInvoker.java:46)
at org.databene.contiperf.util.InvokerProxy.invoke(InvokerProxy.java:38)
at org.databene.contiperf.PerformanceTracker.invoke(PerformanceTracker.java:87)
at org.databene.contiperf.CountRunner.run(CountRunner.java:44)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
at java.util.ArrayList$Itr.next(ArrayList.java:791)
at org.easymock.internal.UnorderedBehavior.addExpected(UnorderedBehavior.java:38)
at org.easymock.internal.MocksBehavior.addExpected(MocksBehavior.java:61)
at org.easymock.internal.RecordState.times(RecordState.java:184)
at org.easymock.internal.RecordState.closeMethod(RecordState.java:226)
at org.easymock.internal.RecordState.invoke(RecordState.java:76)
at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:40)
at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:85)
at $Proxy7.getByName(Unknown Source)
at fi.hut.soberit.agilefant.business.SettingBusinessTest.testStoreSetting_boolean(SettingBusinessTest.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.databene.contiperf.junit.JUnitInvoker.invoke(JUnitInvoker.java:43)
... 4 more

My Question is how can I use multi threads using ContiPerf with EasyMock?
And to be more clear the test case like this:

@Test
@PerfTest(invocations = 10, threads = 5)
public void testStoreSetting_boolean() {
	expect(settingDAO.getByName("bool")).andReturn(null);
    expect(settingDAO.create(EasyMock.isA(Setting.class))).andReturn((Integer)1);
    Setting created = new Setting();
    created.setValue("true");
    expect(settingDAO.getByName("bool")).andReturn(created);
    replay(settingDAO);
    testable.storeSetting("bool", true);
    assertEquals("true", testable.retrieveByName("bool").getValue());
    verify(settingDAO);
}
@henri-tremblay
Copy link
Contributor

henri-tremblay commented Jul 23, 2017

I will need to dig a little more into it to see if something can be done about it. But right now I'll call this "normal". This idea was that for a multithreaded test, you record on mono thread and then we sync replay during the replay phase. In your case, you would need full sync. Which could be done by EasyMock, but also externally.

For instance,

@Test
@PerfTest(invocations = 10, threads = 5)
public void testStoreSetting_boolean() {
    Setting created = new Setting();
    created.setValue("true");          
    synchronized(this) {
        expect(settingDAO.getByName("bool")).andReturn(null);
        expect(settingDAO.create(EasyMock.isA(Setting.class))).andReturn((Integer)1);
        expect(settingDAO.getByName("bool")).andReturn(created);
    }
    replay(settingDAO);
    testable.storeSetting("bool", true);
    assertEquals("true", testable.retrieveByName("bool").getValue());
    verify(settingDAO);
}

might work.

I will keep this bug open for now in case you might do something better than that.

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

No branches or pull requests

3 participants
@henri-tremblay @salma-yasser and others