From 83d84135aa25e25e7cab66457be6db1f883fa036 Mon Sep 17 00:00:00 2001 From: cezary-witkowski Date: Wed, 11 Dec 2024 10:49:59 +0100 Subject: [PATCH 1/5] [ACS-9069] Fix failing tests after configuration change in lifeIndexer that makes subscription durable by default --- .../reindexing/ElasticsearchReindexingTests.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java index 75017d3984..bcabed65c3 100644 --- a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java +++ b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java @@ -184,7 +184,11 @@ private void internalTestEnabledFeatures( // Delete index documents cleanUpIndex(); // Restart ElasticsearchConnector to Index Content - AlfrescoStackInitializer.liveIndexer.start(); + if (contentIndexingEnabled) + { + // Reindexer requires lifeIndexer to index content. + AlfrescoStackInitializer.liveIndexer.start(); + } // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default From 3eb886b859bb377caa453f26d19b69631f13eadf Mon Sep 17 00:00:00 2001 From: cezary-witkowski Date: Thu, 12 Dec 2024 09:17:30 +0100 Subject: [PATCH 2/5] [ACS-9069] Refactoring reindex tests --- .../ElasticsearchInitialReindexingTests.java | 60 +-- .../parallel/PathUpdateTests.java | 5 +- .../ElasticsearchReindexingTests.java | 361 ++++++++---------- .../tas/AlfrescoStackInitializer.java | 10 +- 4 files changed, 184 insertions(+), 252 deletions(-) diff --git a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/initialReindex/ElasticsearchInitialReindexingTests.java b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/initialReindex/ElasticsearchInitialReindexingTests.java index a94760d7f5..435ad8a50c 100644 --- a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/initialReindex/ElasticsearchInitialReindexingTests.java +++ b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/initialReindex/ElasticsearchInitialReindexingTests.java @@ -1,9 +1,9 @@ package org.alfresco.elasticsearch.initialReindex; import static org.alfresco.elasticsearch.SearchQueryService.req; -import static org.alfresco.tas.AlfrescoStackInitializer.getImagesConfig; +import static org.alfresco.tas.AlfrescoStackInitializer.*; +import static org.alfresco.utility.model.FileType.TEXT_PLAIN; -import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -13,19 +13,15 @@ import org.alfresco.utility.data.DataContent; import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; import org.alfresco.utility.network.ServerHealth; import org.alfresco.utility.report.log.Step; -import org.apache.http.HttpHost; -import org.opensearch.client.RestClient; -import org.opensearch.client.RestHighLevelClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.startupcheck.IndefiniteWaitOneShotStartupCheckStrategy; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -37,10 +33,6 @@ public class ElasticsearchInitialReindexingTests extends AbstractTestNGSpringContextTests { - private static final Logger LOGGER = LoggerFactory.getLogger(ElasticsearchInitialReindexingTests.class); - - public static final String CUSTOM_ALFRESCO_INDEX = "custom-alfresco-index"; - @Autowired private ServerHealth serverHealth; @Autowired @@ -52,11 +44,8 @@ public class ElasticsearchInitialReindexingTests extends AbstractTestNGSpringCon @Autowired protected SearchQueryService searchQueryService; - private org.alfresco.utility.model.UserModel testUser; - - private org.alfresco.utility.model.SiteModel testSite; - - private RestHighLevelClient elasticClient; + private UserModel testUser; + private SiteModel testSite; /** * Create a user and a private site and wait for these to be indexed. @@ -72,13 +61,6 @@ public void dataPreparation() testUser = dataUser.createRandomTestUser(); testSite = dataSite.usingUser(testUser).createPrivateRandomSite(); createDocument(); - - Step.STEP("create ES client"); - elasticClient = new RestHighLevelClient( - RestClient.builder(new HttpHost(AlfrescoStackInitializer.searchEngineContainer.getContainerIpAddress(), - AlfrescoStackInitializer.searchEngineContainer.getFirstMappedPort(), - "http"))); - } /** @@ -96,36 +78,14 @@ public void testReindexerIndexesSystemDocuments() // WHEN // Run reindexer against the initial documents. reindex(Map.of("ALFRESCO_REINDEX_JOB_NAME", "reindexByIds", - "ELASTICSEARCH_INDEX_NAME", CUSTOM_ALFRESCO_INDEX, - "ALFRESCO_REINDEX_FROM_ID", "0", - "ALFRESCO_REINDEX_TO_ID", "1000")); + "ALFRESCO_REINDEX_FROM_ID", "0", + "ALFRESCO_REINDEX_TO_ID", "1000")); // THEN // Check system document is indexed. searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), "budget.xls"); } - /** - * Run the alfresco-elasticsearch-reindexing container. - * - * @param envParam Any environment variables to override from the defaults. - */ - private void reindex(Map envParam) - { - // Run the reindexing container. - Map env = AlfrescoStackInitializer.getReindexEnvBasic(); - env.putAll(envParam); - - try (GenericContainer reindexingComponent = new GenericContainer(getImagesConfig().getReIndexingImage()) - .withEnv(env) - .withNetwork(AlfrescoStackInitializer.network) - .withStartupCheckStrategy( - new IndefiniteWaitOneShotStartupCheckStrategy())) - { - reindexingComponent.start(); - } - } - /** * Create a document using in the test site using the test user. * @@ -136,7 +96,7 @@ private String createDocument() String documentName = "TestFile" + UUID.randomUUID() + ".txt"; dataContent.usingUser(testUser) .usingSite(testSite) - .createContent(new org.alfresco.utility.model.FileModel(documentName, org.alfresco.utility.model.FileType.TEXT_PLAIN, "content")); + .createContent(new FileModel(documentName, TEXT_PLAIN, "content")); return documentName; } } diff --git a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/parallel/PathUpdateTests.java b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/parallel/PathUpdateTests.java index f7919d07c8..03ce2c6417 100644 --- a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/parallel/PathUpdateTests.java +++ b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/parallel/PathUpdateTests.java @@ -4,8 +4,11 @@ import static java.util.stream.Collectors.joining; import static org.alfresco.elasticsearch.SearchQueryService.req; +import static org.alfresco.tas.AlfrescoStackInitializer.reindex; import java.util.Arrays; +import java.util.Map; + import jakarta.json.Json; import jakarta.json.JsonObject; @@ -65,7 +68,7 @@ public void dataPreparation() // Before we start testing the live indexing we need to use the reindexing component to index the system nodes. Step.STEP("Index system nodes."); - AlfrescoStackInitializer.reindexEverything(); + reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); // Ensure path reindexing is enabled. Step.STEP("Create a test user and private site."); testUser = dataUser.createRandomTestUser(); diff --git a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java index bcabed65c3..6981c2f190 100644 --- a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java +++ b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java @@ -1,7 +1,11 @@ package org.alfresco.elasticsearch.reindexing; import static org.alfresco.elasticsearch.SearchQueryService.req; -import static org.alfresco.tas.AlfrescoStackInitializer.getImagesConfig; +import static org.alfresco.tas.AlfrescoStackInitializer.CUSTOM_ALFRESCO_INDEX; +import static org.alfresco.tas.AlfrescoStackInitializer.liveIndexer; +import static org.alfresco.tas.AlfrescoStackInitializer.reindex; +import static org.alfresco.tas.AlfrescoStackInitializer.searchEngineContainer; +import static org.alfresco.utility.model.FileType.TEXT_PLAIN; import static org.alfresco.utility.report.log.Step.STEP; import static org.junit.Assert.fail; @@ -18,7 +22,10 @@ import org.alfresco.utility.data.DataContent; import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; import org.alfresco.utility.network.ServerHealth; import org.apache.http.HttpHost; import org.opensearch.client.RequestOptions; @@ -30,8 +37,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.startupcheck.IndefiniteWaitOneShotStartupCheckStrategy; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -43,8 +48,6 @@ @SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation") // these are testng tests public class ElasticsearchReindexingTests extends AbstractTestNGSpringContextTests { - public static final String CUSTOM_ALFRESCO_INDEX = "custom-alfresco-index"; - @Autowired private ServerHealth serverHealth; @Autowired @@ -56,15 +59,10 @@ public class ElasticsearchReindexingTests extends AbstractTestNGSpringContextTes @Autowired protected SearchQueryService searchQueryService; - private org.alfresco.utility.model.UserModel testUser; - - private org.alfresco.utility.model.SiteModel testSite; - + private UserModel testUser; + private SiteModel testSite; private RestHighLevelClient elasticClient; - /** - * Create a user and a private site and wait for these to be indexed. - */ @BeforeClass(alwaysRun = true) public void dataPreparation() { @@ -75,288 +73,258 @@ public void dataPreparation() testUser = dataUser.createRandomTestUser(); testSite = dataSite.usingUser(testUser).createPrivateRandomSite(); - createDocument(); + createDocumentWithRandomName(); STEP("create ES client"); elasticClient = new RestHighLevelClient( - RestClient.builder(new HttpHost(AlfrescoStackInitializer.searchEngineContainer.getContainerIpAddress(), - AlfrescoStackInitializer.searchEngineContainer.getFirstMappedPort(), + RestClient.builder(new HttpHost(searchEngineContainer.getContainerIpAddress(), + searchEngineContainer.getFirstMappedPort(), "http"))); - } @Test(groups = TestGroup.SEARCH) public void testReindexerFixesBrokenIndex() { // GIVEN - - // Delete all documents inside Elasticsearch. + String reindexerStartTime = getReindexerStartTime(); cleanUpIndex(); - //stop live indexing - AlfrescoStackInitializer.liveIndexer.stop(); - // Create document. - - String testStart = DateTimeFormatter.ofPattern("yyyyMMddHHmm").format(ZonedDateTime.now(Clock.systemUTC())); - String documentName = createDocument(); + liveIndexer.stop(); + String documentName = createDocumentWithRandomName(); // Check document not indexed. // Nb. The cm:name:* term ensures that the query hits the index rather than the db. - SearchRequest query = req("cm:name:" + documentName + " AND cm:name:*"); searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser()); // WHEN // Run reindexer (leaving ALFRESCO_REINDEX_TO_TIME as default). - try(GenericContainer reindexingComponent = createReindexContainer(Map.of("ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", - "ELASTICSEARCH_INDEX_NAME", CUSTOM_ALFRESCO_INDEX, - "ALFRESCO_REINDEX_FROM_TIME", testStart))) { - //Reindex - reindexingComponent.start(); - - // THEN - // Check document indexed. - searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); - } - // TIDY - // Restart ElasticsearchConnector. - cleanUpIndex(); - AlfrescoStackInitializer.liveIndexer.start(); + reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime)); + // THEN + // Check document indexed. + searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); } @Test(groups = TestGroup.SEARCH) public void testRecreateIndex() { // GIVEN - // Create document. - String documentName = createDocument(); - // Stop ElasticsearchConnector. - AlfrescoStackInitializer.liveIndexer.stop(); - // Delete index documents. + String reindexerStartTime = getReindexerStartTime(); + liveIndexer.start(); + String documentName = createDocumentWithRandomName(); + liveIndexer.stop(); cleanUpIndex(); // WHEN // Run reindexer (with default dates to reindex everything). - try(GenericContainer reindexingComponent = createReindexContainer(Map.of("ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", - "ELASTICSEARCH_INDEX_NAME", CUSTOM_ALFRESCO_INDEX))) { - //Reindex - reindexingComponent.start(); - - // THEN - // Check document indexed. - // Nb. The cm:name:* term ensures that the query hits the index rather than the db. - SearchRequest query = req("cm:name:" + documentName + " AND cm:name:*"); - searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); - } - - // TIDY - // Restart ElasticsearchConnector. - cleanUpIndex(); - AlfrescoStackInitializer.liveIndexer.start(); + reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime)); + // THEN + // Check document indexed. + // Nb. The cm:name:* term ensures that the query hits the index rather than the db. + SearchRequest query = req("cm:name:" + documentName + " AND cm:name:*"); + searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); } - /** - * Common testing method for reindexing enabled and disabled features tests. - * @param metadataIndexingEnabled Reindexing metadata is enabled when true, disabled when false - * @param contentIndexingEnabled Reindexing content is enabled when true, disabled when false - * @param pathIndexingEnabled Reindexing path is enabled when true, disabled when false - * @param queryString Verification query string. It may include a mark that is replaced by the actual document name created. - * @param expectingDocNameAsResult Result from verification query string is the name of the document created when true, empty result when false. - */ - private void internalTestEnabledFeatures( - Boolean metadataIndexingEnabled, - Boolean contentIndexingEnabled, - Boolean pathIndexingEnabled, - String queryString, - Boolean expectingDocNameAsResult - ) + @Test(groups = TestGroup.SEARCH) + public void testRecreateIndexWithMetadataAndContent() { - // Initial timestamp for reindexing by date: this will save reindexing time for these tests - ZonedDateTime now = ZonedDateTime.now(Clock.systemUTC()); - // ACS-5044 Increased time to 20 minutes as 10 minutes proved insufficient to prevent intermittent failures - String testStart = DateTimeFormatter.ofPattern("yyyyMMddHHmm").format(now.minusMinutes(20)); - // GIVEN - // Stop ElasticsearchConnector - AlfrescoStackInitializer.liveIndexer.stop(); - // Create document - String documentName = createDocument(); - // Delete index documents + String reindexerStartTime = getReindexerStartTime(); + liveIndexer.stop(); + String documentName = createDocumentWithRandomName(); cleanUpIndex(); - // Restart ElasticsearchConnector to Index Content - if (contentIndexingEnabled) - { - // Reindexer requires lifeIndexer to index content. - AlfrescoStackInitializer.liveIndexer.start(); - } + // Reindexer requires lifeIndexer to index content. + liveIndexer.start(); // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default - try(GenericContainer reindexingComponent = createReindexContainer(Map.of("ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", - "ELASTICSEARCH_INDEX_NAME", CUSTOM_ALFRESCO_INDEX, - "ALFRESCO_REINDEX_FROM_TIME", testStart, - "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", metadataIndexingEnabled.toString(), - "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", contentIndexingEnabled.toString(), - "ALFRESCO_REINDEX_PATHINDEXINGENABLED", pathIndexingEnabled.toString()))) { - //Reindex - reindexingComponent.start(); - - // THEN - SearchRequest query = req(queryString.replace("", documentName)); - - if (expectingDocNameAsResult) { - searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); - } else { - searchQueryService.expectNoResultsFromQuery(query, dataUser.getAdminUser()); - } - } - - } - - @Test(groups = TestGroup.SEARCH) - public void testRecreateIndexWithMetadataAndContent() - { - internalTestEnabledFeatures(true, true, false, - "cm:name:'' AND TEXT:'content'", true); + reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "true", + "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "true", + "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "false")); + + // THEN + // Document is still indexed after reindexing. + SearchRequest query = req("cm:name:'" + documentName + "' AND TEXT:'content'"); + searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); } @Test(groups = TestGroup.SEARCH) public void testRecreateIndexWithMetadataAndNoContent() { - internalTestEnabledFeatures(true, false, false, - "cm:name:'' AND TEXT:'content'", false); + // GIVEN + String reindexerStartTime = getReindexerStartTime(); + liveIndexer.stop(); + String documentName = createDocumentWithRandomName(); + cleanUpIndex(); + + // WHEN + // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default + reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "true", + "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "false", + "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "false")); + + // THEN + SearchRequest query = req("cm:name:'" + documentName + "' AND TEXT:'content'"); + searchQueryService.expectNoResultsFromQuery(query, dataUser.getAdminUser()); } @Test(groups = TestGroup.SEARCH) public void testRecreateIndexWithNoMetadataAndContent() { + // GIVEN + String reindexerStartTime = getReindexerStartTime(); + liveIndexer.stop(); + String documentName = createDocumentWithRandomName(); + cleanUpIndex(); + // Reindexer requires lifeIndexer to index content. + liveIndexer.start(); + + // WHEN + // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default + reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "false", + "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "true", + "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "false")); + + // THEN // When not using metadata, document shouldn't be present in Elasticsearch index, // since metadata reindexing process is indexing also permissions - internalTestEnabledFeatures(false, true, false, - "cm:name:'' AND cm:name:*", false); + SearchRequest query = req("cm:name:'" + documentName + "' AND cm:name:*"); + searchQueryService.expectNoResultsFromQuery(query, dataUser.getAdminUser()); } @Test(groups = TestGroup.SEARCH) public void testRecreateIndexWithMetadataAndNoContentAndPath() { - internalTestEnabledFeatures(true, false, true, - "cm:name:'' AND PATH:'/app:company_home/st:sites/cm:" + testSite + "/cm:documentLibrary/cm:'", true); + // GIVEN + String reindexerStartTime = getReindexerStartTime(); + liveIndexer.stop(); + String documentName = createDocumentWithRandomName(); + cleanUpIndex(); + + // WHEN + // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default + reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "true", + "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "false", + "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); + + // THEN + SearchRequest query = req("cm:name:'%s' AND PATH:'/app:company_home/st:sites/cm:%s/cm:documentLibrary/cm:%s'".formatted(documentName, testSite, documentName)); + searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); } @Test(groups = TestGroup.SEARCH) public void testRecreateIndexWithMetadataAndContentAndPath() { - internalTestEnabledFeatures(true, true, true, - "cm:name:'' AND TEXT:'content' " + - "AND PATH:'/app:company_home/st:sites/cm:" + testSite + "/cm:documentLibrary/cm:'", true); + // GIVEN + String reindexerStartTime = getReindexerStartTime(); + liveIndexer.stop(); + String documentName = createDocumentWithRandomName(); + cleanUpIndex(); + // Reindexer requires lifeIndexer to index content. + liveIndexer.start(); + + // WHEN + // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default + reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "true", + "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "true", + "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); + + // THEN + SearchRequest query = req("cm:name:'%s' AND TEXT:'content' AND PATH:'/app:company_home/st:sites/cm:%s/cm:documentLibrary/cm:%s'".formatted(documentName, testSite, documentName)); + searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); } @Test(groups = TestGroup.SEARCH) public void testRecreateIndexWithNoMetadataAndPath() { + // GIVEN + String reindexerStartTime = getReindexerStartTime(); + liveIndexer.stop(); + String documentName = createDocumentWithRandomName(); + cleanUpIndex(); + + // WHEN + // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default + reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "false", + "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "false", + "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); + + // THEN // When not using metadata, document shouldn't be present in Elasticsearch index, // since metadata reindexing process is indexing also permissions - internalTestEnabledFeatures(false, false, true, - "cm:name:'' AND cm:name:*", false); + SearchRequest query = req("cm:name:'" + documentName + "' AND cm:name:*"); + searchQueryService.expectNoResultsFromQuery(query, dataUser.getAdminUser()); } @Test (groups = TestGroup.SEARCH) public void testPathReindex() { // GIVEN - // Create document. - String documentName = createDocument(); - // Stop ElasticsearchConnector. - AlfrescoStackInitializer.liveIndexer.stop(); - // Delete index documents. + String reindexerStartTime = getReindexerStartTime(); + liveIndexer.start(); + String documentName = createDocumentWithRandomName(); + liveIndexer.stop(); cleanUpIndex(); // WHEN // Run reindexer with path indexing enabled (and with default dates to reindex everything). - try(GenericContainer reindexingComponent = createReindexContainer(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true", - "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", - "ELASTICSEARCH_INDEX_NAME", CUSTOM_ALFRESCO_INDEX))) { - //Reindex - reindexingComponent.start(); - - // THEN - // Check path indexed. - // Nb. The cm:name:* term ensures that the query hits the index rather than the db. - SearchRequest query = req("PATH:\"//" + documentName + "\" AND cm:name:*"); - searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); - // Also check that the document can be obtained by a path query against the site. - query = req("PATH:\"//" + testSite.getTitle() + "/documentLibrary/*\" AND cm:name:" + documentName + " AND cm:name:*"); - searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); - } + reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", + "true", "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime)); - // TIDY - // Restart ElasticsearchConnector. - AlfrescoStackInitializer.liveIndexer.start(); + // THEN + // Check path indexed. + // Nb. The cm:name:* term ensures that the query hits the index rather than the db. + SearchRequest query = req("PATH:\"//" + documentName + "\" AND cm:name:*"); + searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); + // Also check that the document can be obtained by a path query against the site. + query = req("PATH:\"//" + testSite.getTitle() + "/documentLibrary/*\" AND cm:name:" + documentName + " AND cm:name:*"); + searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); } @Test (groups = TestGroup.SEARCH) public void testPathReindexQueryWithNamespaces() { // GIVEN - // Create document. - String documentName = createDocument(); - // Stop ElasticsearchConnector. - AlfrescoStackInitializer.liveIndexer.stop(); - // Delete index documents. + String reindexerStartTime = getReindexerStartTime(); + liveIndexer.start(); + String documentName = createDocumentWithRandomName(); + liveIndexer.stop(); cleanUpIndex(); // WHEN // Run reindexer with path indexing enabled (and with default dates to reindex everything). - try(GenericContainer reindexingComponent = createReindexContainer(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true", - "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", - "ELASTICSEARCH_INDEX_NAME", CUSTOM_ALFRESCO_INDEX))) { - //Reindex - reindexingComponent.start(); - - // THEN - // Check path indexed. - // Nb. The cm:name:* term ensures that the query hits the index rather than the db. - SearchRequest query = req("PATH:\"//cm:" + documentName + "\" AND cm:name:*"); - searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); - // Also check that the document can be obtained by a path query against the site. - query = req("PATH:\"//cm:" + testSite.getTitle() + "/cm:documentLibrary/*\" AND cm:name:" + documentName + " AND cm:name:*"); - searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); - } + reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true", + "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime)); - // TIDY - // Restart ElasticsearchConnector. - AlfrescoStackInitializer.liveIndexer.start(); + // THEN + // Check path indexed. + // Nb. The cm:name:* term ensures that the query hits the index rather than the db. + SearchRequest query = req("PATH:\"//cm:" + documentName + "\" AND cm:name:*"); + searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); + // Also check that the document can be obtained by a path query against the site. + query = req("PATH:\"//cm:" + testSite.getTitle() + "/cm:documentLibrary/*\" AND cm:name:" + documentName + " AND cm:name:*"); + searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); } - /** - * Run the alfresco-elasticsearch-reindexing container. - * - * @param envParam Any environment variables to override from the defaults. - * @return reindex container - */ - private GenericContainer createReindexContainer(Map envParam) + private String getReindexerStartTime() { - // Run the reindexing container. - Map env = AlfrescoStackInitializer.getReindexEnvBasic(); - env.putAll(envParam); - - return new GenericContainer(getImagesConfig().getReIndexingImage()) - .withEnv(env) - .withNetwork(AlfrescoStackInitializer.network) - .withStartupCheckStrategy(new IndefiniteWaitOneShotStartupCheckStrategy()); + // Initial timestamp for reindexing by date: this will save reindexing time for these tests + ZonedDateTime now = ZonedDateTime.now(Clock.systemUTC()); + return DateTimeFormatter.ofPattern("yyyyMMddHHmm").format(now.minusMinutes(1)); } - /** - * Create a document using in the test site using the test user. - * - * @return The randomly generated name of the new document. - */ - private String createDocument() + private String createDocumentWithRandomName() { String documentName = "TestFile" + UUID.randomUUID() + ".txt"; dataContent.usingUser(testUser) .usingSite(testSite) - .createContent(new org.alfresco.utility.model.FileModel(documentName, org.alfresco.utility.model.FileType.TEXT_PLAIN, "content")); + .createContent(new FileModel(documentName, TEXT_PLAIN, "content")); return documentName; } @@ -374,5 +342,4 @@ private void cleanUpIndex() fail("Failed to tidy index. " + e); } } - } diff --git a/tests/testcontainers-env/src/main/java/org/alfresco/tas/AlfrescoStackInitializer.java b/tests/testcontainers-env/src/main/java/org/alfresco/tas/AlfrescoStackInitializer.java index 0e00d01dcd..bd0d6cfaaf 100644 --- a/tests/testcontainers-env/src/main/java/org/alfresco/tas/AlfrescoStackInitializer.java +++ b/tests/testcontainers-env/src/main/java/org/alfresco/tas/AlfrescoStackInitializer.java @@ -145,14 +145,15 @@ public void configureSecuritySettings(GenericContainer searchEngineContainer) } /** - * Run the alfresco-elasticsearch-reindexing container with path reindexing enabled. + * Run the alfresco-elasticsearch-reindexing container. + * + * @param envParam Any environment variables to override from the defaults. */ - public static void reindexEverything() + public static void reindex(Map envParam) { // Run the reindexing container. Map env = AlfrescoStackInitializer.getReindexEnvBasic(); - env.putAll(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true", // Ensure path reindexing is enabled. - "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate")); + env.putAll(envParam); try (GenericContainer reindexingComponent = new GenericContainer(getImagesConfig().getReIndexingImage()) .withEnv(env) @@ -174,6 +175,7 @@ public static Map getReindexEnvBasic() "SPRING_DATASOURCE_USERNAME", databaseType.getUsername(), "SPRING_DATASOURCE_PASSWORD", databaseType.getPassword(), "ELASTICSEARCH_INDEX_NAME", CUSTOM_ALFRESCO_INDEX, + "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", "SPRING_ACTIVEMQ_BROKER-URL", "nio://activemq:61616", "JAVA_TOOL_OPTIONS", "-Xmx1g", "ALFRESCO_ACCEPTEDCONTENTMEDIATYPESCACHE_BASEURL", "http://transform-core-aio:8090/transform/config")); From 32b72d5b67f1ef928485ba50d510f2e7220e4a83 Mon Sep 17 00:00:00 2001 From: cezary-witkowski Date: Thu, 12 Dec 2024 10:12:09 +0100 Subject: [PATCH 3/5] [ACS-9069] Missed some classes, restoring required method --- .../elasticsearch/parallel/PathUpdateTests.java | 5 +---- .../org/alfresco/tas/AlfrescoStackInitializer.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/parallel/PathUpdateTests.java b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/parallel/PathUpdateTests.java index 03ce2c6417..f7919d07c8 100644 --- a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/parallel/PathUpdateTests.java +++ b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/parallel/PathUpdateTests.java @@ -4,11 +4,8 @@ import static java.util.stream.Collectors.joining; import static org.alfresco.elasticsearch.SearchQueryService.req; -import static org.alfresco.tas.AlfrescoStackInitializer.reindex; import java.util.Arrays; -import java.util.Map; - import jakarta.json.Json; import jakarta.json.JsonObject; @@ -68,7 +65,7 @@ public void dataPreparation() // Before we start testing the live indexing we need to use the reindexing component to index the system nodes. Step.STEP("Index system nodes."); - reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); // Ensure path reindexing is enabled. + AlfrescoStackInitializer.reindexEverything(); Step.STEP("Create a test user and private site."); testUser = dataUser.createRandomTestUser(); diff --git a/tests/testcontainers-env/src/main/java/org/alfresco/tas/AlfrescoStackInitializer.java b/tests/testcontainers-env/src/main/java/org/alfresco/tas/AlfrescoStackInitializer.java index bd0d6cfaaf..0c70990540 100644 --- a/tests/testcontainers-env/src/main/java/org/alfresco/tas/AlfrescoStackInitializer.java +++ b/tests/testcontainers-env/src/main/java/org/alfresco/tas/AlfrescoStackInitializer.java @@ -145,10 +145,18 @@ public void configureSecuritySettings(GenericContainer searchEngineContainer) } /** - * Run the alfresco-elasticsearch-reindexing container. - * - * @param envParam Any environment variables to override from the defaults. + * Run the alfresco-elasticsearch-reindexing container with path reindexing enabled. */ + public static void reindexEverything() + { + reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); // Ensure path reindexing is enabled. + } + + /** + * Run the alfresco-elasticsearch-reindexing container. + * + * @param envParam Any environment variables to override from the defaults. + */ public static void reindex(Map envParam) { // Run the reindexing container. From 6b1b5340e309b92a3e84cdfadcf4d6bd210a92b9 Mon Sep 17 00:00:00 2001 From: cezary-witkowski Date: Fri, 13 Dec 2024 12:52:35 +0100 Subject: [PATCH 4/5] [ACS-9069] Minor tweaks --- .../ElasticsearchInitialReindexingTests.java | 2 +- .../ElasticsearchReindexingTests.java | 22 ++++++++++++++----- .../tas/AlfrescoStackInitializer.java | 4 ++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/initialReindex/ElasticsearchInitialReindexingTests.java b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/initialReindex/ElasticsearchInitialReindexingTests.java index 435ad8a50c..f7ea0fb49d 100644 --- a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/initialReindex/ElasticsearchInitialReindexingTests.java +++ b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/initialReindex/ElasticsearchInitialReindexingTests.java @@ -1,7 +1,7 @@ package org.alfresco.elasticsearch.initialReindex; import static org.alfresco.elasticsearch.SearchQueryService.req; -import static org.alfresco.tas.AlfrescoStackInitializer.*; +import static org.alfresco.tas.AlfrescoStackInitializer.reindex; import static org.alfresco.utility.model.FileType.TEXT_PLAIN; import java.util.Map; diff --git a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java index 6981c2f190..0e16d2efae 100644 --- a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java +++ b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java @@ -45,7 +45,7 @@ */ @ContextConfiguration(locations = "classpath:alfresco-elasticsearch-context.xml", initializers = AlfrescoStackInitializer.class) -@SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation") // these are testng tests +@SuppressWarnings({"PMD.JUnit4TestShouldUseTestAnnotation", "PMD.JUnitTestsShouldIncludeAssert"}) // these are testng tests public class ElasticsearchReindexingTests extends AbstractTestNGSpringContextTests { @Autowired @@ -97,7 +97,8 @@ public void testReindexerFixesBrokenIndex() // WHEN // Run reindexer (leaving ALFRESCO_REINDEX_TO_TIME as default). - reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime)); + reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate")); // THEN // Check document indexed. @@ -116,7 +117,8 @@ public void testRecreateIndex() // WHEN // Run reindexer (with default dates to reindex everything). - reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime)); + reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate")); // THEN // Check document indexed. @@ -139,6 +141,7 @@ public void testRecreateIndexWithMetadataAndContent() // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "true", "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "true", "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "false")); @@ -161,6 +164,7 @@ public void testRecreateIndexWithMetadataAndNoContent() // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "true", "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "false", "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "false")); @@ -184,6 +188,7 @@ public void testRecreateIndexWithNoMetadataAndContent() // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "false", "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "true", "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "false")); @@ -207,6 +212,7 @@ public void testRecreateIndexWithMetadataAndNoContentAndPath() // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "true", "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "false", "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); @@ -230,6 +236,7 @@ public void testRecreateIndexWithMetadataAndContentAndPath() // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "true", "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "true", "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); @@ -251,6 +258,7 @@ public void testRecreateIndexWithNoMetadataAndPath() // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "false", "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "false", "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); @@ -274,8 +282,9 @@ public void testPathReindex() // WHEN // Run reindexer with path indexing enabled (and with default dates to reindex everything). - reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", - "true", "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime)); + reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true", + "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate")); // THEN // Check path indexed. @@ -300,7 +309,8 @@ public void testPathReindexQueryWithNamespaces() // WHEN // Run reindexer with path indexing enabled (and with default dates to reindex everything). reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true", - "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime)); + "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, + "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate")); // THEN // Check path indexed. diff --git a/tests/testcontainers-env/src/main/java/org/alfresco/tas/AlfrescoStackInitializer.java b/tests/testcontainers-env/src/main/java/org/alfresco/tas/AlfrescoStackInitializer.java index 0c70990540..f77887535d 100644 --- a/tests/testcontainers-env/src/main/java/org/alfresco/tas/AlfrescoStackInitializer.java +++ b/tests/testcontainers-env/src/main/java/org/alfresco/tas/AlfrescoStackInitializer.java @@ -149,7 +149,8 @@ public void configureSecuritySettings(GenericContainer searchEngineContainer) */ public static void reindexEverything() { - reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); // Ensure path reindexing is enabled. + reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true", // Ensure path reindexing is enabled. + "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate")); } /** @@ -183,7 +184,6 @@ public static Map getReindexEnvBasic() "SPRING_DATASOURCE_USERNAME", databaseType.getUsername(), "SPRING_DATASOURCE_PASSWORD", databaseType.getPassword(), "ELASTICSEARCH_INDEX_NAME", CUSTOM_ALFRESCO_INDEX, - "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", "SPRING_ACTIVEMQ_BROKER-URL", "nio://activemq:61616", "JAVA_TOOL_OPTIONS", "-Xmx1g", "ALFRESCO_ACCEPTEDCONTENTMEDIATYPESCACHE_BASEURL", "http://transform-core-aio:8090/transform/config")); From 28014d8a562980fb9ab2da7f641d40b6142d6a1a Mon Sep 17 00:00:00 2001 From: cezary-witkowski Date: Sat, 14 Dec 2024 16:24:02 +0100 Subject: [PATCH 5/5] [ACS-9069] Revert changes to restore old behaviour of tests --- .../ElasticsearchReindexingTests.java | 84 +++++++++++-------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java index 0e16d2efae..4b32d969b4 100644 --- a/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java +++ b/tests/tas-elasticsearch/src/test/java/org/alfresco/elasticsearch/reindexing/ElasticsearchReindexingTests.java @@ -86,9 +86,9 @@ public void dataPreparation() public void testReindexerFixesBrokenIndex() { // GIVEN - String reindexerStartTime = getReindexerStartTime(); cleanUpIndex(); liveIndexer.stop(); + String reindexerStartTime = getReindexerStartTimeNow(); String documentName = createDocumentWithRandomName(); // Check document not indexed. // Nb. The cm:name:* term ensures that the query hits the index rather than the db. @@ -97,41 +97,47 @@ public void testReindexerFixesBrokenIndex() // WHEN // Run reindexer (leaving ALFRESCO_REINDEX_TO_TIME as default). - reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, - "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate")); + reindex(Map.of("ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime)); // THEN // Check document indexed. searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); + + // TIDY + cleanUpIndex(); + liveIndexer.start(); } @Test(groups = TestGroup.SEARCH) public void testRecreateIndex() { // GIVEN - String reindexerStartTime = getReindexerStartTime(); - liveIndexer.start(); String documentName = createDocumentWithRandomName(); liveIndexer.stop(); cleanUpIndex(); // WHEN // Run reindexer (with default dates to reindex everything). - reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, - "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate")); + reindex(Map.of("ALFRESCO_REINDEX_JOB_NAME", "reindexByDate")); // THEN // Check document indexed. // Nb. The cm:name:* term ensures that the query hits the index rather than the db. SearchRequest query = req("cm:name:" + documentName + " AND cm:name:*"); searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); + + // TIDY + // Restart ElasticsearchConnector. + cleanUpIndex(); + liveIndexer.start(); } @Test(groups = TestGroup.SEARCH) public void testRecreateIndexWithMetadataAndContent() { // GIVEN - String reindexerStartTime = getReindexerStartTime(); + String reindexerStartTime = getReindexerStartTimeTwentyMinutesAgo(); liveIndexer.stop(); String documentName = createDocumentWithRandomName(); cleanUpIndex(); @@ -140,8 +146,8 @@ public void testRecreateIndexWithMetadataAndContent() // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default - reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, - "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + reindex(Map.of("ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "true", "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "true", "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "false")); @@ -156,15 +162,15 @@ public void testRecreateIndexWithMetadataAndContent() public void testRecreateIndexWithMetadataAndNoContent() { // GIVEN - String reindexerStartTime = getReindexerStartTime(); + String reindexerStartTime = getReindexerStartTimeTwentyMinutesAgo(); liveIndexer.stop(); String documentName = createDocumentWithRandomName(); cleanUpIndex(); // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default - reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, - "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + reindex(Map.of("ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "true", "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "false", "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "false")); @@ -178,7 +184,7 @@ public void testRecreateIndexWithMetadataAndNoContent() public void testRecreateIndexWithNoMetadataAndContent() { // GIVEN - String reindexerStartTime = getReindexerStartTime(); + String reindexerStartTime = getReindexerStartTimeTwentyMinutesAgo(); liveIndexer.stop(); String documentName = createDocumentWithRandomName(); cleanUpIndex(); @@ -187,8 +193,8 @@ public void testRecreateIndexWithNoMetadataAndContent() // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default - reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, - "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + reindex(Map.of("ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "false", "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "true", "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "false")); @@ -204,15 +210,15 @@ public void testRecreateIndexWithNoMetadataAndContent() public void testRecreateIndexWithMetadataAndNoContentAndPath() { // GIVEN - String reindexerStartTime = getReindexerStartTime(); + String reindexerStartTime = getReindexerStartTimeTwentyMinutesAgo(); liveIndexer.stop(); String documentName = createDocumentWithRandomName(); cleanUpIndex(); // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default - reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, - "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + reindex(Map.of("ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "true", "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "false", "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); @@ -226,7 +232,7 @@ public void testRecreateIndexWithMetadataAndNoContentAndPath() public void testRecreateIndexWithMetadataAndContentAndPath() { // GIVEN - String reindexerStartTime = getReindexerStartTime(); + String reindexerStartTime = getReindexerStartTimeTwentyMinutesAgo(); liveIndexer.stop(); String documentName = createDocumentWithRandomName(); cleanUpIndex(); @@ -235,8 +241,8 @@ public void testRecreateIndexWithMetadataAndContentAndPath() // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default - reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, - "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + reindex(Map.of("ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "true", "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "true", "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); @@ -250,15 +256,15 @@ public void testRecreateIndexWithMetadataAndContentAndPath() public void testRecreateIndexWithNoMetadataAndPath() { // GIVEN - String reindexerStartTime = getReindexerStartTime(); + String reindexerStartTime = getReindexerStartTimeTwentyMinutesAgo(); liveIndexer.stop(); String documentName = createDocumentWithRandomName(); cleanUpIndex(); // WHEN // Run reindexer leaving ALFRESCO_REINDEX_TO_TIME as default - reindex(Map.of("ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, - "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + reindex(Map.of("ALFRESCO_REINDEX_JOB_NAME", "reindexByDate", + "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, "ALFRESCO_REINDEX_METADATAINDEXINGENABLED", "false", "ALFRESCO_REINDEX_CONTENTINDEXINGENABLED", "false", "ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true")); @@ -274,8 +280,6 @@ public void testRecreateIndexWithNoMetadataAndPath() public void testPathReindex() { // GIVEN - String reindexerStartTime = getReindexerStartTime(); - liveIndexer.start(); String documentName = createDocumentWithRandomName(); liveIndexer.stop(); cleanUpIndex(); @@ -283,7 +287,6 @@ public void testPathReindex() // WHEN // Run reindexer with path indexing enabled (and with default dates to reindex everything). reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true", - "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate")); // THEN @@ -294,14 +297,15 @@ public void testPathReindex() // Also check that the document can be obtained by a path query against the site. query = req("PATH:\"//" + testSite.getTitle() + "/documentLibrary/*\" AND cm:name:" + documentName + " AND cm:name:*"); searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); + + // TIDY + liveIndexer.start(); } @Test (groups = TestGroup.SEARCH) public void testPathReindexQueryWithNamespaces() { // GIVEN - String reindexerStartTime = getReindexerStartTime(); - liveIndexer.start(); String documentName = createDocumentWithRandomName(); liveIndexer.stop(); cleanUpIndex(); @@ -309,7 +313,6 @@ public void testPathReindexQueryWithNamespaces() // WHEN // Run reindexer with path indexing enabled (and with default dates to reindex everything). reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true", - "ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime, "ALFRESCO_REINDEX_JOB_NAME", "reindexByDate")); // THEN @@ -320,13 +323,28 @@ public void testPathReindexQueryWithNamespaces() // Also check that the document can be obtained by a path query against the site. query = req("PATH:\"//cm:" + testSite.getTitle() + "/cm:documentLibrary/*\" AND cm:name:" + documentName + " AND cm:name:*"); searchQueryService.expectResultsFromQuery(query, dataUser.getAdminUser(), documentName); + + // TIDY + liveIndexer.start(); } - private String getReindexerStartTime() + private String getReindexerStartTimeNow() + { + ZonedDateTime now = ZonedDateTime.now(Clock.systemUTC()); + return formatTimeForReindexer(now); + } + + private String getReindexerStartTimeTwentyMinutesAgo() { // Initial timestamp for reindexing by date: this will save reindexing time for these tests ZonedDateTime now = ZonedDateTime.now(Clock.systemUTC()); - return DateTimeFormatter.ofPattern("yyyyMMddHHmm").format(now.minusMinutes(1)); + // ACS-5044 Increased time to 20 minutes as 10 minutes proved insufficient to prevent intermittent failures + return formatTimeForReindexer(now.minusMinutes(20)); + } + + private String formatTimeForReindexer(ZonedDateTime zonedDateTime) + { + return DateTimeFormatter.ofPattern("yyyyMMddHHmm").format(zonedDateTime); } private String createDocumentWithRandomName()