mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged V2.0 to HEAD
5447: (From V1.4 5278, 5279, 5280, 5285, 5298, 5299, 5304): Hibernate session size management for large transactions git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5481 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -36,6 +36,8 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.dictionary.DictionaryComponent;
|
||||
@@ -1042,12 +1044,6 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
|
||||
ASSOC_TYPE_QNAME_TEST_CHILDREN,
|
||||
QName.createQName("pathA"),
|
||||
TYPE_QNAME_TEST_MULTIPLE_TESTER).getChildRef();
|
||||
// commit as we will be breaking the transaction in the test
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
// each of these tests will be in a new transaction started by the NodeService
|
||||
|
||||
ArrayList<String> values = new ArrayList<String>(1);
|
||||
values.add("ABC");
|
||||
values.add("DEF");
|
||||
@@ -1062,15 +1058,26 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
|
||||
nodeService.setProperty(nodeRef, PROP_QNAME_ANY_PROP_MULTIPLE, values);
|
||||
nodeService.setProperty(nodeRef, undeclaredPropQName, "ABC");
|
||||
nodeService.setProperty(nodeRef, undeclaredPropQName, values);
|
||||
// this should fail as we are passing multiple values into a non-any that is multiple=false
|
||||
|
||||
// commit as we will be breaking the transaction in the next test
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
UserTransaction txn = transactionService.getUserTransaction();
|
||||
try
|
||||
{
|
||||
txn.begin();
|
||||
// this should fail as we are passing multiple values into a non-any that is multiple=false
|
||||
nodeService.setProperty(nodeRef, PROP_QNAME_STRING_PROP_SINGLE, values);
|
||||
}
|
||||
catch (DictionaryException e)
|
||||
{
|
||||
// expected
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { txn.rollback(); } catch (Throwable e) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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.node.db.hibernate;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.node.BaseNodeServiceTest;
|
||||
import org.alfresco.repo.node.db.DbNodeServiceImpl;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.repo.transaction.TransactionResourceInterceptor;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Tests the session size limiters in the context of a full stack.
|
||||
*
|
||||
* @see org.alfresco.util.resource.MethodResourceManager
|
||||
* @see org.alfresco.repo.transaction.TransactionResourceInterceptor
|
||||
* @see org.alfresco.repo.domain.hibernate.SessionSizeResourceManager
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class SessionSizeManagementTest extends BaseNodeServiceTest
|
||||
{
|
||||
private TransactionResourceInterceptor interceptor;
|
||||
private Method createNodesMethod;
|
||||
|
||||
public SessionSizeManagementTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
Class clazz = SessionSizeManagementTest.class;
|
||||
createNodesMethod = clazz.getMethod(
|
||||
"createNodes",
|
||||
new Class[] {NodeService.class, Integer.TYPE, Boolean.TYPE});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException("Instantiation failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config locations
|
||||
*
|
||||
* @return an array containing the config locations
|
||||
*/
|
||||
protected String[] getConfigLocations()
|
||||
{
|
||||
return new String[] {"session-size-test-context.xml"};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NodeService getNodeService()
|
||||
{
|
||||
NodeService nodeService = (NodeService) applicationContext.getBean("testSessionSizeDbNodeService");
|
||||
return nodeService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
super.onSetUpInTransaction();
|
||||
// Get the interceptor for manual testing
|
||||
interceptor = (TransactionResourceInterceptor) applicationContext.getBean("testSessionSizeResourceInterceptor");
|
||||
}
|
||||
|
||||
/** Helper to create a given number of nodes using the provided service */
|
||||
public void createNodes(NodeService nodeService, int count, boolean manualFlush)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
long beforeNs = System.nanoTime();
|
||||
nodeService.createNode(
|
||||
rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "child-" + i),
|
||||
ContentModel.TYPE_FOLDER);
|
||||
long deltaNs = System.nanoTime() - beforeNs;
|
||||
// Perform manual flush if necessary
|
||||
if (manualFlush)
|
||||
{
|
||||
interceptor.performManualCheck(createNodesMethod, deltaNs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final int LOAD_COUNT = 1000;
|
||||
/**
|
||||
* Create a bunch of nodes and see that the auto-clear is working
|
||||
*/
|
||||
public synchronized void testBulkLoad() throws Exception
|
||||
{
|
||||
NodeService nodeService = getNodeService();
|
||||
createNodes(nodeService, LOAD_COUNT, false);
|
||||
// We can't check the session size as this is dependent on machine speed
|
||||
|
||||
// Now flush integrity to be sure things are not broken
|
||||
AlfrescoTransactionSupport.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a bunch of nodes and see that the manual clearing is working. The
|
||||
* original node service is used for this.
|
||||
*/
|
||||
public synchronized void testManualOperation() throws Exception
|
||||
{
|
||||
NodeService nodeService = (NodeService) applicationContext.getBean("dbNodeServiceImpl");
|
||||
if (!(nodeService instanceof DbNodeServiceImpl))
|
||||
{
|
||||
fail("This test requires the unwrapped raw DbNodeServiceImpl");
|
||||
}
|
||||
|
||||
createNodes(nodeService, LOAD_COUNT, true);
|
||||
// Check the session size
|
||||
int entityCount = getSession().getStatistics().getEntityCount();
|
||||
assertTrue("Manual flush: Entity count should be less than " + LOAD_COUNT, entityCount < LOAD_COUNT);
|
||||
|
||||
// Now flush integrity to be sure things are not broken
|
||||
AlfrescoTransactionSupport.flush();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user