diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java index 6bfadb8738..ce4e9f0e89 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java @@ -140,6 +140,24 @@ public class SearchAPI extends BaseAPI return getItemNames(rmSearch(username, password, "rm", query, searchFilterParamaters, sortby)); } + public List searchForNodeNamesAsUserWithWait(String username, String password, String query, String sortby, + boolean includeCategories, boolean includeFolders ) throws InterruptedException + { + String searchFilterParameters = MessageFormat.format(RM_DEFAULT_NODES_FILTERS, Boolean.toString(includeFolders), + Boolean.toString(includeCategories)); + JSONObject jsonResults = rmSearch(username, password, "rm", query, searchFilterParameters, sortby); + // Delay because JSON parsing not always completed yet + for (int i = 0 ; i < 20; i++) + { + if (jsonResults.has("items")) + { + break; + } + Thread.sleep(1000); + } + return getItemNames(jsonResults); + } + /** * Search as a user for nodes on site "rm" matching query, using SearchAPI.RM_DEFAULT_RECORD_FILTERS and sorted * by sortby and returns the property value for the given nodeRef and property name diff --git a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java index 68d3a21dcc..20ed2dc5ae 100644 --- a/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java +++ b/amps/ags/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java @@ -710,15 +710,47 @@ public class BaseRMRestTest extends RestTest } } - String searchFilterParameters = MessageFormat.format(RM_DEFAULT_NODES_FILTERS, Boolean.toString(includeFolders), - Boolean.toString(includeCategories)); - JSONObject jsonResults = rmSearch(user.getUsername(), user.getPassword(), "rm", term, searchFilterParameters, sortby); - if (expectedResults != null && !expectedResults.isEmpty()) + results = searchApi.searchForNodeNamesAsUser(user.getUsername(), user.getPassword(), term, sortby, + includeFolders, includeCategories); + if (!results.isEmpty() && results.containsAll(expectedResults)) { - // Delay because JSON parsing not always completed yet - Utility.sleep(1000, 20000, () -> assertTrue(searchResult.has("items"))); + break; } - results = getItemNames(jsonResults); + else + { + counter++; + } + // double wait time to not overdo solr search + waitInMilliSeconds = waitInMilliSeconds * 2; + } + return results; + } + + // Poc code to see if waiting for JSON parsing to complete has any effect on intermittent error + public List searchForRMContentAsUserWithWait(UserModel user, String term, String sortby, boolean includeFolders, + boolean includeCategories, List expectedResults) + { + List results = new ArrayList<>(); + // wait for solr indexing + int counter = 0; + int waitInMilliSeconds = 7000; + while (counter < 4) + { + synchronized (this) + { + try + { + this.wait(waitInMilliSeconds); + } + catch (InterruptedException e) + { + // Restore interrupted state... + Thread.currentThread().interrupt(); + } + } + + results = searchApi.searchForNodeNamesAsUserWithWait(user.getUsername(), user.getPassword(), term, sortby, + includeFolders, includeCategories); if (!results.isEmpty() && results.containsAll(expectedResults)) { break;