Skip to content

Commit

Permalink
fix: TransactionSynchronizationManager 트랜잭션 활성화 여부 테스트 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hong-sile committed Oct 10, 2023
1 parent da18ff9 commit 6fb201c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static Connection unbindResource(final DataSource key) {

public static boolean isTransactionActive(final DataSource dataSource) {
try {
return resources.get().get(dataSource).getAutoCommit();
return !resources.get().get(dataSource).getAutoCommit();
} catch (final SQLException e) {
throw new TransactionSynchronizationManagerException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,24 @@ class IsTransactionActive {
@DisplayName("실행한 경우")
void trueCase() throws SQLException {
final DataSource datasource = getInstance();
TransactionSynchronizationManager.bindResource(datasource, datasource.getConnection());
final Connection connection = datasource.getConnection();
connection.setAutoCommit(false);

TransactionSynchronizationManager.bindResource(datasource, connection);

assertTrue(isTransactionActive(getInstance()));
connection.close();
}

@Test
@DisplayName("실행하지 않은 경우")
void falseCase() throws SQLException {
final DataSource datasource = getInstance();
final Connection connection = datasource.getConnection();
TransactionSynchronizationManager.bindResource(datasource, connection);

assertFalse(isTransactionActive(getInstance()));
connection.close();
}
}

Expand Down

0 comments on commit 6fb201c

Please sign in to comment.