HHH-11617 : Update test to work on 5.1

This commit is contained in:
Gail Badner 2018-04-27 16:15:27 -07:00
parent 95e3ca1831
commit 34df214981
2 changed files with 29 additions and 15 deletions

View File

@ -7,6 +7,7 @@
package org.hibernate.test.util.jdbc;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.Connection;
@ -119,14 +120,19 @@ private static class PreparedStatementHandler implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
final Object returnValue = method.invoke( actualPreparedStatement, args );
preparedStatementObserver.preparedStatementMethodInvoked(
(PreparedStatement) proxy,
method,
args,
returnValue
);
return returnValue;
try {
final Object returnValue = method.invoke( actualPreparedStatement, args );
preparedStatementObserver.preparedStatementMethodInvoked(
(PreparedStatement) proxy,
method,
args,
returnValue
);
return returnValue;
}
catch (InvocationTargetException ex) {
throw ex.getTargetException();
}
}
}
}

View File

@ -13,11 +13,11 @@
import javax.persistence.EntityManager;
import javax.persistence.LockModeType;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.test.util.jdbc.BasicPreparedStatementObserver;
import org.hibernate.test.util.jdbc.PreparedStatementObserver;
@ -72,9 +72,12 @@ public void releaseResources() {
CONNECTION_PROVIDER.stop();
}
@Test(timeout = 1000 * 10) //10 seconds
// Setting AvailableSettings.LOCK_TIMEOUT to 0 does not work consistently for "no wait" locking
// and there is no consistent way to set this. For now, just test on H2 because it may
// hang on other dialects.
@Test
@TestForIssue(jiraKey = "HHH-11617")
@RequiresDialectFeature(value = DialectChecks.SupportsLockTimeouts.class,
@RequiresDialect(value = H2Dialect.class,
comment = "Test verifies statement is closed after a lock excpetion.",
jiraKey = "HHH-11617")
public void testStatementIsClosed() {
@ -84,14 +87,19 @@ public void testStatementIsClosed() {
{
Map<String, Object> properties = new HashMap<String, Object>();
properties.put( AvailableSettings.LOCK_TIMEOUT, 0L );
Lock lock2 = entityManager.find( Lock.class, lockId, LockModeType.PESSIMISTIC_WRITE, properties );
Lock lock2 = entityManager.find(
Lock.class,
lockId,
LockModeType.PESSIMISTIC_WRITE,
properties
);
assertEquals(
"lock mode should be PESSIMISTIC_WRITE ",
LockModeType.PESSIMISTIC_WRITE,
entityManager.getLockMode( lock2 )
);
EntityManager entityManager2 = createEntityManager();
EntityManager entityManager2 = createIsolatedEntityManager();
entityManager2.getTransaction().begin();
{
try {
@ -117,7 +125,7 @@ public void testStatementIsClosed() {
}
}
}
entityManager2.getTransaction().commit();
entityManager2.getTransaction().setRollbackOnly();
entityManager2.close();
}
entityManager.getTransaction().commit();