BackendTransactionManager implements TransactionManager { @Override public void rollback() throws SQLException { if (connection.getTransactionStatus().isInTransaction()) { try { if (TransactionType.LOCAL == transactionType || null == shardingTransactionManager) { localTransactionManager.rollback(); } else { shardingTransactionManager.rollback(); } } finally { connection.getTransactionStatus().setInTransaction(false); } } } BackendTransactionManager(final BackendConnection backendConnection); @Override void begin(); @Override void commit(); @Override void rollback();  }
@Test public void assertRollbackForLocalTransaction() throws SQLException { newBackendTransactionManager(TransactionType.LOCAL, true); backendTransactionManager.rollback(); verify(transactionStatus).setInTransaction(false); verify(localTransactionManager).rollback(); }
@Test public void assertRollbackForDistributedTransaction() throws SQLException { newBackendTransactionManager(TransactionType.XA, true); backendTransactionManager.rollback(); verify(transactionStatus).setInTransaction(false); verify(shardingTransactionManager).rollback(); }
@Test public void assertRollbackWithoutTransaction() throws SQLException { newBackendTransactionManager(TransactionType.LOCAL, false); backendTransactionManager.rollback(); verify(transactionStatus, times(0)).setInTransaction(false); verify(localTransactionManager, times(0)).rollback(); verify(shardingTransactionManager, times(0)).rollback(); }