HHH-18866 - Fix CockroachDB test failures
This commit is contained in:
parent
de3408662c
commit
5d2c58982e
|
@ -14,10 +14,12 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import jakarta.persistence.RollbackException;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.community.dialect.DerbyDialect;
|
||||
import org.hibernate.dialect.CockroachDialect;
|
||||
import org.hibernate.dialect.OracleDialect;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.dialect.SybaseDialect;
|
||||
|
@ -117,8 +119,14 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
|
|||
parallelTx.commit();
|
||||
fail( "All optimistic locking should have make it fail" );
|
||||
}
|
||||
catch (OptimisticLockException e) {
|
||||
if ( parallelTx != null ) parallelTx.rollback();
|
||||
catch (Exception e) {
|
||||
if (getDialect() instanceof CockroachDialect) {
|
||||
// CockroachDB always runs in SERIALIZABLE isolation, and throws a RollbackException
|
||||
assertTrue( e instanceof RollbackException );
|
||||
} else {
|
||||
assertTrue( e instanceof OptimisticLockException );
|
||||
}
|
||||
parallelTx.rollback();
|
||||
}
|
||||
finally {
|
||||
parallelSession.close();
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import jakarta.persistence.RollbackException;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.CockroachDialect;
|
||||
|
||||
|
@ -29,7 +30,7 @@ import static org.junit.Assert.fail;
|
|||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
public class BatchOptimisticLockingTest extends
|
||||
public class BatchOptimisticLockingTest extends
|
||||
BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
|
@ -94,17 +95,18 @@ public class BatchOptimisticLockingTest extends
|
|||
} );
|
||||
}
|
||||
catch (Exception expected) {
|
||||
assertEquals( OptimisticLockException.class, expected.getClass() );
|
||||
if ( getDialect() instanceof CockroachDialect ) {
|
||||
// CockroachDB always runs in SERIALIZABLE isolation, and uses SQL state 40001 to indicate
|
||||
// serialization failure.
|
||||
var msg = "org.hibernate.exception.LockAcquisitionException: could not execute batch";
|
||||
// serialization failure. The failure is mapped to a RollbackException.
|
||||
assertEquals( RollbackException.class, expected.getClass() );
|
||||
var msg = "could not execute batch";
|
||||
assertEquals(
|
||||
"org.hibernate.exception.LockAcquisitionException: could not execute batch",
|
||||
msg,
|
||||
expected.getMessage().substring( 0, msg.length() )
|
||||
);
|
||||
}
|
||||
else {
|
||||
assertEquals( OptimisticLockException.class, expected.getClass() );
|
||||
assertTrue(
|
||||
expected.getMessage()
|
||||
.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=?]")
|
||||
|
|
|
@ -6,6 +6,7 @@ package org.hibernate.orm.test.mapping.naturalid.compound;
|
|||
|
||||
import org.hibernate.annotations.NaturalId;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.CockroachDialect;
|
||||
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
|
||||
import org.hibernate.query.criteria.JpaCriteriaQuery;
|
||||
|
||||
|
@ -15,6 +16,7 @@ import org.hibernate.testing.orm.junit.ServiceRegistry;
|
|||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -41,6 +43,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@SkipForDialect(
|
||||
dialectClass = CockroachDialect.class,
|
||||
reason = "On CockroachDB the difference between simple and compound natural id is very high"
|
||||
)
|
||||
public class CompoundNaturalIdTest {
|
||||
|
||||
private static final int OBJECT_NUMBER = 2000;
|
||||
|
|
Loading…
Reference in New Issue