Skip to content

Commit

Permalink
[ACS-9069] Revert changes to restore old behaviour of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cezary-witkowski committed Dec 14, 2024
1 parent 6b1b534 commit 28014d8
Showing 1 changed file with 51 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
Expand All @@ -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"));
Expand All @@ -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"));
Expand All @@ -178,7 +184,7 @@ public void testRecreateIndexWithMetadataAndNoContent()
public void testRecreateIndexWithNoMetadataAndContent()
{
// GIVEN
String reindexerStartTime = getReindexerStartTime();
String reindexerStartTime = getReindexerStartTimeTwentyMinutesAgo();
liveIndexer.stop();
String documentName = createDocumentWithRandomName();
cleanUpIndex();
Expand All @@ -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"));
Expand All @@ -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"));
Expand All @@ -226,7 +232,7 @@ public void testRecreateIndexWithMetadataAndNoContentAndPath()
public void testRecreateIndexWithMetadataAndContentAndPath()
{
// GIVEN
String reindexerStartTime = getReindexerStartTime();
String reindexerStartTime = getReindexerStartTimeTwentyMinutesAgo();
liveIndexer.stop();
String documentName = createDocumentWithRandomName();
cleanUpIndex();
Expand All @@ -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"));
Expand All @@ -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"));
Expand All @@ -274,16 +280,13 @@ public void testRecreateIndexWithNoMetadataAndPath()
public void testPathReindex()
{
// GIVEN
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).
reindex(Map.of("ALFRESCO_REINDEX_PATHINDEXINGENABLED", "true",
"ALFRESCO_REINDEX_FROM_TIME", reindexerStartTime,
"ALFRESCO_REINDEX_JOB_NAME", "reindexByDate"));

// THEN
Expand All @@ -294,22 +297,22 @@ 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();

// 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
Expand All @@ -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()
Expand Down

0 comments on commit 28014d8

Please sign in to comment.