Search in sources :

Example 6 with TestTransactionManager

use of org.springframework.integration.util.TestTransactionManager in project spring-integration by spring-projects.

the class PollingTransactionTests method propagationSupports.

@Test
public void propagationSupports() throws InterruptedException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("propagationSupportsTests.xml", this.getClass());
    TestTransactionManager txManager = (TestTransactionManager) context.getBean("txManager");
    PollableChannel input = (PollableChannel) context.getBean("input");
    PollableChannel output = (PollableChannel) context.getBean("output");
    assertEquals(0, txManager.getCommitCount());
    input.send(new GenericMessage<String>("test"));
    Message<?> reply = output.receive(3000);
    assertNotNull(reply);
    assertEquals(0, txManager.getCommitCount());
    assertNull(txManager.getLastDefinition());
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) TestTransactionManager(org.springframework.integration.util.TestTransactionManager) Test(org.junit.Test)

Example 7 with TestTransactionManager

use of org.springframework.integration.util.TestTransactionManager in project spring-integration by spring-projects.

the class PollingTransactionTests method propagationRequiresNew.

@Test
public void propagationRequiresNew() throws InterruptedException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("propagationRequiresNewTests.xml", this.getClass());
    TestTransactionManager txManager = (TestTransactionManager) context.getBean("txManager");
    PollableChannel input = (PollableChannel) context.getBean("input");
    PollableChannel output = (PollableChannel) context.getBean("output");
    assertEquals(0, txManager.getCommitCount());
    input.send(new GenericMessage<String>("test"));
    Message<?> reply = output.receive(3000);
    assertNotNull(reply);
    txManager.waitForCompletion(3000);
    assertEquals(1, txManager.getCommitCount());
    assertEquals(Propagation.REQUIRES_NEW.value(), txManager.getLastDefinition().getPropagationBehavior());
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) TestTransactionManager(org.springframework.integration.util.TestTransactionManager) Test(org.junit.Test)

Example 8 with TestTransactionManager

use of org.springframework.integration.util.TestTransactionManager in project spring-integration by spring-projects.

the class PollingTransactionTests method propagationNotSupported.

@Test
public void propagationNotSupported() throws InterruptedException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("propagationNotSupportedTests.xml", this.getClass());
    TestTransactionManager txManager = (TestTransactionManager) context.getBean("txManager");
    PollableChannel input = (PollableChannel) context.getBean("input");
    PollableChannel output = (PollableChannel) context.getBean("output");
    assertEquals(0, txManager.getCommitCount());
    input.send(new GenericMessage<String>("test"));
    Message<?> reply = output.receive(3000);
    assertNotNull(reply);
    assertEquals(0, txManager.getCommitCount());
    assertNull(txManager.getLastDefinition());
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) TestTransactionManager(org.springframework.integration.util.TestTransactionManager) Test(org.junit.Test)

Example 9 with TestTransactionManager

use of org.springframework.integration.util.TestTransactionManager in project spring-integration by spring-projects.

the class PollingTransactionTests method transactionWithRollback.

@Test
public void transactionWithRollback() throws InterruptedException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("transactionTests.xml", this.getClass());
    TestTransactionManager txManager = (TestTransactionManager) context.getBean("txManager");
    MessageChannel input = (MessageChannel) context.getBean("badInput");
    PollableChannel output = (PollableChannel) context.getBean("output");
    assertEquals(0, txManager.getCommitCount());
    assertEquals(0, txManager.getRollbackCount());
    input.send(new GenericMessage<String>("test"));
    txManager.waitForCompletion(1000);
    Message<?> message = output.receive(0);
    assertNull(message);
    assertEquals(0, txManager.getCommitCount());
    assertEquals(1, txManager.getRollbackCount());
    context.close();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) TestTransactionManager(org.springframework.integration.util.TestTransactionManager) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)9 TestTransactionManager (org.springframework.integration.util.TestTransactionManager)9 PollableChannel (org.springframework.messaging.PollableChannel)9 MessageChannel (org.springframework.messaging.MessageChannel)3 MessagingException (org.springframework.messaging.MessagingException)2 Advice (org.aopalliance.aop.Advice)1 Advisor (org.springframework.aop.Advisor)1 Advised (org.springframework.aop.framework.Advised)1 PollingConsumer (org.springframework.integration.endpoint.PollingConsumer)1 TransactionInterceptor (org.springframework.transaction.interceptor.TransactionInterceptor)1