当前位置: 首页>>代码示例>>Java>>正文


Java UnitOfWork类代码示例

本文整理汇总了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();
}
 
开发者ID:sventorben,项目名称:axon-jms,代码行数:23,代码来源:JmsPublisherTest.java

示例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();
}
 
开发者ID:sventorben,项目名称:axon-jms,代码行数:27,代码来源:JmsPublisherTest.java

示例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();
}
 
开发者ID:sventorben,项目名称:axon-jms,代码行数:31,代码来源:JmsPublisherTest.java


注:本文中的org.axonframework.messaging.unitofwork.UnitOfWork类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。