Skip to content

Commit 4e4b04a

Browse files
committed
Verify read-only propagation in DataSourceTransactionManagerTests
See gh-23747
1 parent a2c06b7 commit 4e4b04a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run
857857
public void testTransactionWithIsolationAndReadOnly() throws Exception {
858858
given(con.getTransactionIsolation()).willReturn(Connection.TRANSACTION_READ_COMMITTED);
859859
given(con.getAutoCommit()).willReturn(true);
860+
given(con.isReadOnly()).willReturn(true);
860861

861862
TransactionTemplate tt = new TransactionTemplate(tm);
862863
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
@@ -874,11 +875,13 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
874875

875876
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
876877
InOrder ordered = inOrder(con);
878+
ordered.verify(con).setReadOnly(true);
877879
ordered.verify(con).setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
878880
ordered.verify(con).setAutoCommit(false);
879881
ordered.verify(con).commit();
880882
ordered.verify(con).setAutoCommit(true);
881883
ordered.verify(con).setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
884+
ordered.verify(con).setReadOnly(false);
882885
verify(con).close();
883886
}
884887

@@ -889,6 +892,7 @@ public void testTransactionWithEnforceReadOnly() throws Exception {
889892
given(con.getAutoCommit()).willReturn(true);
890893
Statement stmt = mock(Statement.class);
891894
given(con.createStatement()).willReturn(stmt);
895+
given(con.isReadOnly()).willReturn(true);
892896

893897
TransactionTemplate tt = new TransactionTemplate(tm);
894898
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
@@ -905,11 +909,13 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
905909

906910
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
907911
InOrder ordered = inOrder(con, stmt);
912+
ordered.verify(con).setReadOnly(true);
908913
ordered.verify(con).setAutoCommit(false);
909914
ordered.verify(stmt).executeUpdate("SET TRANSACTION READ ONLY");
910915
ordered.verify(stmt).close();
911916
ordered.verify(con).commit();
912917
ordered.verify(con).setAutoCommit(true);
918+
ordered.verify(con).setReadOnly(false);
913919
ordered.verify(con).close();
914920
}
915921

0 commit comments

Comments
 (0)