From cde00286435a5dbcbcf3f570f1a062ae3c8572b3 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Thu, 18 Dec 2008 11:51:12 +0000 Subject: [PATCH] Merged V3.0 to HEAD 11829: Updated javadocs for RuntimeExec class 11830: Updated and wired in Spring source 11831: Fixed ETHREEOH-382: Can't run Lucene search via Node Browser 11832: Added unit test for V3.0 rev 11535 11834: Removed redundant TODO item 11835: ETHREEOH-798 Double clicking OK on most pop-up dialogs in Share causing multiple requests to be sent - and errors generated for the user 11836: Fix for a number of session based authentication and webscript authentication issues with NTLM from Share. Fixes ETHREEOH-806 and ETHREEOH-834 and first part of fix for ETHREEOH-789. 11838: Sharepoint Protocol Support 11843: Build fix 11846: Refactor of the SSO web filters (NTLM and Kerberos) for web-client and WebDAV. 11848: Added commented out entries for web-client and WebDAV Kerberos filter debugging. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12483 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../RetryingTransactionHelperTest.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/source/java/org/alfresco/repo/transaction/RetryingTransactionHelperTest.java b/source/java/org/alfresco/repo/transaction/RetryingTransactionHelperTest.java index 417bb79dae..ca89b6d152 100644 --- a/source/java/org/alfresco/repo/transaction/RetryingTransactionHelperTest.java +++ b/source/java/org/alfresco/repo/transaction/RetryingTransactionHelperTest.java @@ -24,11 +24,15 @@ */ package org.alfresco.repo.transaction; +import javax.transaction.Status; +import javax.transaction.UserTransaction; + import junit.framework.TestCase; import org.alfresco.error.ExceptionStackUtil; import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationComponent; +import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.repository.InvalidNodeRefException; @@ -164,6 +168,61 @@ public class RetryingTransactionHelperTest extends TestCase assertEquals("The txn value must be the same as the value after", afterValue, txnValue); } + /** + * Check that the transaction state can be fetched in and around the transaction. + * This also checks that any mischievous attempts to manipulate the transaction + * (other than setRollback) are detected. + */ + public void testUserTransactionStatus() + { + UserTransaction txnBefore = RetryingTransactionHelper.getActiveUserTransaction(); + assertNull("Did not expect to get an active UserTransaction", txnBefore); + + RetryingTransactionCallback callbackOuter = new RetryingTransactionCallback() + { + public Long execute() throws Throwable + { + final UserTransaction txnOuter = RetryingTransactionHelper.getActiveUserTransaction(); + assertNotNull("Expected an active UserTransaction", txnOuter); + assertEquals( + "Should be read-write txn", + TxnReadState.TXN_READ_WRITE, AlfrescoTransactionSupport.getTransactionReadState()); + assertEquals("Expected state is active", Status.STATUS_ACTIVE, txnOuter.getStatus()); + RetryingTransactionCallback callbackInner = new RetryingTransactionCallback() + { + public Long execute() throws Throwable + { + UserTransaction txnInner = RetryingTransactionHelper.getActiveUserTransaction(); + assertNotNull("Expected an active UserTransaction", txnInner); + assertEquals( + "Should be read-only txn", + TxnReadState.TXN_READ_ONLY, AlfrescoTransactionSupport.getTransactionReadState()); + assertEquals("Expected state is active", Status.STATUS_ACTIVE, txnInner.getStatus()); + // Check blow up + try + { + txnInner.commit(); + fail("Should not be able to commit the UserTransaction. It is for info only."); + } + catch (Throwable e) + { + // Expected + } + // Force a rollback + txnInner.setRollbackOnly(); + // Done + return null; + } + }; + return txnHelper.doInTransaction(callbackInner, true, true); + } + }; + txnHelper.doInTransaction(callbackOuter); + + UserTransaction txnAfter = RetryingTransactionHelper.getActiveUserTransaction(); + assertNull("Did not expect to get an active UserTransaction", txnAfter); + } + /** * Check that the retries happening for simple concurrency exceptions */