Return-Path: Delivered-To: apmail-openjpa-commits-archive@www.apache.org Received: (qmail 79848 invoked from network); 8 Apr 2010 15:54:37 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Apr 2010 15:54:37 -0000 Received: (qmail 92020 invoked by uid 500); 8 Apr 2010 15:54:35 -0000 Delivered-To: apmail-openjpa-commits-archive@openjpa.apache.org Received: (qmail 91812 invoked by uid 500); 8 Apr 2010 15:54:35 -0000 Mailing-List: contact commits-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list commits@openjpa.apache.org Received: (qmail 91631 invoked by uid 99); 8 Apr 2010 15:54:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Apr 2010 15:54:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Apr 2010 15:54:27 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2B4082388A39; Thu, 8 Apr 2010 15:54:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Thu, 08 Apr 2010 15:54:06 -0000 To: commits@openjpa.apache.org From: dwoods@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100408155406.2B4082388A39@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ - 1204,1205,1222 + 1204,1205,1222,HY008 544,2601,2627,8114,8115 23000 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 hint = new HashMap(); + 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 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