Search-2142: Fixed the solr api tests to work based on the Sharding Method

This commit is contained in:
Meenal Bhave
2020-04-01 13:59:58 +01:00
parent 17a5b9c652
commit 88e5718325
6 changed files with 103 additions and 58 deletions
@@ -27,14 +27,12 @@ public class TestGroup
public static final String PREUPGRADE = "pre-upgrade";
public static final String POSTUPGRADE = "post-upgrade";
public static final String ASS_MASTER_SLAVE = "ASS_Master_Slave"; // Alfresco Search Services using master slave configurations
public static final String ASS_MASTER ="ASS_Master"; // Alfresco search services using master/stand alone mode
public static final String EXPLICIT_SHARDING ="Explicit_Sharding"; // Alfresco search services using sharded environment and explicit routing
public static final String CONFIG_MASTER_SLAVE = "CONFIG_Master_Slave"; // Alfresco Search Services using master slave configurations
public static final String CONFIG_MASTER ="CONFIG_Master"; // Alfresco search services using master/stand alone mode
public static final String SHARDING ="Sharding"; // Alfresco search services using sharded environment
public static final String ASS_SHARDING = "ASS_Sharding"; // Alfresco Search Services using Sharding
public static final String ASS_SHARDING_DB_ID_RANGE = "ASS_Sharding_DB_ID_RANGE"; // Alfresco Search Services using Sharding with DB_ID_RANGE
public static final String CONFIG_SHARDING ="CONFIG_Sharding"; // Alfresco search services using sharded environment
public static final String CONFIG_SHARDING_EXPLICIT ="CONFIG_Sharding_EXPLICIT"; // Alfresco search services using sharded environment and explicit routing
public static final String CONFIG_SHARDING_DB_ID_RANGE = "CONFIG_Sharding_DB_ID_RANGE"; // Alfresco Search Services using Sharding with DB_ID_RANGE
public static final String NOT_INSIGHT_ENGINE = "Not_InsightEngine"; // When Alfresco Insight Engine 1.0 isn't running
@@ -46,6 +44,4 @@ public class TestGroup
public static final String ACS_63n = "ACS_63n"; // Alfresco Content Services 6.3 or above
public static final String AGS_302 = "AGS_302"; // Alfresco governance Services 3.0.2 or above
public static final String NOT_BAMBOO = "Not_Bamboo"; // The does not run on bamboo
}
@@ -11,6 +11,8 @@ import static java.util.Optional.ofNullable;
import static lombok.AccessLevel.PROTECTED;
import static org.testng.Assert.assertEquals;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -21,10 +23,13 @@ import org.alfresco.dataprep.ContentService;
import org.alfresco.dataprep.SiteService.Visibility;
import org.alfresco.rest.core.RestProperties;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.exception.EmptyRestModelCollectionException;
import org.alfresco.rest.model.RestRequestSpellcheckModel;
import org.alfresco.rest.search.Pagination;
import org.alfresco.rest.search.RestRequestHighlightModel;
import org.alfresco.rest.search.RestRequestQueryModel;
import org.alfresco.rest.search.RestShardInfoModel;
import org.alfresco.rest.search.RestShardInfoModelCollection;
import org.alfresco.rest.search.SearchRequest;
import org.alfresco.rest.search.SearchResponse;
import org.alfresco.utility.LogFactory;
@@ -49,6 +54,8 @@ import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import com.fasterxml.jackson.core.JsonProcessingException;
/**
* @author meenal bhave
*/
@@ -93,6 +100,9 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
protected SiteModel testSite, testSite2;
protected static String unique_searchString;
protected static String shardingMethod = "DB_ID";
protected int shardCount = 0;
protected static final String SEARCH_LANGUAGE_CMIS = "cmis";
@@ -101,6 +111,16 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
AFTS
}
protected enum ShardingMethod {
DB_ID,
DB_ID_RANGE,
MOD_ACL_ID,
ACL_ID,
DATE,
PROPERTY,
EXPLICIT_ID
}
@BeforeSuite (alwaysRun = true)
public void beforeSuite() throws Exception
{
@@ -595,4 +615,50 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
response.getContext().getSpellCheck().assertThat().field("suggestions").contains(spellCheckSuggestion);
}
}
/**
* Method returns the sharding method used for the core by the 1st shard instance registered with ACS
* @return String sharding Method
* @throws JsonProcessingException
* @throws EmptyRestModelCollectionException
*/
public String getShardMethod() throws JsonProcessingException, EmptyRestModelCollectionException
{
RestShardInfoModelCollection info = getShardInfo();
return shardingMethod =
ofNullable(info)
.map(RestShardInfoModelCollection::getEntries)
.map(Collection::iterator)
.filter(Iterator::hasNext)
.map(Iterator::next)
.map(RestShardInfoModel::getShardMethod)
.orElseThrow( () -> new RuntimeException("Cannot retrieve the shard method in use."));
}
/**
* Method returns the shardCount for the 1st core (of the shard instance) that registers with ACS
* @return shard Count
* @throws JsonProcessingException
* @throws EmptyRestModelCollectionException
*/
public int getShardCount() throws JsonProcessingException, EmptyRestModelCollectionException
{
RestShardInfoModelCollection info = getShardInfo();
return shardCount = ofNullable(info)
.map(RestShardInfoModelCollection::getEntries)
.map(Collection::iterator)
.filter(Iterator::hasNext)
.map(Iterator::next)
.map(RestShardInfoModel::getNumberOfShards)
.orElseThrow( () -> new RuntimeException("Cannot retrieve the number of shards registered."));
}
public RestShardInfoModelCollection getShardInfo() throws JsonProcessingException, EmptyRestModelCollectionException
{
RestShardInfoModelCollection info = restClient.authenticateUser(dataUser.getAdminUser()).withShardInfoAPI().getInfo();
return info;
}
}
@@ -20,7 +20,7 @@ public class ExplicitRoutingTest 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, TestGroup.ACS_62n})
@Test(priority = 1, groups = {TestGroup.CONFIG_SHARDING, TestGroup.CONFIG_SHARDING_EXPLICIT, TestGroup.ACS_62n})
public void testIndexingStillWorkingAfterShardModelIsDeactivated() throws Exception
{
@@ -20,7 +20,6 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -44,7 +43,7 @@ import org.springframework.http.HttpStatus;
public class ShardInfoTest extends AbstractE2EFunctionalTest
{
/* The test that will be excluded when running master slave setup, excluding the ASS_MASTER test group. */
@Test(groups = { TestGroup.ACS_60n, TestGroup.ASS_MASTER })
@Test(groups = { TestGroup.ACS_60n, TestGroup.CONFIG_MASTER })
public void getShardInfoWithAdminAuthority() throws JsonProcessingException
{
RestShardInfoModelCollection info = restClient.authenticateUser(dataUser.getAdminUser()).withShardInfoAPI()
@@ -89,7 +88,7 @@ public class ShardInfoTest extends AbstractE2EFunctionalTest
}
/* The test that will be run when in master slave setup by including the ASS_MASTER_SLAVE test group. */
@Test(groups = {TestGroup.ACS_60n, TestGroup.ASS_MASTER_SLAVE })
@Test(groups = {TestGroup.ACS_60n, TestGroup.CONFIG_MASTER_SLAVE })
public void getShardInfoWithAdminAuthorityMasterSlaveConfig() throws JsonProcessingException
{
RestShardInfoModelCollection info = restClient.authenticateUser(dataUser.getAdminUser()).withShardInfoAPI()
@@ -139,7 +138,7 @@ public class ShardInfoTest extends AbstractE2EFunctionalTest
* @throws JsonProcessingException
*/
@Test(groups = { TestGroup.ACS_60n, TestGroup.SHARDING })
@Test(groups = { TestGroup.ACS_60n, TestGroup.CONFIG_SHARDING })
public void getShardInfoWith2OrMoreShards() throws JsonProcessingException
{
RestShardInfoModelCollection info = restClient.authenticateUser(dataUser.getAdminUser()).withShardInfoAPI().getInfo();
@@ -187,7 +187,7 @@ public class CascadingIntegrationTest extends AbstractE2EFunctionalTest
* Check that, after parent renaming, both the children are searchable in the new path
* (computed accordingly with the new parent folder name)
*/
@Test(priority = 3, groups = {TestGroup.NOT_BAMBOO, TestGroup.EXPLICIT_SHARDING })
@Test(priority = 3, groups = {TestGroup.CONFIG_SHARDING, TestGroup.CONFIG_SHARDING_EXPLICIT })
public void testChildrenPathOnParentRenamedWithChildrenInDifferentShards() throws Exception
{
@@ -31,6 +31,7 @@ import org.testng.annotations.Test;
* http://<server>:<port>/solr/admin/cores?action=(actionName)
*
* @author aborroy
* @author mbhave
*
*/
@Configuration
@@ -465,7 +466,7 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest
* This test verifies expected result when using another deployment
* @throws Exception
*/
@Test(priority = 20)
@Test(priority = 20, groups = {TestGroup.CONFIG_SHARDING})
public void testRangeCheck() throws Exception
{
String coreName = "alfresco";
@@ -475,24 +476,17 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest
checkResponseStatusOk(response);
Integer expand = response.getResponse().body().jsonPath().get("expand");
Assert.assertEquals(expand, Integer.valueOf(-1), "Expansion is not allowed when not using Shard DB_ID_RANGE method,");
}
/**
* When using DB_ID_RANGE Sharding method, expand param is including a number of nodes to be extended.
* @throws Exception
*/
@Test(priority = 21, groups = { TestGroup.ASS_SHARDING_DB_ID_RANGE })
public void testRangeCheckSharding() throws Exception
{
String coreName = "alfresco";
RestResponse response = restClient.withParams("coreName=" + coreName).withSolrAdminAPI().getAction("rangeCheck");
checkResponseStatusOk(response);
Integer expand = response.getResponse().body().jsonPath().get("expand");
Assert.assertNotEquals(expand, Integer.valueOf(-1), "Expansion is a positive number when using Shard DB_ID_RANGE method,");
// RangeCheck action only applies to DB_ID_RANGE Sharding method, so expect error in other sharding methods and success for DB_ID_RANGE
if (ShardingMethod.DB_ID_RANGE.toString().equalsIgnoreCase(getShardMethod()))
{
// This assertion replicates: testRangeCheckSharding, priority = 21, hence deleting that test as duplicate
Assert.assertNotEquals(expand, Integer.valueOf(-1), "Expansion is not successful when not using Shard DB_ID_RANGE method,");
}
else
{
Assert.assertEquals(expand, Integer.valueOf(-1), "Expansion should not have been allowed when not using Shard DB_ID_RANGE method,");
}
}
/**
@@ -500,7 +494,7 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest
* This test verifies expected result when using another deployment
* @throws Exception
*/
@Test(priority = 22)
@Test(priority = 22, groups = { TestGroup.CONFIG_SHARDING})
public void testExpand() throws Exception
{
String coreName = "alfresco";
@@ -509,29 +503,19 @@ public class SolrE2eAdminTest extends AbstractE2EFunctionalTest
RestResponse response = restClient.withParams("coreName=" + coreName, "add=" + add).withSolrAdminAPI().getAction("expand");
checkResponseStatusOk(response);
// This action only applies to DB_ID_RANGE Sharding method
Integer expand = response.getResponse().body().jsonPath().get("expand");
Assert.assertEquals(expand, Integer.valueOf(-1), "Expansion is not allowed when not using Shard DB_ID_RANGE method,");
}
/**
* When using DB_ID_RANGE Sharding method, expand param is including a number of nodes extended.
* @throws Exception
*/
@Test(priority = 23, groups = { TestGroup.ASS_SHARDING_DB_ID_RANGE })
public void testExpandSharding() throws Exception
{
String coreName = "alfresco";
String add = "1000";
RestResponse response = restClient.withParams("coreName=" + coreName, "add=" + add).withSolrAdminAPI().getAction("expand");
checkResponseStatusOk(response);
// This action only applies to DB_ID_RANGE Sharding method
Integer expand = response.getResponse().body().jsonPath().get("expand");
Assert.assertNotEquals(expand, Integer.valueOf(-1), "Expansion is a positive number when using Shard DB_ID_RANGE method,");
Integer expand = response.getResponse().body().jsonPath().get("expand");
// Expand action only applies to DB_ID_RANGE Sharding method, so expect error in other sharding methods and success for DB_ID_RANGE
if (ShardingMethod.DB_ID_RANGE.toString().equalsIgnoreCase(getShardMethod()))
{
// This assertion replicates: testExpandSharding, priority = 23, hence deleting that test as duplicate
Assert.assertNotEquals(expand, Integer.valueOf(-1), "Expansion is not successful when not using Shard DB_ID_RANGE method,");
}
else
{
Assert.assertEquals(expand, Integer.valueOf(-1), "Expansion should not have been allowed when not using Shard DB_ID_RANGE method,");
}
}
/**