[SEARCH-1829]

Adding test for checking that indexing still works after sharding model has been disabled.
Modified cascading sharding test in order to clean up the environment after test execution.
This commit is contained in:
eliaporciani
2019-09-13 10:09:05 +02:00
parent 433959dacb
commit 39421555af
3 changed files with 175 additions and 23 deletions
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<model name="shard:contentModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<description>Explicit Routing for Sharding Sample Model</description>
<imports>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
</imports>
<namespaces>
<namespace uri="http://www.alfresco.org/model/sharding/1.0" prefix="shard"/>
</namespaces>
<aspects>
<aspect name="shard:sharding">
<title>Sharding</title>
<properties>
<!-- Shard number to index this content -->
<property name="shard:shardId">
<title>Shard Id</title>
<type>d:text</type>
</property>
</properties>
</aspect>
</aspects>
</model>
@@ -0,0 +1,79 @@
package org.alfresco.test.search.functional.searchServices.search;
import org.alfresco.search.TestGroup;
import org.alfresco.test.search.functional.AbstractE2EFunctionalTest;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FileType;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
import org.testng.annotations.Test;
import java.util.List;
import java.util.Map;
import static org.testng.Assert.assertTrue;
public class ExplicitRouting extends AbstractE2EFunctionalTest {
/**
* Checks indexing still works after sharding model used for explicit routing has been disabled
* @throws Exception
*/
@Test(priority = 1, groups = {TestGroup.NOT_BAMBOO, TestGroup.EXPLICIT_SHARDING })
public void testIndexingStillWorkingAfterShardModelIsDeactivated() throws Exception
{
// Deploy sharding model
assertTrue(deployCustomModel("model/sharding-content-model.xml"),
"failing while deploying sharding model");
// Create a first child in parent folder. It will be indexed in the parent shard (shard 0)
FileModel file = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content");
Map<String, Object> propertiesFirstChild = Map.of(PropertyIds.NAME, file.getName(),
PropertyIds.OBJECT_TYPE_ID, "cmis:document",
"cmis:secondaryObjectTypeIds", List.of("P:shard:sharding"),
"shard:shardId", "0");
// Create file using shard:shardId
cmisApi.authenticateUser(testUser).usingSite(testSite)
.createFile(file,
Map.of(PropertyIds.NAME, file.getName(),
PropertyIds.OBJECT_TYPE_ID, "cmis:document"),
VersioningState.MAJOR)
.assertThat().existsInRepo();
// Wait for file to be indexed
assertTrue(waitForMetadataIndexing(file.getName(), true),
"A file using sharding model has not been indexed");
// Deleting file
dataContent.usingSite(testSite).usingUser(testUser).usingResource(file).deleteContent();
restClient.withCoreAPI().usingTrashcan().deleteNodeFromTrashcan(file);
// Deleting sharding model
assertTrue(deactivateCustomModel("sharding-content-model.xml"),
"failing while deactivating sharding model");
assertTrue(deleteCustomModel("sharding-content-model.xml"),
"failing while removing sharding model");
assertTrue(waitForIndexing("TYPE:'" + "shard:shardId" + "'", false),
"Indexes are not updated after deactivating a model");
// Create a file in the parent folder
file = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content");
cmisApi.authenticateUser(testUser).usingSite(testSite)
.createFile(file,
Map.of(PropertyIds.NAME, file.getName(),
PropertyIds.OBJECT_TYPE_ID, "cmis:document"),
VersioningState.MAJOR)
.assertThat().existsInRepo();
assertTrue(waitForMetadataIndexing(file.getName(), true),
"Indexing is not working after the sharding model has been removed");
}
}
@@ -19,8 +19,12 @@ import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static org.testng.Assert.assertTrue;
/**
* Test class tests cascading updates for a child node when parent node is updated
*
@@ -31,6 +35,46 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest
{
@Autowired
protected DataContent dataContent;
private FolderModel parentFolderSharded;
private FileModel firstChildFileSharded;
private FileModel secondChildFileSharded;
@BeforeClass(alwaysRun = true)
public void setupEnvironment()
{
assertTrue(deployCustomModel("model/sharding-content-model.xml"),
"failing while deploying sharding model");
}
@AfterClass
public void cleanUpEnvironment()
{
if (firstChildFileSharded != null)
{
dataContent.usingSite(testSite).usingUser(testUser).usingResource(firstChildFileSharded).deleteContent();
restClient.withCoreAPI().usingTrashcan().deleteNodeFromTrashcan(firstChildFileSharded);
}
if (secondChildFileSharded != null)
{
dataContent.usingSite(testSite).usingUser(testUser).usingResource(secondChildFileSharded).deleteContent();
restClient.withCoreAPI().usingTrashcan().deleteNodeFromTrashcan(secondChildFileSharded);
}
if (parentFolderSharded != null)
{
dataContent.usingSite(testSite).usingUser(testUser).usingResource(parentFolderSharded).deleteContent();
restClient.withCoreAPI().usingTrashcan().deleteNodeFromTrashcan(parentFolderSharded);
}
dataContent.deleteSite(testSite);
assertTrue(deactivateCustomModel("sharding-content-model.xml"),
"failing while deactivating sharding model");
assertTrue(deleteCustomModel("sharding-content-model.xml"),
"failing while removing sharding model");
}
@Test(priority = 1)
public void testChildPathWhenParentRenamed() throws Exception
@@ -41,6 +85,7 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest
// Create a file in the parent folder
FileModel childFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content");
cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(parentFolder)
.createFile(childFile,
Map.of(PropertyIds.NAME, childFile.getName(),
@@ -79,10 +124,10 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest
public void testGrandChildPathWhenGrandParentRenamed() throws Exception
{
// Create grand parent folder
FolderModel grandParentFolder = dataContent.usingSite(testSite).usingUser(testUser).createFolder();
FolderModel grandParentFolderSharding = dataContent.usingSite(testSite).usingUser(testUser).createFolder();
// Create child folder
FolderModel childFolder = dataContent.usingUser(testUser).usingResource(grandParentFolder).createFolder();
FolderModel childFolder = dataContent.usingUser(testUser).usingResource(grandParentFolderSharding).createFolder();
// Create grand child file
FileModel grandChildFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content");
@@ -100,15 +145,15 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest
// Query to find nodes where Path with original folder name matches
String parentQuery = "PATH:\"/app:company_home/st:sites/cm:" + testSite.getTitle() +
"/cm:documentLibrary/cm:" + grandParentFolder.getName() + "/*\"";
"/cm:documentLibrary/cm:" + grandParentFolderSharding.getName() + "/*\"";
// Rename grand parent folder
String grandParentNewName = "grandParentRenamed";
grandParentFolder.setName(grandParentNewName);
grandParentFolderSharding.setName(grandParentNewName);
ContentModel grandParentFolderRenamed = new ContentModel(grandParentNewName);
dataContent.usingUser(testUser).usingResource(grandParentFolder).renameContent(grandParentFolderRenamed);
dataContent.usingUser(testUser).usingResource(grandParentFolderSharding).renameContent(grandParentFolderRenamed);
// Find nodes where Path with new folder name matches
String childrenQueryAfterRename = "PATH:\"/app:company_home/st:sites/cm:" + testSite.getTitle() +
@@ -148,48 +193,48 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest
{
// Create Parent folder. It will be indexed in shard 0
FolderModel parentFolder = FolderModel.getRandomFolderModel();
parentFolderSharded = FolderModel.getRandomFolderModel();
List<String> secondaryTypes = List.of("P:shard:sharding");
Map<String, Object> parentProperties = Map.of(PropertyIds.NAME, parentFolder.getName(),
Map<String, Object> parentProperties = Map.of(PropertyIds.NAME, parentFolderSharded.getName(),
PropertyIds.OBJECT_TYPE_ID, "cmis:folder",
"cmis:secondaryObjectTypeIds", secondaryTypes,
"shard:shardId", "0");
// Create a first child in parent folder. It will be indexed in the parent shard (shard 0)
FileModel firstChildFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content");
Map<String, Object> propertiesFirstChild = Map.of(PropertyIds.NAME, firstChildFile.getName(),
firstChildFileSharded = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content");
Map<String, Object> propertiesFirstChild = Map.of(PropertyIds.NAME, firstChildFileSharded.getName(),
PropertyIds.OBJECT_TYPE_ID, "cmis:document",
"cmis:secondaryObjectTypeIds", secondaryTypes,
"shard:shardId", "0");
// Create a second child in parent folder. It will be indexed in shard 1.
FileModel secondChildFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content");
Map<String, Object> propertiesSecondChild = Map.of(PropertyIds.NAME, secondChildFile.getName(),
secondChildFileSharded = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content");
Map<String, Object> propertiesSecondChild = Map.of(PropertyIds.NAME, secondChildFileSharded.getName(),
PropertyIds.OBJECT_TYPE_ID, "cmis:document",
"cmis:secondaryObjectTypeIds", secondaryTypes,
"shard:shardId", "1");
cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(parentFolder, parentProperties).then()
.usingResource(parentFolder)
.createFile(firstChildFile, propertiesFirstChild, VersioningState.MAJOR)
.createFile(secondChildFile, propertiesSecondChild, VersioningState.MAJOR);
cmisApi.authenticateUser(testUser).usingSite(testSite).createFolder(parentFolderSharded, parentProperties).then()
.usingResource(parentFolderSharded)
.createFile(firstChildFileSharded, propertiesFirstChild, VersioningState.MAJOR)
.createFile(secondChildFileSharded, propertiesSecondChild, VersioningState.MAJOR);
// Check everything is indexed
Assert.assertTrue(waitForIndexing(firstChildFile.getName(), true), "file: " + firstChildFile.getName() + " has not been indexed.");
Assert.assertTrue(waitForIndexing(secondChildFile.getName(), true), "file: " + secondChildFile.getName() + " has not been indexed.");
Assert.assertTrue(waitForIndexing(parentFolder.getName(), true), "file: " + parentFolder.getName() + " has not been indexed.");
assertTrue(waitForIndexing(firstChildFileSharded.getName(), true), "file: " + firstChildFileSharded.getName() + " has not been indexed.");
assertTrue(waitForIndexing(secondChildFileSharded.getName(), true), "file: " + secondChildFileSharded.getName() + " has not been indexed.");
assertTrue(waitForIndexing(parentFolderSharded.getName(), true), "file: " + parentFolderSharded.getName() + " has not been indexed.");
// Query to find nodes where Path with original folder name matches
String parentQuery = "PATH:\"/app:company_home/st:sites/cm:" + testSite.getTitle() +
"/cm:documentLibrary/cm:" + parentFolder.getName() + "/*\"";
"/cm:documentLibrary/cm:" + parentFolderSharded.getName() + "/*\"";
// Rename parent folder
String parentNewName = "parentRenamedSharding";
parentFolder.setName(parentNewName);
parentFolderSharded.setName(parentNewName);
ContentModel parentNewNameModel = new ContentModel(parentNewName);
dataContent.usingUser(testUser).usingResource(parentFolder).renameContent(parentNewNameModel);
dataContent.usingUser(testUser).usingResource(parentFolderSharded).renameContent(parentNewNameModel);
String parentQueryAfterRename = "PATH:\"/app:company_home/st:sites/cm:" + testSite.getTitle() +
"/cm:documentLibrary/cm:" + parentNewName + "/*\"";
@@ -199,9 +244,9 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest
Assert.assertEquals(descendantCountOfNewNameBeforeUpdate, 0, "There should be 0 results performing the new query before updating parent name");
Assert.assertTrue(waitForMetadataIndexing(parentNewName, true), "failing while renaming " + parentFolder.getName() + " to " + parentNewName);
assertTrue(waitForMetadataIndexing(parentNewName, true), "failing while renaming " + parentFolderSharded.getName() + " to " + parentNewName);
boolean indexingInProgress = !isContentInSearchResults(parentQueryAfterRename, firstChildFile.getName(), true);
boolean indexingInProgress = !isContentInSearchResults(parentQueryAfterRename, firstChildFileSharded.getName(), true);
// Query using new parent name: Expect the two children
int descendantCountOfNewName = query(parentQueryAfterRename).getPagination().getCount();
@@ -210,6 +255,7 @@ public class CascadingTrackerIntegrationTest extends AbstractE2EFunctionalTest
// Query using old parent name: Expect no descendant after rename
int descendantCountOfOriginalName = query(parentQuery).getPagination().getCount();
Assert.assertEquals(descendantCountOfOriginalName, 0, "Old path still has descendants: " + parentQuery);
}
}