1010import org .hibernate .cfg .Configuration ;
1111import org .hibernate .reactive .testing .SqlStatementTracker ;
1212
13- import java .util .ArrayList ;
14- import java .util .Collection ;
15- import java .util .List ;
16- import java .util .concurrent .TimeUnit ;
17-
1813import org .junit .jupiter .api .BeforeEach ;
19- import org .junit .jupiter .api .Disabled ;
2014import org .junit .jupiter .api .Test ;
2115
2216import io .vertx .junit5 .Timeout ;
2721import jakarta .persistence .LockModeType ;
2822import jakarta .persistence .ManyToOne ;
2923import jakarta .persistence .OneToMany ;
24+ import java .util .ArrayList ;
25+ import java .util .Collection ;
26+ import java .util .List ;
27+ import java .util .concurrent .TimeUnit ;
3028
3129import static org .assertj .core .api .Assertions .assertThat ;
3230import static org .hibernate .reactive .containers .DatabaseConfiguration .dbType ;
@@ -84,7 +82,6 @@ context, getMutinySessionFactory()
8482 );
8583 }
8684
87- @ Disabled
8885 @ Test
8986 public void testFindUpgradeNoWait (VertxTestContext context ) {
9087 Child child = new Child ( CHILD_ID , "And" );
@@ -97,30 +94,49 @@ context, getMutinySessionFactory()
9794 .invoke ( c -> {
9895 assertThat ( c ).isNotNull ();
9996 assertThat ( c .getId () ).isEqualTo ( CHILD_ID );
100- String selectQuery = sqlTracker .getLoggedQueries ().get ( 0 );
101- assertThat ( sqlTracker .getLoggedQueries () ).hasSize ( 1 );
102- assertThat ( selectQuery )
103- .matches ( this ::noWaitLockingPredicate , "SQL query with nowait lock for " + dbType ().name () );
97+
98+ assertThatExecutedQueriesContainLock ();
10499 }
105100 ) ) )
106101 );
107102 }
108103
109- /**
110- * @return true if the query contains the expected nowait keyword for the selected database
111- */
112- private boolean noWaitLockingPredicate (String selectQuery ) {
113- return switch ( dbType () ) {
114- case POSTGRESQL -> selectQuery .endsWith ( "for no key update of c1_0 nowait" );
115- case COCKROACHDB -> selectQuery .endsWith ( "for update of c1_0 nowait" );
116- case SQLSERVER -> selectQuery .contains ( "with (updlock,holdlock,rowlock,nowait)" );
117- case ORACLE -> selectQuery .contains ( "for update of c1_0.id nowait" );
104+ private void assertThatExecutedQueriesContainLock () {
105+ switch ( dbType () ) {
106+ case POSTGRESQL -> {
107+ assertThat ( sqlTracker .getLoggedQueries () ).hasSize ( 2 );
108+ assertThat ( sqlTracker .getLoggedQueries ().get ( 1 ) ).endsWith ( "for no key update of tbl nowait" );
109+ }
110+ case COCKROACHDB -> {
111+ assertThat ( sqlTracker .getLoggedQueries () ).hasSize ( 2 );
112+ assertThat ( sqlTracker .getLoggedQueries ().get ( 1 ) ).endsWith ( "for update of tbl nowait" );
113+ }
114+ case SQLSERVER -> {
115+ assertThat ( sqlTracker .getLoggedQueries () ).hasSize ( 2 );
116+ assertThat ( sqlTracker .getLoggedQueries ()
117+ .get ( 1 ) ).contains ( "with (updlock,holdlock,rowlock,nowait)" );
118+ }
119+ case ORACLE -> {
120+ assertThat ( sqlTracker .getLoggedQueries () ).hasSize ( 2 );
121+ assertThat ( sqlTracker .getLoggedQueries ().get ( 1 ) ).contains ( "for update of tbl.id nowait" );
122+ }
118123 // DB2 does not support nowait
119- case DB2 -> selectQuery .contains ( "for read only with rs use and keep update locks" );
120- case MARIA -> selectQuery .contains ( "for update nowait" );
121- case MYSQL -> selectQuery .contains ( "for update of c1_0 nowait" );
124+ case DB2 -> {
125+ assertThat ( sqlTracker .getLoggedQueries () ).hasSize ( 2 );
126+ assertThat ( sqlTracker .getLoggedQueries ().get ( 1 ) ).contains (
127+ "for read only with rs use and keep update locks" );
128+ }
129+ // For MariaDB and MySQL LockStrategy.FOLLOW_ON is not applied but LockStrategy.CLAUSE is, so only one query is executed.
130+ case MARIA -> {
131+ assertThat ( sqlTracker .getLoggedQueries () ).hasSize ( 1 );
132+ assertThat ( sqlTracker .getLoggedQueries ().get ( 0 ) ).contains ( "for update nowait" );
133+ }
134+ case MYSQL -> {
135+ assertThat ( sqlTracker .getLoggedQueries () ).hasSize ( 1 );
136+ assertThat ( sqlTracker .getLoggedQueries ().get ( 0 ) ).contains ( "for update of c1_0 nowait" );
137+ }
122138 default -> throw new IllegalArgumentException ( "Database not recognized: " + dbType ().name () );
123- };
139+ }
124140 }
125141
126142 @ Entity (name = "Parent" )
0 commit comments