From 39421555afbd088ae759d6daf60f3d5f5441f8a4 Mon Sep 17 00:00:00 2001 From: eliaporciani Date: Fri, 13 Sep 2019 10:09:05 +0200 Subject: [PATCH] [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. --- .../model/sharding-content-model.xml | 27 ++++++ .../search/ExplicitRouting.java | 79 ++++++++++++++++ .../CascadingTrackerIntegrationTest.java | 92 ++++++++++++++----- 3 files changed, 175 insertions(+), 23 deletions(-) create mode 100644 e2e-test/src/main/resources/model/sharding-content-model.xml create mode 100644 e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/ExplicitRouting.java diff --git a/e2e-test/src/main/resources/model/sharding-content-model.xml b/e2e-test/src/main/resources/model/sharding-content-model.xml new file mode 100644 index 000000000..159d02f12 --- /dev/null +++ b/e2e-test/src/main/resources/model/sharding-content-model.xml @@ -0,0 +1,27 @@ + + + + Explicit Routing for Sharding Sample Model + + + + + + + + + + + + Sharding + + + + Shard Id + d:text + + + + + + diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/ExplicitRouting.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/ExplicitRouting.java new file mode 100644 index 000000000..e0691ca5f --- /dev/null +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/ExplicitRouting.java @@ -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 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"); + + } +} diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java index daf9e0ce0..977e12cd8 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/tracker/CascadingTrackerIntegrationTest.java @@ -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 secondaryTypes = List.of("P:shard:sharding"); - Map parentProperties = Map.of(PropertyIds.NAME, parentFolder.getName(), + Map 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 propertiesFirstChild = Map.of(PropertyIds.NAME, firstChildFile.getName(), + firstChildFileSharded = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); + Map 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 propertiesSecondChild = Map.of(PropertyIds.NAME, secondChildFile.getName(), + secondChildFileSharded = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); + Map 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); + } }