Skip to content

Commit

Permalink
HHH-18023 fix questionable test
Browse files Browse the repository at this point in the history
PESSIMISTIC_READ is not really a "more exclusive" lock than UPGRADE_NOWAIT

Signed-off-by: Gavin King <gavin@hibernate.org>
  • Loading branch information
gavinking committed Apr 28, 2024
1 parent 1e0e0ac commit fe7b3c9
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package org.hibernate.orm.test.locking;

import java.util.Collections;
import java.util.concurrent.CountDownLatch;

import jakarta.persistence.LockModeType;
import jakarta.persistence.criteria.CriteriaBuilder;
Expand All @@ -17,7 +16,6 @@
import org.hibernate.LockOptions;
import org.hibernate.Session;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.dialect.CockroachDialect;
import org.hibernate.dialect.SQLServerDialect;
Expand Down Expand Up @@ -56,8 +54,6 @@ public class LockModeTest extends BaseSessionFactoryFunctionalTest {

private Long id;

private CountDownLatch endLatch = new CountDownLatch( 1 );

@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { A.class };
Expand Down Expand Up @@ -240,19 +236,30 @@ public void testRefreshWithExplicitLowerLevelLockMode() {
@Test
@TestForIssue(jiraKey = "HHH-12257")
@SkipForDialect( dialectClass = CockroachDialect.class )
public void testRefreshWithExplicitHigherLevelLockMode() {
public void testRefreshWithExplicitHigherLevelLockMode1() {
doInHibernate( this::sessionFactory, session -> {
A a = session.get( A.class, id );
checkLockMode( a, LockMode.READ, session );
session.refresh( a, LockMode.UPGRADE_NOWAIT );
checkLockMode( a, LockMode.UPGRADE_NOWAIT, session );
session.refresh( a, LockModeType.PESSIMISTIC_READ );
checkLockMode( a, LockMode.PESSIMISTIC_READ, session );
session.refresh( a, LockModeType.PESSIMISTIC_WRITE, Collections.emptyMap() );
checkLockMode( a, LockMode.PESSIMISTIC_WRITE, session );
} );
}

@Test
@TestForIssue(jiraKey = "HHH-12257")
@SkipForDialect( dialectClass = CockroachDialect.class )
public void testRefreshWithExplicitHigherLevelLockMode2() {
doInHibernate( this::sessionFactory, session -> {
A a = session.get( A.class, id );
checkLockMode( a, LockMode.READ, session );
session.refresh( a, LockModeType.PESSIMISTIC_READ );
checkLockMode( a, LockMode.PESSIMISTIC_READ, session );
session.refresh( a, LockModeType.PESSIMISTIC_WRITE, Collections.emptyMap() );
checkLockMode( a, LockMode.PESSIMISTIC_WRITE, session );
} );
}

@Test
@TestForIssue(jiraKey = "HHH-12257")
Expand Down

0 comments on commit fe7b3c9

Please sign in to comment.