I would like to to load tests in JUnit. The scenario is the following: I want to test the EJB3 with their transactions, with the EntityManager, and a memory database. For the load test I'm using ContiPerf 2. I googled it and I saw different approaches. In some of then they were using a embedded EJBContainer, in another they were just initializing the EntityManager and they were starting the transaction from the EntityTransaction.
For a simple unit test, with the EntityManager and the EntityTransaction is enough, but when I want to do a load test I find several problems, but the biggest one it's conceptual.
My first approach was this:
@Test
@PerfTest(invocations = 1000, threads = 5)
@Required(max = 1000, average = 250)
public void testTransaction() {
et.begin();
MyEntity myEntity = new MyEntity();
service.performAction(myEntity);
thenMyEntityIsOk(myEntity);
et.rollback();
}
But in this test I had problems doing the load test because of the rollback (if instead of a rollback I use commit the problem is the same).
After this I thought that maybe the problem could be the transactions, then I start using the embedded EJBContainer, but I had a lot of problems with the dependencies and with the execution.
Do you have any suggestion about how to do a load test in JUnit?