Skip to content

Commit

Permalink
Merge pull request #1639 from Alfresco/fix/ACS-4463_FixPipelineInterm…
Browse files Browse the repository at this point in the history
…ittentFailures

Check for non-empty results and move some tests out of pipeline suite
  • Loading branch information
SaraAspery authored Feb 3, 2023
2 parents e9de99d + 8aae077 commit fe64043
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Alfresco Search Services E2E Test
* %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
Expand All @@ -26,10 +26,15 @@

package org.alfresco.test.search.functional.searchServices.search;

import org.alfresco.rest.exception.EmptyJsonResponseException;
import org.alfresco.rest.search.SearchResponse;
import org.alfresco.test.search.functional.AbstractE2EFunctionalTest;
import org.alfresco.utility.Utility;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FileType;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.UserModel;
import org.springframework.http.HttpStatus;
import org.testng.Assert;

import static java.util.List.of;
Expand All @@ -47,6 +52,10 @@
public abstract class AbstractSearchServicesE2ETest extends AbstractE2EFunctionalTest
{
private static final String SEARCH_DATA_SAMPLE_FOLDER = "FolderSearch";
private static final int MAX_ATTEMPTS_TO_RETRY_QUERY = 10;
private static final int MAX_WAIT_IN_SECONDS_BEFORE_RETRY_QUERY = 5;
private static final int MAX_ATTEMPTS_TO_READ_RESPONSE = 10;
private static final int MAX_WAIT_IN_SECONDS_BEFORE_REREAD_RESPONSE = 2;

/** The maximum time to wait for content indexing to complete (in ms). */
private static final int MAX_TIME = 120 * 1000;
Expand Down Expand Up @@ -104,4 +113,46 @@ protected FileModel createFileWithProvidedText(String filename, String providedT

return uniqueFile;
}

protected SearchResponse queryUntilResponseEntriesListNotEmpty(UserModel user, String queryString)
{
SearchResponse response = queryUntilStatusIsOk(user, queryString);
if (restClient.getStatusCode().matches(HttpStatus.OK.toString()))
{
for (int readAttempts = 0; readAttempts < MAX_ATTEMPTS_TO_READ_RESPONSE; readAttempts++)
{
if (!response.isEmpty())
{
return response;
}
Utility.waitToLoopTime(MAX_WAIT_IN_SECONDS_BEFORE_REREAD_RESPONSE, "Re-reading empty response. Retry Attempt: " + (readAttempts + 1));
}
}

return response;
}

private SearchResponse queryUntilStatusIsOk(UserModel user, String queryString)
{
// Repeat query until status is OK or Query Retry limit is hit
for (int queryAttempts = 0; queryAttempts < MAX_ATTEMPTS_TO_RETRY_QUERY - 1; queryAttempts++)
{
try
{
SearchResponse response = queryAsUser(user, queryString);
if (restClient.getStatusCode().matches(HttpStatus.OK.toString()))
{
return response;
}

// Wait for pipeline to calm down
Utility.waitToLoopTime(MAX_WAIT_IN_SECONDS_BEFORE_RETRY_QUERY, "Re-trying query for valid status code. Retry Attempt: " + (queryAttempts + 1));
}
catch (EmptyJsonResponseException ignore)
{
}
}
// Final attempt
return queryAsUser(user, queryString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Alfresco Search Services E2E Test
* %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
Expand Down Expand Up @@ -51,6 +51,162 @@ public void dataPreparation() throws Exception
}

@Test(priority=1)
public void testSearchNameField()
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:name:pangram");
queryReq.setUserQuery("pangram");
searchReq.setQuery(queryReq);
SearchResponse response = queryAsUser(testUser, "cm:name:pangram");
restClient.assertStatusCodeIs(HttpStatus.OK);
response.assertThat().entriesListIsNotEmpty();
}

@Test(priority=2)
public void testSearchTitleField()
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:title:cars");
queryReq.setUserQuery("cars");
searchReq.setQuery(queryReq);
SearchResponse response2 = queryAsUser(testUser, "cm:title:cars");
restClient.assertStatusCodeIs(HttpStatus.OK);
response2.assertThat().entriesListIsNotEmpty();
}

@Test(priority=3)
public void testSearchDescriptionField()
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:description:alfresco");
queryReq.setUserQuery("alfresco");
searchReq.setQuery(queryReq);
SearchResponse response3 = queryAsUser(testUser, "cm:description:alfresco");
restClient.assertStatusCodeIs(HttpStatus.OK);
response3.assertThat().entriesListIsNotEmpty();
}

@Test(priority=4)
public void testSearchTextFile()
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:name:pangram.txt");
queryReq.setUserQuery("pangram.txt");
searchReq.setQuery(queryReq);
SearchResponse response6 = queryAsUser(testUser, "cm:name:pangram.txt");
restClient.assertStatusCodeIs(HttpStatus.OK);
response6.assertThat().entriesListIsNotEmpty();
}

@Test(priority=5)
public void testSearchPDFFile()
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:name:cars.PDF");
queryReq.setUserQuery("cars.PDF");
searchReq.setQuery(queryReq);
SearchResponse response6 = queryAsUser(testUser, "cm:name:cars.PDF");
restClient.assertStatusCodeIs(HttpStatus.OK);
response6.assertThat().entriesListIsNotEmpty();
}

@Test(priority=6)
public void testSearchDocxFile()
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:name:alfresco.docx");
queryReq.setUserQuery("alfresco.docx");
searchReq.setQuery(queryReq);
SearchResponse response6 = queryAsUser(testUser, "cm:name:alfresco.docx");
restClient.assertStatusCodeIs(HttpStatus.OK);
response6.assertThat().entriesListIsNotEmpty();
}

@Test(priority=7)
public void testSearchPhraseQueries()
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:name:alfresco");
queryReq.setUserQuery("alfresco");
searchReq.setQuery(queryReq);
SearchResponse response6 = queryAsUser(testUser, "The quick brown fox jumps over the lazy dog");
restClient.assertStatusCodeIs(HttpStatus.OK);
response6.assertThat().entriesListIsNotEmpty();
}

@Test(priority=8)
public void testSearchExactTermQueries()
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:name:alfresco");
queryReq.setUserQuery("alfresco");
searchReq.setQuery(queryReq);
SearchResponse response6 = queryAsUser(testUser, "=alfresco");
restClient.assertStatusCodeIs(HttpStatus.OK);
response6.assertThat().entriesListIsNotEmpty();
}

@Test(priority=9)
public void testSearchConjunctionQueries()
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:name:unique");
queryReq.setUserQuery("unique");
searchReq.setQuery(queryReq);
SearchResponse response6 = queryAsUser(testUser, "unique AND search");
restClient.assertStatusCodeIs(HttpStatus.OK);
response6.assertThat().entriesListIsNotEmpty();
}

@Test(priority=10)
public void testSearchDisjunctionQueries()
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:name:cars");
queryReq.setUserQuery("cars");
searchReq.setQuery(queryReq);
SearchResponse response6 = queryAsUser(testUser, "file OR discovery");
restClient.assertStatusCodeIs(HttpStatus.OK);
response6.assertThat().entriesListIsNotEmpty();
}

@Test(priority=11)
public void testSearchNegationQueries()
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:name:pangram");
queryReq.setUserQuery("pangram");
searchReq.setQuery(queryReq);
SearchResponse response6 = queryAsUser(testUser, "pangram NOT pan");
restClient.assertStatusCodeIs(HttpStatus.OK);
response6.assertThat().entriesListIsNotEmpty();
}

@Test(priority=12)
public void testSearchWildcardQueries()
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:name:alfresco");
queryReq.setUserQuery("alfresco");
searchReq.setQuery(queryReq);
SearchResponse response6 = queryAsUser(testUser, "al?res*");
restClient.assertStatusCodeIs(HttpStatus.OK);
response6.assertThat().entriesListIsNotEmpty();
}

@Test(priority=13)
public void testSearchUpdateContent() throws InterruptedException
{
String originalText = String.valueOf(System.currentTimeMillis());
Expand Down Expand Up @@ -96,7 +252,7 @@ public void testSearchUpdateContent() throws InterruptedException
* }
* }
*/
@Test(priority=2)
@Test(priority=14)
public void searchWithFacedFields() throws InterruptedException
{
String uniqueText = String.valueOf(System.currentTimeMillis());
Expand Down Expand Up @@ -134,7 +290,7 @@ public void searchWithFacedFields() throws InterruptedException
bucket1.assertThat().field("count").is(1);
}

@Test(priority=3)
@Test(priority=15)
public void searchSpecialCharacters()
{
String specialCharfileName = "è¥äæ§ç§-åæ.pdf";
Expand Down
Loading

0 comments on commit fe64043

Please sign in to comment.