1

I am struggling to get some tests I wrote to roll back transaction. My test passes and works ok. However when I try to make it transactional (so i can roll back the test) I am getting the following error

java.lang.IllegalStateException: Cannot start a new transaction without ending the existing transaction.
    at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:175)        ~[spring-test-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:249) [spring-test-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at 

If I throw an exception in my routing it will undo any database saves so the transaction I have does work... It just does not seem to attach itself to the test and rollback?

My test looks like this.

@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestAppConfig.class})
@Transactional
public class RouteTest
{

    @Autowired SignUpRoute signUpRoute;

    @Test
    public void basicTest() throws Exception{

        ModelCamelContext signUpRouteContext = signUpRoute.getContext();

        MessageDto messageDto = new MessageDto();
        messageDto.setFirstName();
        messageDto.setLastName();
        // etc

        ObjectMapper mapper = new ObjectMapper();
        String jsonMessage = mapper.writeValueAsString(messageDto);  

       String rabbitURL = "rabbitmq://docker:5672/ignUp.exchange?queue=...etc...";

        ProducerTemplate producerTemplate = supplierSignUpRouteContext.createProducerTemplate();
        producerTemplate.setDefaultEndpoint(END_POINT_MOCK);
        producerTemplate.sendBody(rabbitmqURL, jsonMessage);

        END_POINT_MOCK.expectedMessageCount(1);
        END_POINT_MOCK.assertIsSatisfied();
    }   
}
Robbo_UK
  • 11,351
  • 25
  • 81
  • 117
  • can you post your camel route definition and the entire stack trace as well? – stringy05 Jun 08 '16 at 02:05
  • It seems related to : http://stackoverflow.com/questions/2202045/testng-multithreaded-test-with-spring-transactional if you are using maven, try `mvn test -DforkCount=0` – michael_bitard Jun 08 '16 at 09:49

0 Answers0