SeataATShardingTransactionManager implements ShardingTransactionManager { @Override @SneakyThrows(TransactionException.class) public void commit() { Preconditions.checkState(enableSeataAT, "sharding seata-at transaction has been disabled."); try { SeataTransactionHolder.get().commit(); } finally { SeataTransactionHolder.clear(); RootContext.unbind(); } } SeataATShardingTransactionManager(); @Override void init(final DatabaseType databaseType, final Collection<ResourceDataSource> resourceDataSources); @Override TransactionType getTransactionType(); @Override boolean isInTransaction(); @Override Connection getConnection(final String dataSourceName); @Override @SneakyThrows(TransactionException.class) void begin(); @Override @SneakyThrows(TransactionException.class) void commit(); @Override @SneakyThrows(TransactionException.class) void rollback(); @Override void close();  }
@Test public void assertCommit() { SeataTransactionHolder.set(GlobalTransactionContext.getCurrentOrCreate()); setXID("testXID"); seataATShardingTransactionManager.commit(); assertResult(); }
@Test(expected = IllegalStateException.class) public void assertCommitWithoutBegin() { SeataTransactionHolder.set(GlobalTransactionContext.getCurrentOrCreate()); seataATShardingTransactionManager.commit(); }