diff --git a/source/java/org/alfresco/repo/model/filefolder/FileFolderPerformanceTester.java b/source/java/org/alfresco/repo/model/filefolder/FileFolderPerformanceTester.java new file mode 100644 index 0000000000..fd99ea8596 --- /dev/null +++ b/source/java/org/alfresco/repo/model/filefolder/FileFolderPerformanceTester.java @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2005 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ +package org.alfresco.repo.model.filefolder; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.content.transform.AbstractContentTransformerTest; +import org.alfresco.repo.transaction.TransactionUtil; +import org.alfresco.repo.transaction.TransactionUtil.TransactionWork; +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.model.FileFolderService; +import org.alfresco.service.cmr.model.FileInfo; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.transaction.TransactionService; +import org.alfresco.util.ApplicationContextHelper; +import org.alfresco.util.GUID; +import org.springframework.context.ApplicationContext; + +/** + * Tests around some of the data structures that lead to performance + * degradation. We use the {@link org.alfresco.service.cmr.model.FileFolderService FileFolderService} + * as it provides the most convenient and most common test scenarios. + *
+ * Note that this test is not designed to validate performance figures, but is
+ * rather a handy tool for doing benchmarking. It is therefore not named *Test as is the
+ * pattern for getting tests run by the continuous build.
+ *
+ * @author Derek Hulley
+ */
+public class FileFolderPerformanceTester extends TestCase
+{
+ private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
+
+ private TransactionService transactionService;
+ private NodeService nodeService;
+ private FileFolderService fileFolderService;
+ private StoreRef storeRef;
+ private NodeRef rootFolderRef;
+ private File dataFile;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
+ transactionService = serviceRegistry.getTransactionService();
+ nodeService = serviceRegistry.getNodeService();
+ fileFolderService = serviceRegistry.getFileFolderService();
+
+ // create a folder root to work in
+ storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + "_" + System.currentTimeMillis());
+ NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
+ rootFolderRef = nodeService.createNode(
+ rootNodeRef,
+ ContentModel.ASSOC_CHILDREN,
+ QName.createQName(NamespaceService.ALFRESCO_URI, getName()),
+ ContentModel.TYPE_FOLDER).getChildRef();
+ dataFile = AbstractContentTransformerTest.loadQuickTestFile("txt");
+ }
+
+ public void testSetUp() throws Exception
+ {
+ assertNotNull(dataFile);
+ }
+
+ /**
+ * Creates folderCount
folders below the given parent and populates each folder with
+ * fileCount
files. The folders will be created as siblings in one go, but the files
+ * are added one to each folder until each folder has the presribed number of files within it.
+ * This can therefore be used to test the performance when the L2 cache sizes are exceeded.
+ *
+ * Each creation (file or folder) uses the REQUIRES_NEW transaction declaration.
+ *
+ * @param parentNodeRef the level zero parent
+ * @return Returns the average time (ms) to create the files only
+ */
+ private double buildStructure(final NodeRef parentNodeRef, final int folderCount, final int fileCount)
+ {
+ List