Skip to content

Commit dc82b81

Browse files
committed
Various code cleanup
1 parent a570566 commit dc82b81

File tree

3 files changed

+65
-35
lines changed

3 files changed

+65
-35
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/interceptor/InterceptorTest.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
package org.hibernate.orm.test.interceptor;
66

7-
import jakarta.persistence.PersistenceException;
87
import jakarta.persistence.criteria.CriteriaBuilder;
98
import jakarta.persistence.criteria.CriteriaQuery;
109
import java.util.LinkedList;
@@ -26,13 +25,11 @@
2625
import org.hibernate.resource.jdbc.spi.StatementInspector;
2726
import org.hibernate.type.Type;
2827

29-
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
3028
import static org.junit.Assert.assertEquals;
3129
import static org.junit.Assert.assertNotNull;
3230
import static org.junit.Assert.assertNull;
3331
import static org.junit.Assert.assertSame;
3432
import static org.junit.Assert.assertTrue;
35-
import static org.junit.Assert.fail;
3633

3734
/**
3835
* @author Gavin King
@@ -139,37 +136,6 @@ public boolean onFlushDirty(
139136

140137
}
141138

142-
/**
143-
* Test that setting a transaction timeout will cause an Exception to occur
144-
* if the transaction timeout is exceeded.
145-
*/
146-
@Test
147-
public void testTimeout() throws Exception {
148-
final int TIMEOUT = 2;
149-
final int WAIT = TIMEOUT + 1;
150-
Session s = openSession();
151-
// Get the transaction and set the timeout BEFORE calling begin()
152-
Transaction t = s.getTransaction();
153-
t.setTimeout( TIMEOUT );
154-
t.begin();
155-
// Sleep for an amount of time that exceeds the transaction timeout
156-
Thread.sleep( WAIT * 1000 );
157-
try {
158-
// Do something with the transaction and try to commit it
159-
s.persist( new User( "john", "test" ) );
160-
t.commit();
161-
fail( "Transaction should have timed out" );
162-
}
163-
catch (PersistenceException e) {
164-
assertTyping( TransactionException.class, e );
165-
assertTrue(
166-
"Transaction failed for the wrong reason. Expecting transaction timeout, but found [" +
167-
e.getMessage() + "]",
168-
e.getMessage().contains( "transaction timeout expired" )
169-
);
170-
}
171-
}
172-
173139
@Test
174140
public void testComponentInterceptor() {
175141
final int checkPerm = 500;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.resource.transaction;
6+
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.PersistenceException;
10+
import jakarta.persistence.Table;
11+
import org.hibernate.Transaction;
12+
import org.hibernate.TransactionException;
13+
import org.hibernate.testing.orm.junit.DomainModel;
14+
import org.hibernate.testing.orm.junit.SessionFactory;
15+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
16+
import org.junit.jupiter.api.Test;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.junit.jupiter.api.Assertions.fail;
20+
21+
/**
22+
* Test behavior of transaction timeouts
23+
*
24+
* @author Steve Ebersole
25+
*/
26+
@SuppressWarnings("JUnitMalformedDeclaration")
27+
@DomainModel(annotatedClasses = TransactionTimeoutTests.Person.class)
28+
@SessionFactory
29+
public class TransactionTimeoutTests {
30+
@Test
31+
void testJdbcTxn(SessionFactoryScope sessions) {
32+
sessions.inSession( (session) -> {
33+
final Transaction transaction = session.getTransaction();
34+
// timeout in 2 seconds
35+
transaction.setTimeout( 2 );
36+
37+
// start the transaction and sleep for 3 seconds to exceed the transaction timeout
38+
transaction.begin();
39+
try {
40+
Thread.sleep( 3 * 1000 );
41+
}
42+
catch (InterruptedException e) {
43+
throw new RuntimeException( "Thread#sleep error", e );
44+
}
45+
try {
46+
// perform an operation against the db and try to commit the transaction
47+
session.createSelectionQuery( "from Person", Person.class ).list();
48+
transaction.commit();
49+
fail( "Transaction should have timed out" );
50+
}
51+
catch (PersistenceException e) {
52+
assertThat( e ).isInstanceOf( TransactionException.class );
53+
assertThat( e ).hasMessageContaining( "transaction timeout expired" );
54+
}
55+
} );
56+
}
57+
58+
@Entity(name="Person")
59+
@Table(name="persons")
60+
public static class Person {
61+
@Id
62+
private Integer id;
63+
private String name;
64+
}
65+
}

hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/SchemaExportTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import static org.hamcrest.core.Is.is;
3131
import static org.junit.Assert.assertEquals;
3232
import static org.junit.Assert.assertThat;
33-
import static org.junit.Assert.assertTrue;
3433

3534
/**
3635
* @author Gail Badner

0 commit comments

Comments
 (0)