From a014faeac09b922dbc0c74a877ee31d37a6ff5dd Mon Sep 17 00:00:00 2001 From: eliaporciani Date: Mon, 22 Jul 2019 16:19:57 +0200 Subject: [PATCH 1/9] [SEARCH-1641] break after element is found. --- .../test/search/functional/AbstractE2EFunctionalTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/AbstractE2EFunctionalTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/AbstractE2EFunctionalTest.java index fbae986f8..60a241846 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/AbstractE2EFunctionalTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/AbstractE2EFunctionalTest.java @@ -276,10 +276,10 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont } else { - for (SearchNodeModel entry : entries) - { - found = (contentName.equalsIgnoreCase(entry.getModel().getName())); - } + found = entries.stream() + .map(entry -> entry.getModel().getName()) + .filter(name -> name.equalsIgnoreCase(contentName)) + .count() > 0; } } else From afc84f4fd7b99bf6372fca6bfd95842d5ab7b3c5 Mon Sep 17 00:00:00 2001 From: eliaporciani Date: Mon, 22 Jul 2019 16:20:24 +0200 Subject: [PATCH 2/9] [SEARCH-1641] Use PATH instead of NPATH Added test for test cascading with sharding and explicit-routing --- .../CascadingTrackerIntegrationTest.java | 112 ++++++++++++++++-- 1 file changed, 104 insertions(+), 8 deletions(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java index b6f546016..c9ea8127b 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java @@ -6,7 +6,9 @@ */ package org.alfresco.test.search.functional.searchServices.search.tracker; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.alfresco.test.search.functional.AbstractE2EFunctionalTest; @@ -50,7 +52,8 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest .createFile(childFile, properties, VersioningState.MAJOR).assertThat().existsInRepo(); // Query to find nodes where Path with original folder name matches - String parentQuery = "NPATH:\"4/Company Home/Sites/" + testSite.getTitle() + "/documentLibrary/" + parentFolder.getName() + "\""; + String parentQuery = "PATH:\"/app:company_home/st:sites/cm:" + testSite.getTitle() + + "/cm:documentLibrary/cm:" + parentFolder.getName() + "/*\""; // Rename parent folder String parentNewName = "parentRenamed"; @@ -62,12 +65,13 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest waitForMetadataIndexing(parentNewName, true); // Find nodes where Path with new folder name matches - String parentQueryAfterRename = "NPATH:\"4/Company Home/Sites/" + testSite.getTitle() + "/documentLibrary/" + parentNewName + "\""; + String parentQueryAfterRename = "PATH:\"/app:company_home/st:sites/cm:" + testSite.getTitle() + + "/cm:documentLibrary/cm:" + parentNewName + "/*\""; boolean indexingInProgress = !isContentInSearchResults(parentQueryAfterRename, childFile.getName(), true); // Query using new parent name: Expect parent folder and child file int descendantCountOfNewName = query(parentQueryAfterRename).getPagination().getCount(); - Assert.assertEquals(descendantCountOfNewName, 2, String.format("Indexing in progress: %s New renamed path has not the same descendants as before renaming: %s", indexingInProgress, parentQueryAfterRename)); + Assert.assertEquals(descendantCountOfNewName, 1, String.format("Indexing in progress: %s New renamed path has not the same descendants as before renaming: %s", indexingInProgress, parentQueryAfterRename)); // Query using old parent name: Expect no descendant after rename int descendantCountOfOriginalName = query(parentQuery).getPagination().getCount(); @@ -96,7 +100,10 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest waitForMetadataIndexing(grandChildFile.getName(), true); // Query to find nodes where Path with original folder name matches - String parentQuery = "NPATH:\"4/Company Home/Sites/" + testSite.getTitle() + "/documentLibrary/" + grandParentFolder.getName() + "\""; + + String parentQuery = "PATH:\"/app:company_home/st:sites/cm:" + testSite.getTitle() + + "/cm:documentLibrary/cm:" + grandParentFolder.getName() + "/*\""; + // Rename grand parent folder String grandParentNewName = "grandParentRenamed"; @@ -106,12 +113,101 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest dataContent.usingUser(testUser).usingResource(grandParentFolder).renameContent(grandParentFolderRenamed); // Find nodes where Path with new folder name matches - String parentQueryAfterRename = "NPATH:\"4/Company Home/Sites/" + testSite.getTitle() + "/documentLibrary/" + grandParentNewName + "\""; - boolean indexingInProgress = !isContentInSearchResults(parentQueryAfterRename, grandChildFile.getName(), true); + String childrenQueryAfterRename = "PATH:\"/app:company_home/st:sites/cm:" + testSite.getTitle() + + "/cm:documentLibrary/cm:" + grandParentNewName + "/*\""; - // Query using new parent name: Expect grand parent, child folder, grand child file + String grandChildrenQueryAfterRename = "PATH:\"app:company_home/st:sites/cm:" + testSite.getTitle() + + "/cm:documentLibrary/cm:" + grandParentNewName + "/cm:" + childFolder.getName() + "/*\""; + + boolean indexingInProgress = !isContentInSearchResults(grandChildrenQueryAfterRename, grandChildFile.getName(), true); + + // Query using new parent name: Expect grandchild file + int grandChildrenCountOfNewName = query(grandChildrenQueryAfterRename).getPagination().getCount(); + Assert.assertEquals(grandChildrenCountOfNewName, 1, + String.format("Indexing in progress: %s New renamed path has not the same descendants as before renaming: %s", + indexingInProgress, + grandChildrenQueryAfterRename)); + + // Query using new parent name: Expect child folder + int childrenCountOfNewName = query(childrenQueryAfterRename).getPagination().getCount(); + Assert.assertEquals(childrenCountOfNewName, 1, + String.format("Indexing in progress: %s New renamed path has not the same descendants as before renaming: %s", + indexingInProgress, + childrenQueryAfterRename)); + + // Query using old parent name: Expect no descendant after rename + int descendantCountOfOriginalName = query(parentQuery).getPagination().getCount(); + Assert.assertEquals(descendantCountOfOriginalName, 0, "Old path still has descendants: " + parentQuery); + } + + /** + * Index three nodes (parent folder and two files) in two different shards. + * Check that, after parent renaming, both the children are searchable in the new path + * (computed accordingly with the new parent folder name) + */ + @Test(priority = 1, groups = { TestGroup.ASS_13 }) + public void testChildrenPathOnParentRenamedWithChildrenInDifferentShards() throws Exception{ + + + // Create Parent folder. It will be indexed in shard 0 + FolderModel parentFolder = FolderModel.getRandomFolderModel(); + Map parentProperties = new HashMap<>(); + List secondaryTypes = new ArrayList(); + secondaryTypes.add("P:shard:sharding"); + secondaryTypes.add("P:cm:titled"); + parentProperties.put(PropertyIds.NAME, parentFolder.getName()); + parentProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); + parentProperties.put("cmis:secondaryObjectTypeIds", secondaryTypes); + parentProperties.put("shard:shardId", "0"); + + // Create a first child in parent folder. It will be indexed in the parent shard (shard 0) + FileModel firstChildFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); + + Map propertiesFirstChild = new HashMap<>(); + propertiesFirstChild.put(PropertyIds.NAME, firstChildFile.getName()); + propertiesFirstChild.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); + propertiesFirstChild.put("cmis:secondaryObjectTypeIds", secondaryTypes); + propertiesFirstChild.put("shard:shardId", "0"); + + // Create a second child in parent folder. It will be indexed in shard 1. + FileModel secondChildFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); + + Map propertiesSecondChild = new HashMap<>(); + propertiesSecondChild.put(PropertyIds.NAME, secondChildFile.getName()); + propertiesSecondChild.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); + propertiesSecondChild.put("cmis:secondaryObjectTypeIds", secondaryTypes); + propertiesSecondChild.put("shard:shardId", "1"); + + cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(parentFolder, parentProperties).then() + .usingResource(parentFolder) + .createFile(firstChildFile, propertiesFirstChild, VersioningState.MAJOR) + .createFile(secondChildFile, propertiesSecondChild, VersioningState.MAJOR); + + // Check everything is indexed + Assert.assertTrue(waitForIndexing(firstChildFile.getName(), true), "file: " + firstChildFile.getName() + " has not been indexed."); + Assert.assertTrue(waitForIndexing(secondChildFile.getName(), true), "file: " + secondChildFile.getName() + " has not been indexed."); + Assert.assertTrue(waitForIndexing(parentFolder.getName(), true), "file: " + parentFolder.getName() + " has not been indexed."); + + // Query to find nodes where Path with original folder name matches + String parentQuery = "PATH:\"/app:company_home/st:sites/cm:" + testSite.getTitle() + + "/cm:documentLibrary/cm:" + parentFolder.getName() + "/*\""; + + // Rename parent folder + String parentNewName = "parentRenamedSharding"; + parentFolder.setName(parentNewName); + ContentModel parentNewNameModel = new ContentModel(parentNewName); + dataContent.usingUser(testUser).usingResource(parentFolder).renameContent(parentNewNameModel); + + String parentQueryAfterRename = "PATH:\"/app:company_home/st:sites/cm:" + testSite.getTitle() + + "/cm:documentLibrary/cm:" + parentNewName + "/*\""; + + Assert.assertTrue(waitForMetadataIndexing(parentNewName, true), "failing while renaming " + parentFolder.getName() + " to " + parentNewName); + + boolean indexingInProgress = !isContentInSearchResults(parentQueryAfterRename, firstChildFile.getName(), true); + + // Query using new parent name: Expect parent folder and child file int descendantCountOfNewName = query(parentQueryAfterRename).getPagination().getCount(); - Assert.assertEquals(descendantCountOfNewName, 3, String.format("Indexing in progress: %s New renamed path has not the same descendants as before renaming: %s", indexingInProgress, parentQueryAfterRename)); + Assert.assertEquals(descendantCountOfNewName, 2, String.format("Indexing in progress: %s New renamed path has not the same descendants as before renaming: %s", indexingInProgress, parentQuery)); // Query using old parent name: Expect no descendant after rename int descendantCountOfOriginalName = query(parentQuery).getPagination().getCount(); From 26b3362d16354dc4becbe56a05338632274c3e02 Mon Sep 17 00:00:00 2001 From: eliaporciani Date: Mon, 22 Jul 2019 17:57:16 +0200 Subject: [PATCH 3/9] [SEARCH-1641] removed test group --- .../search/tracker/CascadingTrackerIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java index c9ea8127b..89cf0d24a 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java @@ -145,7 +145,7 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest * Check that, after parent renaming, both the children are searchable in the new path * (computed accordingly with the new parent folder name) */ - @Test(priority = 1, groups = { TestGroup.ASS_13 }) + @Test(priority = 1) public void testChildrenPathOnParentRenamedWithChildrenInDifferentShards() throws Exception{ From 3f15a017346db585eec12883fdec59dc520b1a52 Mon Sep 17 00:00:00 2001 From: eliaporciani Date: Wed, 24 Jul 2019 11:37:03 +0200 Subject: [PATCH 4/9] [SEARCH-1641] Added test groups - EXPLICIT_SHARDING - NOT_BAMBOO for saying that a test should not be run on bamboo --- .../java/org/alfresco/search/TestGroup.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/e2e-test/src/main/java/org/alfresco/search/TestGroup.java b/e2e-test/src/main/java/org/alfresco/search/TestGroup.java index 60a026e14..5b3cc475e 100644 --- a/e2e-test/src/main/java/org/alfresco/search/TestGroup.java +++ b/e2e-test/src/main/java/org/alfresco/search/TestGroup.java @@ -10,20 +10,24 @@ import java.lang.annotation.Target; public @interface TestGroup { // Used for TestRail test annotation - public static final String SEARCH = "search"; - public static final String REST_API = "rest-api"; + String SEARCH = "search"; + String REST_API = "rest-api"; - public static final String PREUPGRADE = "pre-upgrade"; - public static final String POSTUPGRADE = "post-upgrade"; + String PREUPGRADE = "pre-upgrade"; + String POSTUPGRADE = "post-upgrade"; - public static final String ASS_MASTER_SLAVE = "ASS_Master_Slave"; // Alfresco Search Services using master slave configurations - public static final String ASS_MASTER ="ASS_Master"; // Alfresco search services using master/stand alone mode + String ASS_MASTER_SLAVE = "ASS_Master_Slave"; // Alfresco Search Services using master slave configurations + String ASS_MASTER ="ASS_Master"; // Alfresco search services using master/stand alone mode + String EXPLICIT_SHARDING ="Explicit_Sharding"; // Alfresco search services using sharded environment and explicit routing + + String NOT_INSIGHT_ENGINE = "Not_InsightEngine"; // When Alfresco Insight Engine 1.0 isn't running - public static final String NOT_INSIGHT_ENGINE = "Not_InsightEngine"; // When Alfresco Insight Engine 1.0 isn't running - - public static final String ACS_52n = "ACS_52n"; // Alfresco Content Services 5.2.n - public static final String ACS_60n = "ACS_60n"; // Alfresco Content Services 6.0 or above - public static final String ACS_61n = "ACS_61n"; // Alfresco Content Services 6.1 or above - public static final String ACS_611n = "ACS_611n"; // Alfresco Content Services 6.1.1 or above - public static final String ACS_62n = "ACS_62n"; // Alfresco Content Services 6.2 or above + String ACS_52n = "ACS_52n"; // Alfresco Content Services 5.2.n + String ACS_60n = "ACS_60n"; // Alfresco Content Services 6.0 or above + String ACS_61n = "ACS_61n"; // Alfresco Content Services 6.1 or above + String ACS_611n = "ACS_611n"; // Alfresco Content Services 6.1.1 or above + String ACS_62n = "ACS_62n"; // Alfresco Content Services 6.2 or above + + String NOT_BAMBOO = "Not_Bamboo"; // The does not run on bamboo + } From ae8b6ff0cbe240f765a1400a2afee611b6830ca3 Mon Sep 17 00:00:00 2001 From: eliaporciani Date: Wed, 24 Jul 2019 11:38:52 +0200 Subject: [PATCH 5/9] [SEARCH-1641] Added right groups to testChildrenPathOnParentRenamedWithChildrenInDifferentShards test --- .../search/tracker/CascadingTrackerIntegrationTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java index 89cf0d24a..14647e65c 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java @@ -18,6 +18,7 @@ import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; import org.alfresco.utility.model.FolderModel; import org.alfresco.search.TestGroup; +import org.alfresco.utility.testrail.annotation.TestRail; import org.apache.chemistry.opencmis.commons.PropertyIds; import org.apache.chemistry.opencmis.commons.enums.VersioningState; import org.springframework.beans.factory.annotation.Autowired; @@ -145,7 +146,7 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest * Check that, after parent renaming, both the children are searchable in the new path * (computed accordingly with the new parent folder name) */ - @Test(priority = 1) + @Test(priority = 1, groups = {TestGroup.NOT_BAMBOO, TestGroup.EXPLICIT_SHARDING }) public void testChildrenPathOnParentRenamedWithChildrenInDifferentShards() throws Exception{ From c2f26e79cf8229ecdef74d17919dd124ec02febf Mon Sep 17 00:00:00 2001 From: eliaporciani Date: Wed, 24 Jul 2019 15:10:19 +0200 Subject: [PATCH 6/9] [SEARCH-1641] fix comments --- .../search/tracker/CascadingTrackerIntegrationTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java index 14647e65c..d708c0ff7 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java @@ -70,7 +70,7 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest "/cm:documentLibrary/cm:" + parentNewName + "/*\""; boolean indexingInProgress = !isContentInSearchResults(parentQueryAfterRename, childFile.getName(), true); - // Query using new parent name: Expect parent folder and child file + // Query using new parent name: Expect child file int descendantCountOfNewName = query(parentQueryAfterRename).getPagination().getCount(); Assert.assertEquals(descendantCountOfNewName, 1, String.format("Indexing in progress: %s New renamed path has not the same descendants as before renaming: %s", indexingInProgress, parentQueryAfterRename)); @@ -206,7 +206,7 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest boolean indexingInProgress = !isContentInSearchResults(parentQueryAfterRename, firstChildFile.getName(), true); - // Query using new parent name: Expect parent folder and child file + // Query using new parent name: Expect the two children int descendantCountOfNewName = query(parentQueryAfterRename).getPagination().getCount(); Assert.assertEquals(descendantCountOfNewName, 2, String.format("Indexing in progress: %s New renamed path has not the same descendants as before renaming: %s", indexingInProgress, parentQuery)); From 4474008bbbc6c390d7d609e79c0979641d5cc280 Mon Sep 17 00:00:00 2001 From: eliaporciani Date: Wed, 24 Jul 2019 15:12:29 +0200 Subject: [PATCH 7/9] [SEARCH-1641] formatting --- .../search/tracker/CascadingTrackerIntegrationTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java index d708c0ff7..855af8aa6 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java @@ -147,8 +147,8 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest * (computed accordingly with the new parent folder name) */ @Test(priority = 1, groups = {TestGroup.NOT_BAMBOO, TestGroup.EXPLICIT_SHARDING }) - public void testChildrenPathOnParentRenamedWithChildrenInDifferentShards() throws Exception{ - + public void testChildrenPathOnParentRenamedWithChildrenInDifferentShards() throws Exception + { // Create Parent folder. It will be indexed in shard 0 FolderModel parentFolder = FolderModel.getRandomFolderModel(); From 61c7c146be4c518ed9d7cde43e8104319b07dd32 Mon Sep 17 00:00:00 2001 From: eliaporciani Date: Thu, 25 Jul 2019 21:20:52 +0200 Subject: [PATCH 8/9] [SEARCH-1641] Refactoring --- .../functional/AbstractE2EFunctionalTest.java | 46 ++++++------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/AbstractE2EFunctionalTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/AbstractE2EFunctionalTest.java index 60a241846..d85398287 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/AbstractE2EFunctionalTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/AbstractE2EFunctionalTest.java @@ -13,7 +13,6 @@ import org.alfresco.rest.core.RestProperties; import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.search.RestRequestHighlightModel; import org.alfresco.rest.search.RestRequestQueryModel; -import org.alfresco.rest.search.SearchNodeModel; import org.alfresco.rest.search.SearchRequest; import org.alfresco.rest.search.SearchResponse; import org.alfresco.utility.LogFactory; @@ -42,14 +41,14 @@ import lombok.Getter; import static lombok.AccessLevel.PROTECTED; -import java.util.List; - /** * @author meenal bhave */ @ContextConfiguration("classpath:alfresco-search-e2e-context.xml") public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringContextTests { + public static final int SEARCH_MAX_ATTEMPS = 6; + private static Logger LOG = LogFactory.getLogger(); @Autowired @@ -249,49 +248,30 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont * @param contentToFind that's expected to be included / excluded from the results * @param expectedInResults * @return true if search returns expected results, i.e. is given content is found or excluded from the results - * @throws Exception */ - public boolean isContentInSearchResults(String userQuery, String contentToFind, boolean expectedInResults) - throws Exception - { - boolean resultAsExpected = false; - boolean found = !expectedInResults; + public boolean isContentInSearchResults(String userQuery, String contentToFind, boolean expectedInResults) { + String expectedStatusCode = HttpStatus.OK.toString(); String contentName = (contentToFind == null) ? "" : contentToFind; // Repeat search until the query results are as expected or Search Retry count is hit - for (int searchCount = 1; searchCount <= 6; searchCount++) + for (int searchCount = 0; searchCount < SEARCH_MAX_ATTEMPS; searchCount++) { SearchRequest searchRequest = createQuery(userQuery); SearchResponse response = query(searchRequest); if (restClient.getStatusCode().matches(expectedStatusCode)) { - List entries = response.getEntries(); - if (!entries.isEmpty()) - { - if (contentName.isEmpty()) - { - found = true; - } - else - { - found = entries.stream() - .map(entry -> entry.getModel().getName()) - .filter(name -> name.equalsIgnoreCase(contentName)) - .count() > 0; - } - } - else - { - found = false; - } + + boolean found = response.getEntries().stream() + .map(entry -> entry.getModel().getName()) + .filter(name -> name.equalsIgnoreCase(contentName) || contentName.isBlank()) + .count() > 0; // Loop again if result is not as expected: To cater for solr lag: eventual consistency - resultAsExpected = (expectedInResults == found); - if (resultAsExpected) + if (expectedInResults == found) { - break; + return true; } else { @@ -305,7 +285,7 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont } } - return resultAsExpected; + return false; } /** From fafcde5e770c4fae9ef75749ed425d054da092c8 Mon Sep 17 00:00:00 2001 From: eliaporciani Date: Thu, 25 Jul 2019 21:21:49 +0200 Subject: [PATCH 9/9] [SEARCH-1641] Refactoring. Removed unnecessary titled aspect. Add check before parent renaming --- .../CascadingTrackerIntegrationTest.java | 63 +++++++++---------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java index 855af8aa6..daf9e0ce0 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java @@ -6,19 +6,15 @@ */ package org.alfresco.test.search.functional.searchServices.search.tracker; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; - +import org.alfresco.search.TestGroup; import org.alfresco.test.search.functional.AbstractE2EFunctionalTest; import org.alfresco.utility.data.DataContent; import org.alfresco.utility.model.ContentModel; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; import org.alfresco.utility.model.FolderModel; -import org.alfresco.search.TestGroup; -import org.alfresco.utility.testrail.annotation.TestRail; import org.apache.chemistry.opencmis.commons.PropertyIds; import org.apache.chemistry.opencmis.commons.enums.VersioningState; import org.springframework.beans.factory.annotation.Autowired; @@ -45,12 +41,12 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest // Create a file in the parent folder FileModel childFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); - Map properties = new HashMap<>(); - properties.put(PropertyIds.NAME, childFile.getName()); - properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); - cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(parentFolder) - .createFile(childFile, properties, VersioningState.MAJOR).assertThat().existsInRepo(); + .createFile(childFile, + Map.of(PropertyIds.NAME, childFile.getName(), + PropertyIds.OBJECT_TYPE_ID, "cmis:document"), + VersioningState.MAJOR) + .assertThat().existsInRepo(); // Query to find nodes where Path with original folder name matches String parentQuery = "PATH:\"/app:company_home/st:sites/cm:" + testSite.getTitle() + @@ -90,12 +86,13 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest // Create grand child file FileModel grandChildFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); - Map properties = new HashMap<>(); - properties.put(PropertyIds.NAME, grandChildFile.getName()); - properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(childFolder) - .createFile(grandChildFile, properties, VersioningState.MAJOR).assertThat().existsInRepo(); + .createFile(grandChildFile, + Map.of(PropertyIds.NAME, grandChildFile.getName(), + PropertyIds.OBJECT_TYPE_ID, "cmis:document"), + VersioningState.MAJOR) + .assertThat().existsInRepo(); // Wait for file to be indexed waitForMetadataIndexing(grandChildFile.getName(), true); @@ -152,32 +149,27 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest // Create Parent folder. It will be indexed in shard 0 FolderModel parentFolder = FolderModel.getRandomFolderModel(); - Map parentProperties = new HashMap<>(); - List secondaryTypes = new ArrayList(); - secondaryTypes.add("P:shard:sharding"); - secondaryTypes.add("P:cm:titled"); - parentProperties.put(PropertyIds.NAME, parentFolder.getName()); - parentProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); - parentProperties.put("cmis:secondaryObjectTypeIds", secondaryTypes); - parentProperties.put("shard:shardId", "0"); + + List secondaryTypes = List.of("P:shard:sharding"); + Map parentProperties = Map.of(PropertyIds.NAME, parentFolder.getName(), + PropertyIds.OBJECT_TYPE_ID, "cmis:folder", + "cmis:secondaryObjectTypeIds", secondaryTypes, + "shard:shardId", "0"); // Create a first child in parent folder. It will be indexed in the parent shard (shard 0) FileModel firstChildFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); - - Map propertiesFirstChild = new HashMap<>(); - propertiesFirstChild.put(PropertyIds.NAME, firstChildFile.getName()); - propertiesFirstChild.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); - propertiesFirstChild.put("cmis:secondaryObjectTypeIds", secondaryTypes); - propertiesFirstChild.put("shard:shardId", "0"); + Map propertiesFirstChild = Map.of(PropertyIds.NAME, firstChildFile.getName(), + PropertyIds.OBJECT_TYPE_ID, "cmis:document", + "cmis:secondaryObjectTypeIds", secondaryTypes, + "shard:shardId", "0"); // Create a second child in parent folder. It will be indexed in shard 1. FileModel secondChildFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); + Map propertiesSecondChild = Map.of(PropertyIds.NAME, secondChildFile.getName(), + PropertyIds.OBJECT_TYPE_ID, "cmis:document", + "cmis:secondaryObjectTypeIds", secondaryTypes, + "shard:shardId", "1"); - Map propertiesSecondChild = new HashMap<>(); - propertiesSecondChild.put(PropertyIds.NAME, secondChildFile.getName()); - propertiesSecondChild.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); - propertiesSecondChild.put("cmis:secondaryObjectTypeIds", secondaryTypes); - propertiesSecondChild.put("shard:shardId", "1"); cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(parentFolder, parentProperties).then() .usingResource(parentFolder) @@ -202,6 +194,11 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest String parentQueryAfterRename = "PATH:\"/app:company_home/st:sites/cm:" + testSite.getTitle() + "/cm:documentLibrary/cm:" + parentNewName + "/*\""; + // Query using new parent name: Expect the two children + int descendantCountOfNewNameBeforeUpdate = query(parentQueryAfterRename).getPagination().getCount(); + Assert.assertEquals(descendantCountOfNewNameBeforeUpdate, 0, "There should be 0 results performing the new query before updating parent name"); + + Assert.assertTrue(waitForMetadataIndexing(parentNewName, true), "failing while renaming " + parentFolder.getName() + " to " + parentNewName); boolean indexingInProgress = !isContentInSearchResults(parentQueryAfterRename, firstChildFile.getName(), true);