REPO-1204 / MNT-16742: getChildren returns duplicate nodes

- fallout from MNT-12894
- noticed by customer when iterating via CMIS getChildren with no explict sort order
- we need to put back an implicit sort order, if none is specified
- note: todo - we could consider optimising further for those use-cases where maxItems is greater than a pre-configured threshold (eg. > 1000) and we don't expect to sensibly page through that many results

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@135457 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2017-02-27 16:09:00 +00:00
parent c35d81cf84
commit e9da15d93a
2 changed files with 93 additions and 26 deletions

View File

@@ -1,28 +1,28 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.node.getchildren;
import java.io.File;
@@ -74,6 +74,7 @@ import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.MimetypeService;
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.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
@@ -84,6 +85,7 @@ import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.AlfrescoCollator;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.GUID;
import org.alfresco.util.Pair;
import org.alfresco.util.PropertyMap;
import org.alfresco.util.registry.NamedObjectRegistry;
@@ -212,7 +214,7 @@ public class GetChildrenCannedQueryTest extends TestCase
bootstrap.setTenantService(tenantService);
bootstrap.bootstrap();
createUser(TEST_USER_PREFIX, TEST_USER, TEST_USER);
createUser(TEST_USER, TEST_USER, TEST_USER);
createUser(TEST_USER_PREFIX+"aaaa", TEST_USER_PREFIX+"bbbb", TEST_USER_PREFIX+"cccc");
createUser(TEST_USER_PREFIX+"cccc", TEST_USER_PREFIX+"dddd", TEST_USER_PREFIX+"eeee");
@@ -1509,4 +1511,68 @@ public class GetChildrenCannedQueryTest extends TestCase
personService.createPerson(ppOne);
}
}
// REPO-1204 / MNT-16742 (fallout from MNT-12894)
public void testPagingGetChildrenCannedQueryWithoutProps() throws Exception
{
try
{
long startTime = System.currentTimeMillis();
int itemCount = 1500;
int repeatListCount = 5;
Set<QName> assocTypeQNames = new HashSet<>(1);
assocTypeQNames.add(ContentModel.ASSOC_CONTAINS);
Set<QName> childTypeQNames = new HashSet<>(1);
childTypeQNames.add(ContentModel.TYPE_FOLDER);
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
NodeRef testFolder = repositoryHelper.getCompanyHome();
NodeRef parentFolder = createFolder(testFolder, "testCreateList-"+ GUID.generate(), ContentModel.TYPE_FOLDER);
for (int i = 1; i <= itemCount; i++)
{
String folderName = "folder_" + GUID.generate();
createFolder(parentFolder, folderName, ContentModel.TYPE_FOLDER);
}
for (int j = 1; j <= repeatListCount; j++)
{
// page/iterate through the children
boolean hasMore = true;
int skipCount = 0;
int maxItems = 100;
int count = 0;
Set<String> docIds = new HashSet<>(itemCount);
while (hasMore)
{
// note: mimic similar to AlfrescoServiceCmisServiceImpl
PagingResults<NodeRef> results = list(parentFolder, skipCount, maxItems, skipCount + 10000, assocTypeQNames, childTypeQNames, null, null, null, null);
hasMore = results.hasMoreItems();
skipCount = skipCount + maxItems;
for (NodeRef nodeRef : results.getPage())
{
docIds.add(nodeRef.getId());
count++;
}
}
assertEquals(itemCount, count);
assertEquals(itemCount, docIds.size());
}
System.out.println("Test time: " + (System.currentTimeMillis() - startTime) + " ms");
}
finally
{
AuthenticationUtil.clearCurrentSecurityContext();
}
}
}