You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by dw...@apache.org on 2010/04/08 17:54:06 UTC
svn commit: r931982 - in /openjpa/branches/2.0.x:
openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestTimeoutException.java
Author: dwoods
Date: Thu Apr 8 15:54:05 2010
New Revision: 931982
URL: http://svn.apache.org/viewvc?rev=931982&view=rev
Log:
OPENJPA-1616 Fix TestTimeoutException test failures on MSSQL. Merged in from trunk r931693.
Modified:
openjpa/branches/2.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestTimeoutException.java
Modified: openjpa/branches/2.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml?rev=931982&r1=931981&r2=931982&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml (original)
+++ openjpa/branches/2.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml Thu Apr 8 15:54:05 2010
@@ -47,7 +47,7 @@
</dictionary>
<dictionary class="org.apache.openjpa.jdbc.sql.SQLServerDictionary">
- <lock>1204,1205,1222</lock>
+ <lock>1204,1205,1222,HY008</lock>
<referential-integrity>544,2601,2627,8114,8115</referential-integrity>
<object-exists>23000</object-exists>
<object-not-found></object-not-found>
Modified: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestTimeoutException.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestTimeoutException.java?rev=931982&r1=931981&r2=931982&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestTimeoutException.java (original)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestTimeoutException.java Thu Apr 8 15:54:05 2010
@@ -13,6 +13,7 @@
*/
package org.apache.openjpa.persistence.query;
+import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
@@ -44,10 +45,13 @@ public class TestTimeoutException extend
setUnsupportedDatabases(OracleDictionary.class, DB2Dictionary.class);
if (isTestsDisabled())
return;
- super.setUp(entityClass);
+ super.setUp(entityClass, CLEAR_TABLES);
}
public void testQueryTimeOutExceptionWhileQueryingWithLocksOnAlreadyLockedEntities() {
+ if (getLog().isTraceEnabled())
+ getLog().trace("***** Entered TestTimeoutException." +
+ "testQueryTimeOutExceptionWhileQueryingWithLocksOnAlreadyLockedEntities()");
EntityManager em1 = emf.createEntityManager();
EntityManager em2 = emf.createEntityManager();
assertNotSame(em1, em2);
@@ -76,6 +80,9 @@ public class TestTimeoutException extend
}
public void testLockTimeOutExceptionWhileLockingAlreadyLockedEntities() {
+ if (getLog().isTraceEnabled())
+ getLog().trace("***** Entered TestTimeoutException." +
+ "testLockTimeOutExceptionWhileLockingAlreadyLockedEntities()");
EntityManager em1 = emf.createEntityManager();
final EntityManager em2 = emf.createEntityManager();
assertNotSame(em1, em2);
@@ -104,6 +111,10 @@ public class TestTimeoutException extend
}
public void testQueryTimeOutExceptionWhileFindWithLocksOnAlreadyLockedEntities() {
+ final int timeout = 1000;
+ if (getLog().isTraceEnabled())
+ getLog().trace("***** Entered TestTimeoutException." +
+ "testQueryTimeOutExceptionWhileFindWithLocksOnAlreadyLockedEntities()");
EntityManager em1 = emf.createEntityManager();
EntityManager em2 = emf.createEntityManager();
assertNotSame(em1, em2);
@@ -116,7 +127,11 @@ public class TestTimeoutException extend
em2.getTransaction().begin();
try {
- em2.find(entityClass, oid, LockModeType.PESSIMISTIC_WRITE);
+ Map<String,Object> hint = new HashMap<String, Object>();
+ hint.put("javax.persistence.lock.timeout", timeout);
+ //em2.setProperty("javax.persistence.lock.timeout", timeout);
+
+ em2.find(entityClass, oid, LockModeType.PESSIMISTIC_WRITE, hint);
fail("Expected " + LockTimeoutException.class.getName());
} catch (Throwable t) {
assertError(t, LockTimeoutException.class);
@@ -146,9 +161,10 @@ public class TestTimeoutException extend
*/
void assertError(Throwable actual, Class<? extends Throwable> expected) {
if (!expected.isAssignableFrom(actual.getClass())) {
- actual.printStackTrace();
- throw new AssertionFailedError(actual.getClass().getName() + " was raised but expected " +
- expected.getName());
+ getLog().error("TestTimeoutException.assertError() - unexpected exception type", actual);
+ //actual.printStackTrace();
+ print(actual, 0);
+ fail(actual.getClass().getName() + " was raised but expected " + expected.getName());
}
Object failed = getFailedObject(actual);
assertNotNull("Failed object is null", failed);
@@ -156,19 +172,36 @@ public class TestTimeoutException extend
}
Object getFailedObject(Throwable e) {
- if (e instanceof LockTimeoutException) {
+ if (e == null) {
+ getLog().error("TestTimeoutException.getFailedObject() - Object e was null");
+ return null;
+ } else if (e instanceof LockTimeoutException) {
return ((LockTimeoutException) e).getObject();
- }
- if (e instanceof PessimisticLockException) {
+ } else if (e instanceof PessimisticLockException) {
return ((PessimisticLockException) e).getEntity();
- }
- if (e instanceof QueryTimeoutException) {
+ } else if (e instanceof QueryTimeoutException) {
return ((QueryTimeoutException) e).getQuery();
- }
- if (e instanceof OpenJPAException) {
+ } else if (e instanceof OpenJPAException) {
return ((OpenJPAException) e).getFailedObject();
+ } else {
+ getLog().error("TestTimeoutException.getFailedObject() - unexpected exception type", e);
+ return null;
}
- return null;
}
-
+
+ void print(Throwable t, int tab) {
+ if (t == null) return;
+ StringBuilder str = new StringBuilder(80);
+ for (int i=0; i<tab*4;i++)
+ str.append(" ");
+ String sqlState = (t instanceof SQLException) ?
+ "(SQLState=" + ((SQLException)t).getSQLState() + ":"
+ + t.getMessage() + ")" : "";
+ str.append(t.getClass().getName() + sqlState);
+ getLog().error(str);
+ if (t.getCause() == t)
+ return;
+ print(t.getCause(), tab+1);
+ }
+
}