本文整理汇总了Java中org.axonframework.messaging.unitofwork.UnitOfWork类的典型用法代码示例。如果您正苦于以下问题:Java UnitOfWork类的具体用法?Java UnitOfWork怎么用?Java UnitOfWork使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnitOfWork类属于org.axonframework.messaging.unitofwork包,在下文中一共展示了UnitOfWork类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSendMessage_WithTransactionalUnitOfWork
import org.axonframework.messaging.unitofwork.UnitOfWork; //导入依赖的package包/类
@Test
public void testSendMessage_WithTransactionalUnitOfWork() throws Exception {
GenericEventMessage<String> message = new GenericEventMessage<>("Message");
final UnitOfWork<?> uow = DefaultUnitOfWork.startAndGet(message);
TopicConnection connection = mock(TopicConnection.class);
when(connectionFactory.createTopicConnection()).thenReturn(connection);
TopicSession transactionalSession = mock(TopicSession.class);
when(connection.createTopicSession(true, Session.SESSION_TRANSACTED))
.thenReturn(transactionalSession);
when(transactionalSession.createPublisher(topic)).thenReturn(publisher);
when(transactionalSession.getTransacted()).thenReturn(true);
TextMessage jmsMessage = mock(TextMessage.class);
when(converter.createJmsMessage(message, transactionalSession)).thenReturn(jmsMessage);
eventBus.publish(message);
uow.commit();
verify(publisher).publish(jmsMessage);
verify(transactionalSession).commit();
verify(transactionalSession).close();
}
示例2: testSendMessage_WithUnitOfWorkRollback
import org.axonframework.messaging.unitofwork.UnitOfWork; //导入依赖的package包/类
@Test
public void testSendMessage_WithUnitOfWorkRollback() throws Exception {
GenericEventMessage<String> message = new GenericEventMessage<>("Message");
final UnitOfWork<?> uow = DefaultUnitOfWork.startAndGet(message);
TopicConnection connection = mock(TopicConnection.class);
when(connectionFactory.createTopicConnection()).thenReturn(connection);
TopicSession transactionalSession = mock(TopicSession.class);
when(connection.createTopicSession(true, Session.SESSION_TRANSACTED))
.thenReturn(transactionalSession);
when(transactionalSession.createPublisher(topic)).thenReturn(publisher);
when(transactionalSession.getTransacted()).thenReturn(true);
TextMessage jmsMessage = mock(TextMessage.class);
when(converter.createJmsMessage(message, transactionalSession)).thenReturn(jmsMessage);
eventBus.publish(message);
verify(transactionalSession, never()).rollback();
verify(transactionalSession, never()).commit();
verify(transactionalSession, never()).close();
uow.rollback();
verify(publisher, never()).publish(jmsMessage);
verify(transactionalSession, never()).commit();
verify(connectionFactory, never()).createTopicConnection();
}
示例3: testSendMessage_WithTransactionalUnitOfWork_ChannelClosedBeforeCommit
import org.axonframework.messaging.unitofwork.UnitOfWork; //导入依赖的package包/类
@Test
public void testSendMessage_WithTransactionalUnitOfWork_ChannelClosedBeforeCommit()
throws Exception {
GenericEventMessage<String> message = new GenericEventMessage<>("Message");
final UnitOfWork<?> uow = DefaultUnitOfWork.startAndGet(message);
TopicConnection connection = mock(TopicConnection.class);
when(connectionFactory.createTopicConnection()).thenReturn(connection);
TopicSession transactionalSession = mock(TopicSession.class);
when(connection.createTopicSession(true, Session.SESSION_TRANSACTED))
.thenReturn(transactionalSession);
when(transactionalSession.createPublisher(topic)).thenReturn(publisher);
when(transactionalSession.getTransacted()).thenReturn(true);
TextMessage jmsMessage = mock(TextMessage.class);
when(converter.createJmsMessage(message, transactionalSession)).thenReturn(jmsMessage);
doThrow(JMSException.class).when(publisher).publish(jmsMessage);
eventBus.publish(message);
try {
uow.commit();
fail("Expected exception");
} catch (EventPublicationFailedException ex) {
assertNotNull(ex.getMessage());
}
verify(publisher).publish(jmsMessage);
verify(transactionalSession, never()).commit();
verify(transactionalSession).rollback();
verify(transactionalSession).close();
}