@Test
public void middleTxAbortedAndRetryCompensationEvents() {

  new TestKit(system) {{
    final String globalTxId = UUID.randomUUID().toString();
    final String localTxId_1 = UUID.randomUUID().toString();
    final String localTxId_2 = UUID.randomUUID().toString();
    ActorRef saga = system.actorOf(SagaActor.props(genPersistenceId()));
    watch(saga);
    saga.tell(new PersistentFSM.SubscribeTransitionCallBack(getRef()), getRef());
    List<BaseEvent> eventList = SagaEventSender.middleTxAbortedAndRetryCompensationEvents(globalTxId, localTxId_1, localTxId_2);
    eventList.stream().forEach( event -> {
      saga.tell(event, getRef());
    });
    //expect
    CurrentState currentState = expectMsgClass(PersistentFSM.CurrentState.class);
    assertEquals(SagaActorState.IDLE, currentState.state());
    PersistentFSM.Transition transition = expectMsgClass(PersistentFSM.Transition.class);
    assertSagaTransition(transition, saga, SagaActorState.IDLE, SagaActorState.READY);
    transition = expectMsgClass(PersistentFSM.Transition.class);
    assertSagaTransition(transition, saga, SagaActorState.READY, SagaActorState.PARTIALLY_ACTIVE);
    transition = expectMsgClass(PersistentFSM.Transition.class);
    assertSagaTransition(transition, saga, SagaActorState.PARTIALLY_ACTIVE, SagaActorState.PARTIALLY_COMMITTED);
    transition = expectMsgClass(PersistentFSM.Transition.class);
    assertSagaTransition(transition, saga, SagaActorState.PARTIALLY_COMMITTED, SagaActorState.PARTIALLY_ACTIVE);
    transition = expectMsgClass(PersistentFSM.Transition.class);
    assertSagaTransition(transition, saga, SagaActorState.PARTIALLY_ACTIVE, SagaActorState.FAILED);
    transition = expectMsgClass(PersistentFSM.Transition.class);
    assertSagaTransition(transition, saga, SagaActorState.FAILED, SagaActorState.COMPENSATED);
    Terminated terminated = expectMsgClass(Terminated.class);
    assertEquals(terminated.getActor(), saga);
    SagaData sagaData = SAGA_DATA_EXTENSION_PROVIDER.get(system).getLastSagaData();
    assertEquals(sagaData.getGlobalTxId(), globalTxId);
    assertEquals(sagaData.getTxEntities().size(), 2);
    assertEquals(sagaData.getTxEntities().get(localTxId_1).getState(), TxState.COMPENSATED_SUCCEED);
    assertEquals(sagaData.getTxEntities().get(localTxId_2).getState(), TxState.FAILED);
    assertThat(eventList, is(sagaData.getEvents()));
    system.stop(saga);
  }};
}