Skip to content

Commit

Permalink
[ACS-9069] Refactoring reindex tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cezary-witkowski committed Dec 12, 2024
1 parent 83d8413 commit 3eb886b
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 252 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;

Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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")));

}

/**
Expand All @@ -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<String, String> envParam)
{
// Run the reindexing container.
Map<String, String> 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.
*
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 3eb886b

Please sign in to comment.