mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-16 17:55:15 +00:00
6556: AVM performance tweaks 6557: WCM-758. 6558: Fixes WCM-753. 6559: better handling of rename, copy and paste for form instance data and renditions. addresses WCM-752 and partially addresses WCM-559. 6560: Renamed JndiTest.java until we decide to keep it or not. 6561: Oops. 6562: probable fix WCM-669 6563: Build fix after the removal of flushing suport 6564: Fix for WCM-728 6566: Support for avm index clustering via tracking - WCM-762 6567: Test fix after flush changes 6568: Fixed AWC-1517: Can now create space based on existing top-level space 6569: misc IE fixes. 6570: Various changes to improve AVM import performance and submit performance. 6571: Session flushing is now deprecated and doesn't fail with an exception. 6572: Reduced the iteration count to stress nextResults calls a bit more 6573: WS query sessions put back into cache after more results have been fetched. 6574: AR-1347: RepositoryServiceSoapBindingStub.queryAssociated() returns nothing when direction=target 6575: Fixed AR-1680: XPath metadata extraction now handles Node, NodeList and String return values 6577: Fix for AWC-1518 (User Homes renaming issue, and unreported issue with client config overriding of users home location) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6745 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
240 lines
9.9 KiB
Java
240 lines
9.9 KiB
Java
/*
|
|
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* As a special exception to the terms and conditions of version 2.0 of
|
|
* the GPL, you may redistribute this Program in connection with Free/Libre
|
|
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
|
* FLOSS exception. You should have recieved a copy of the text describing
|
|
* the FLOSS exception, and it is also available here:
|
|
* http://www.alfresco.com/legal/licensing"
|
|
*/
|
|
package org.alfresco.repo.transaction;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import javax.transaction.UserTransaction;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
|
import org.alfresco.service.ServiceRegistry;
|
|
import org.alfresco.service.transaction.TransactionService;
|
|
import org.alfresco.util.ApplicationContextHelper;
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
/**
|
|
* Tests integration between our <tt>UserTransaction</tt> implementation and
|
|
* our <tt>TransactionManager</tt>.
|
|
*
|
|
* @see org.alfresco.repo.transaction.AlfrescoTransactionManager
|
|
* @see org.alfresco.util.transaction.SpringAwareUserTransaction
|
|
*
|
|
* @author Derek Hulley
|
|
*/
|
|
public class AlfrescoTransactionSupportTest extends TestCase
|
|
{
|
|
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
|
|
|
private ServiceRegistry serviceRegistry;
|
|
TransactionService transactionService;
|
|
|
|
public void setUp() throws Exception
|
|
{
|
|
serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
|
transactionService = serviceRegistry.getTransactionService();
|
|
}
|
|
|
|
public void testTransactionId() throws Exception
|
|
{
|
|
// get a user transaction
|
|
TransactionService transactionService = serviceRegistry.getTransactionService();
|
|
UserTransaction txn = transactionService.getUserTransaction();
|
|
assertNull("Thread shouldn't have a txn ID", AlfrescoTransactionSupport.getTransactionId());
|
|
assertEquals("No transaction start time expected", -1, AlfrescoTransactionSupport.getTransactionStartTime());
|
|
|
|
// begin the txn
|
|
txn.begin();
|
|
String txnId = AlfrescoTransactionSupport.getTransactionId();
|
|
assertNotNull("Expected thread to have a txn id", txnId);
|
|
long txnStartTime = AlfrescoTransactionSupport.getTransactionStartTime();
|
|
assertTrue("Expected a transaction start time", txnStartTime > 0);
|
|
|
|
// check that the txn id and time doesn't change
|
|
String txnIdCheck = AlfrescoTransactionSupport.getTransactionId();
|
|
assertEquals("Transaction ID changed on same thread", txnId, txnIdCheck);
|
|
long txnStartTimeCheck = AlfrescoTransactionSupport.getTransactionStartTime();
|
|
assertEquals("Transaction start time changed on same thread", txnStartTime, txnStartTimeCheck);
|
|
|
|
// begin a new, inner transaction
|
|
{
|
|
UserTransaction txnInner = transactionService.getNonPropagatingUserTransaction();
|
|
|
|
String txnIdInner = AlfrescoTransactionSupport.getTransactionId();
|
|
assertEquals("Inner transaction not started, so txn ID should not change", txnId, txnIdInner);
|
|
long txnStartTimeInner = AlfrescoTransactionSupport.getTransactionStartTime();
|
|
assertEquals("Inner transaction not started, so txn start time should not change", txnStartTime, txnStartTimeInner);
|
|
|
|
// begin the nested txn
|
|
txnInner.begin();
|
|
// check the ID for the outer transaction
|
|
txnIdInner = AlfrescoTransactionSupport.getTransactionId();
|
|
assertNotSame("Inner txn ID must be different from outer txn ID", txnIdInner, txnId);
|
|
// Check the time against the outer transaction
|
|
txnStartTimeInner = AlfrescoTransactionSupport.getTransactionStartTime();
|
|
assertTrue(
|
|
"Inner transaction start time should be greater or equal (accuracy) to the outer's",
|
|
txnStartTime <= txnStartTimeInner);
|
|
|
|
// rollback the nested txn
|
|
txnInner.rollback();
|
|
txnIdCheck = AlfrescoTransactionSupport.getTransactionId();
|
|
assertEquals("Txn ID not popped inner txn completion", txnId, txnIdCheck);
|
|
}
|
|
|
|
// rollback
|
|
txn.rollback();
|
|
assertNull("Thread shouldn't have a txn ID after rollback", AlfrescoTransactionSupport.getTransactionId());
|
|
|
|
// start a new transaction
|
|
txn = transactionService.getUserTransaction();
|
|
txn.begin();
|
|
txnIdCheck = AlfrescoTransactionSupport.getTransactionId();
|
|
assertNotSame("New transaction has same ID", txnId, txnIdCheck);
|
|
|
|
// rollback
|
|
txn.rollback();
|
|
assertNull("Thread shouldn't have a txn ID after rollback", AlfrescoTransactionSupport.getTransactionId());
|
|
}
|
|
|
|
public void testListener() throws Exception
|
|
{
|
|
final List<String> strings = new ArrayList<String>(1);
|
|
|
|
// anonymous inner class to test it
|
|
TransactionListener listener = new TransactionListener()
|
|
{
|
|
public void flush()
|
|
{
|
|
strings.add("flush");
|
|
}
|
|
public void beforeCommit(boolean readOnly)
|
|
{
|
|
strings.add("beforeCommit");
|
|
}
|
|
public void beforeCompletion()
|
|
{
|
|
strings.add("beforeCompletion");
|
|
}
|
|
public void afterCommit()
|
|
{
|
|
strings.add("afterCommit");
|
|
}
|
|
public void afterRollback()
|
|
{
|
|
strings.add("afterRollback");
|
|
}
|
|
};
|
|
|
|
// begin a transaction
|
|
UserTransaction txn = transactionService.getUserTransaction();
|
|
txn.begin();
|
|
|
|
// register it
|
|
AlfrescoTransactionSupport.bindListener(listener);
|
|
|
|
// test commit
|
|
txn.commit();
|
|
assertTrue("beforeCommit not called on listener", strings.contains("beforeCommit"));
|
|
assertTrue("beforeCompletion not called on listener", strings.contains("beforeCompletion"));
|
|
assertTrue("afterCommit not called on listener", strings.contains("afterCommit"));
|
|
}
|
|
|
|
/**
|
|
* Tests the condition whereby a listener can cause failure by attempting to bind itself to
|
|
* the transaction in the pre-commit callback. This is caused by the listener set being
|
|
* modified during calls to the listeners.
|
|
*/
|
|
public void testPreCommitListenerBinding() throws Exception
|
|
{
|
|
final String beforeCommit = "beforeCommit";
|
|
final String afterCommitInner = "afterCommit - inner";
|
|
final String afterCommitOuter = "afterCommit = outer";
|
|
|
|
// the listeners will play with this
|
|
final List<String> testList = new ArrayList<String>(1);
|
|
testList.add(beforeCommit);
|
|
testList.add(afterCommitInner);
|
|
testList.add(afterCommitOuter);
|
|
|
|
final TransactionListener listener = new TransactionListenerAdapter()
|
|
{
|
|
@Override
|
|
public int hashCode()
|
|
{
|
|
// force this listener to be first in the bound set
|
|
return 100;
|
|
}
|
|
@Override
|
|
public void beforeCommit(boolean readOnly)
|
|
{
|
|
testList.remove(beforeCommit);
|
|
TransactionListener postCommitListener = new TransactionListenerAdapter()
|
|
{
|
|
@Override
|
|
public void afterCommit()
|
|
{
|
|
testList.remove(afterCommitInner);
|
|
}
|
|
};
|
|
// register bogus on the transaction
|
|
AlfrescoTransactionSupport.bindListener(postCommitListener);
|
|
}
|
|
@Override
|
|
public void afterCommit()
|
|
{
|
|
testList.remove(afterCommitOuter);
|
|
}
|
|
};
|
|
final TransactionListener dummyListener = new TransactionListenerAdapter()
|
|
{
|
|
@Override
|
|
public int hashCode()
|
|
{
|
|
// force the dummy listener to be AFTER the binding listener
|
|
return 200;
|
|
}
|
|
};
|
|
// start a transaction
|
|
RetryingTransactionCallback<Object> bindWork = new RetryingTransactionCallback<Object>()
|
|
{
|
|
public Object execute() throws Exception
|
|
{
|
|
// just bind the listener to the transaction
|
|
AlfrescoTransactionSupport.bindListener(dummyListener);
|
|
AlfrescoTransactionSupport.bindListener(listener);
|
|
return null;
|
|
}
|
|
};
|
|
// kick it all off
|
|
transactionService.getRetryingTransactionHelper().doInTransaction(bindWork);
|
|
|
|
// make sure that the binding all worked
|
|
assertTrue("Expected callbacks not all processed: " + testList, testList.size() == 0);
|
|
}
|
|
}
|