-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-17421 Test that no follow-on locking happens on SQL Server and Sy…
…base ASE
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...te-core/src/test/java/org/hibernate/orm/test/locking/jpa/AdvancedFollowOnLockingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.hibernate.orm.test.locking.jpa; | ||
|
||
import org.hibernate.dialect.SQLServerDialect; | ||
import org.hibernate.dialect.SybaseASEDialect; | ||
import org.hibernate.query.spi.QueryImplementor; | ||
|
||
import org.hibernate.testing.jdbc.SQLStatementInspector; | ||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.JiraKey; | ||
import org.hibernate.testing.orm.junit.RequiresDialect; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import jakarta.persistence.LockModeType; | ||
import jakarta.persistence.Tuple; | ||
|
||
@DomainModel(annotatedClasses = { Department.class }) | ||
@SessionFactory(useCollectingStatementInspector = true) | ||
@RequiresDialect(value = SQLServerDialect.class) | ||
@RequiresDialect(value = SybaseASEDialect.class) | ||
public class AdvancedFollowOnLockingTest { | ||
|
||
@Test | ||
@JiraKey("HHH-17421") | ||
public void testNoFollowonLocking(SessionFactoryScope scope) { | ||
SQLStatementInspector statementInspector = scope.getCollectingStatementInspector(); | ||
scope.inTransaction( | ||
session -> { | ||
final Department engineering = new Department( 1, "Engineering" ); | ||
session.persist( engineering ); | ||
} | ||
); | ||
|
||
scope.inTransaction( | ||
session -> { | ||
statementInspector.clear(); | ||
|
||
final QueryImplementor<Department> query = session.createQuery( | ||
"select distinct d from Department d", | ||
Department.class | ||
); | ||
query.setLockMode( LockModeType.PESSIMISTIC_WRITE ); | ||
query.list(); | ||
|
||
// The only statement should be the initial SELECT .. WITH (UPDLOCK, ..) .. | ||
// and without any follow-on locking. | ||
statementInspector.assertExecutedCount( 1 ); | ||
} | ||
); | ||
} | ||
|
||
@Test | ||
@JiraKey("HHH-17421") | ||
public void testNoFollowonLockingOnGroupBy(SessionFactoryScope scope) { | ||
SQLStatementInspector statementInspector = scope.getCollectingStatementInspector(); | ||
scope.inTransaction( session -> { | ||
final Department engineering = new Department( 1, "Engineering" ); | ||
session.persist( engineering ); | ||
} | ||
); | ||
|
||
scope.inTransaction( | ||
session -> { | ||
statementInspector.clear(); | ||
|
||
final QueryImplementor<Tuple> query = session.createQuery( | ||
"select d, count(*) from Department d left join Department d2 on d.name = d2.name group by d", | ||
Tuple.class | ||
); | ||
query.setLockMode( LockModeType.PESSIMISTIC_WRITE ); | ||
query.list(); | ||
|
||
// The only statement should be the initial SELECT .. WITH (UPDLOCK, ..) .. | ||
// and without any follow-on locking. | ||
statementInspector.assertExecutedCount( 1 ); | ||
} | ||
); | ||
} | ||
|
||
@AfterEach | ||
public void dropTestData(SessionFactoryScope scope) { | ||
scope.inTransaction( (session) -> { | ||
session.createMutationQuery( "delete Department" ).executeUpdate(); | ||
} ); | ||
} | ||
} |