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