Skip to content

Commit de0eb22

Browse files
committed
[#2651] Removed @disabled from FindByIdWithLockTest.testFindUpgradeNoWait
1 parent 31c1b88 commit de0eb22

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ org.gradle.java.installations.auto-download=false
3737

3838
# The database type to use (key insensitive and support aliases):
3939
# Db2, MySql, PostgreSQL, CockroachDB, SqlServer, Oracle
40-
#db = MSSQL
40+
db = SqlServer
4141

4242
# Enable the maven Central Snapshot repository, when set to any value (the value is ignored)
4343
enableCentralSonatypeSnapshotsRep = true

hibernate-reactive-core/src/test/java/org/hibernate/reactive/FindByIdWithLockTest.java

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@
1010
import org.hibernate.cfg.Configuration;
1111
import 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-
1813
import org.junit.jupiter.api.BeforeEach;
19-
import org.junit.jupiter.api.Disabled;
2014
import org.junit.jupiter.api.Test;
2115

2216
import io.vertx.junit5.Timeout;
@@ -27,6 +21,10 @@
2721
import jakarta.persistence.LockModeType;
2822
import jakarta.persistence.ManyToOne;
2923
import 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

3129
import static org.assertj.core.api.Assertions.assertThat;
3230
import 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,51 @@ 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 SQLSERVER -> {
107+
assertThat( sqlTracker.getLoggedQueries() ).hasSize( 1 );
108+
assertThat( sqlTracker.getLoggedQueries()
109+
.get( 0 ) ).contains( "with (updlock,holdlock,rowlock,nowait)" );
110+
}
118111
// 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" );
112+
case DB2 -> {
113+
assertThat( sqlTracker.getLoggedQueries() ).hasSize( 1 );
114+
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).contains(
115+
"for read only with rs use and keep update locks" );
116+
}
117+
case ORACLE -> {
118+
assertThat( sqlTracker.getLoggedQueries() ).hasSize( 1 );
119+
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).contains( "for update of c1_0.id nowait" );
120+
}
121+
case MARIA -> {
122+
assertThat( sqlTracker.getLoggedQueries() ).hasSize( 1 );
123+
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).contains( "for update nowait" );
124+
}
125+
case MYSQL -> {
126+
assertThat( sqlTracker.getLoggedQueries() ).hasSize( 1 );
127+
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).contains( "for update of c1_0 nowait" );
128+
}
129+
// For PostgresSql and CockroachDb LockStrategy.FOLLOW_ON is applied
130+
// (dialects do not support outer join for update, see org.hibernate.sql.ast.spiAbstractSqlAst#determineLockingStrategy(QuerySpec,Locking.FollowOn))
131+
// so 2 queries are executed, the first one select the entity and contains the join the second one does not contain the join but contains the lock clause.
132+
case POSTGRESQL -> {
133+
assertThat( sqlTracker.getLoggedQueries() ).hasSize( 2 );
134+
assertThat( sqlTracker.getLoggedQueries().get( 1 ) ).endsWith( "for no key update of tbl nowait" );
135+
}
136+
case COCKROACHDB -> {
137+
assertThat( sqlTracker.getLoggedQueries() ).hasSize( 2 );
138+
assertThat( sqlTracker.getLoggedQueries().get( 1 ) ).endsWith( "for update of tbl nowait" );
139+
}
122140
default -> throw new IllegalArgumentException( "Database not recognized: " + dbType().name() );
123-
};
141+
}
124142
}
125143

126144
@Entity(name = "Parent")

0 commit comments

Comments
 (0)