Skip to content

Commit 894fa84

Browse files
maesenkabeikov
authored andcommitted
HHH-18866 - Fix CockroachDB test failures
1 parent 2109556 commit 894fa84

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entity/BasicHibernateAnnotationsTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
import java.util.Locale;
1515
import java.util.Set;
1616

17+
import jakarta.persistence.RollbackException;
1718
import org.hibernate.Hibernate;
1819
import org.hibernate.Session;
1920
import org.hibernate.Transaction;
2021
import org.hibernate.community.dialect.DerbyDialect;
22+
import org.hibernate.dialect.CockroachDialect;
2123
import org.hibernate.dialect.OracleDialect;
2224
import org.hibernate.dialect.PostgreSQLDialect;
2325
import org.hibernate.dialect.SybaseDialect;
@@ -117,8 +119,14 @@ public void testVersioning() throws Exception {
117119
parallelTx.commit();
118120
fail( "All optimistic locking should have make it fail" );
119121
}
120-
catch (OptimisticLockException e) {
121-
if ( parallelTx != null ) parallelTx.rollback();
122+
catch (Exception e) {
123+
if (getDialect() instanceof CockroachDialect) {
124+
// CockroachDB always runs in SERIALIZABLE isolation, and throws a RollbackException
125+
assertTrue( e instanceof RollbackException );
126+
} else {
127+
assertTrue( e instanceof OptimisticLockException );
128+
}
129+
parallelTx.rollback();
122130
}
123131
finally {
124132
parallelSession.close();

hibernate-core/src/test/java/org/hibernate/orm/test/batch/BatchOptimisticLockingTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.concurrent.ExecutorService;
1111
import java.util.concurrent.Executors;
1212

13+
import jakarta.persistence.RollbackException;
1314
import org.hibernate.cfg.AvailableSettings;
1415
import org.hibernate.dialect.CockroachDialect;
1516

@@ -29,7 +30,7 @@
2930
/**
3031
* @author Vlad Mihalcea
3132
*/
32-
public class BatchOptimisticLockingTest extends
33+
public class BatchOptimisticLockingTest extends
3334
BaseNonConfigCoreFunctionalTestCase {
3435

3536
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
@@ -94,17 +95,18 @@ public void testBatchAndOptimisticLocking() {
9495
} );
9596
}
9697
catch (Exception expected) {
97-
assertEquals( OptimisticLockException.class, expected.getClass() );
9898
if ( getDialect() instanceof CockroachDialect ) {
9999
// CockroachDB always runs in SERIALIZABLE isolation, and uses SQL state 40001 to indicate
100-
// serialization failure.
101-
var msg = "org.hibernate.exception.LockAcquisitionException: could not execute batch";
100+
// serialization failure. The failure is mapped to a RollbackException.
101+
assertEquals( RollbackException.class, expected.getClass() );
102+
var msg = "could not execute batch";
102103
assertEquals(
103-
"org.hibernate.exception.LockAcquisitionException: could not execute batch",
104+
msg,
104105
expected.getMessage().substring( 0, msg.length() )
105106
);
106107
}
107108
else {
109+
assertEquals( OptimisticLockException.class, expected.getClass() );
108110
assertTrue(
109111
expected.getMessage()
110112
.startsWith("Batch update returned unexpected row count from update 1 (expected row count 1 but was 0) [update Person set name=?,version=? where id=? and version=?]")

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/compound/CompoundNaturalIdTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.hibernate.annotations.NaturalId;
88
import org.hibernate.cfg.AvailableSettings;
9+
import org.hibernate.dialect.CockroachDialect;
910
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
1011
import org.hibernate.query.criteria.JpaCriteriaQuery;
1112

@@ -15,6 +16,7 @@
1516
import org.hibernate.testing.orm.junit.SessionFactory;
1617
import org.hibernate.testing.orm.junit.SessionFactoryScope;
1718
import org.hibernate.testing.orm.junit.Setting;
19+
import org.hibernate.testing.orm.junit.SkipForDialect;
1820
import org.junit.jupiter.api.BeforeAll;
1921
import org.junit.jupiter.api.Test;
2022

@@ -41,6 +43,10 @@
4143
}
4244
)
4345
@SessionFactory
46+
@SkipForDialect(
47+
dialectClass = CockroachDialect.class,
48+
reason = "On CockroachDB the difference between simple and compound natural id is very high"
49+
)
4450
public class CompoundNaturalIdTest {
4551

4652
private static final int OBJECT_NUMBER = 2000;

0 commit comments

Comments
 (0)