Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GEODE-8140: scope field in gfsh create RR regions. #5126

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,17 @@ public class CliStrings {
public static final String CREATE_REGION__MSG__OBJECT_SIZER_MUST_BE_OBJECTSIZER_AND_DECLARABLE =
"eviction-object-sizer must implement both ObjectSizer and Declarable interfaces";

public static final String CREATE_REGION__SCOPE = "scope";

public static final String CREATE_REGION__SCOPE__HELP =
"Sets the scope of the region. Scope cannot be set for Partitioned regions";

public static final String CREATE_REGION__MSG__SCOPE_CANNOT_BE_SET_ON_PARTITION_REGION =
"Scope cannot be set on Partitioned region";

public static final String CREATE_REGION__SCOPE__SCOPE_CANNOT_BE_SET_IF_TYPE_NOT_SET =
"Scope cannot be used if --type is not set in the command";

/* debug command */
public static final String DEBUG = "debug";
public static final String DEBUG__HELP = "Enable/Disable debugging output in GFSH.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.geode.cache.configuration.ClassNameType;
import org.apache.geode.cache.configuration.DeclarableType;
import org.apache.geode.cache.configuration.EnumActionDestroyOverflow;
import org.apache.geode.cache.configuration.RegionAttributesScope;
import org.apache.geode.cache.configuration.RegionAttributesType;
import org.apache.geode.cache.configuration.RegionConfig;
import org.apache.geode.distributed.DistributedMember;
Expand Down Expand Up @@ -188,7 +189,9 @@ public ResultModel createRegion(
@CliOption(key = CliStrings.CREATE_REGION__TOTALNUMBUCKETS,
help = CliStrings.CREATE_REGION__TOTALNUMBUCKETS__HELP) Integer prTotalNumBuckets,
@CliOption(key = CliStrings.CREATE_REGION__VALUECONSTRAINT,
help = CliStrings.CREATE_REGION__VALUECONSTRAINT__HELP) String valueConstraint
help = CliStrings.CREATE_REGION__VALUECONSTRAINT__HELP) String valueConstraint,
@CliOption(key = CliStrings.CREATE_REGION__SCOPE,
help = CliStrings.CREATE_REGION__SCOPE__HELP) RegionAttributesScope scope
// NOTICE: keep the region attributes params in alphabetical order
) {
if (regionShortcut != null && templateRegion != null) {
Expand Down Expand Up @@ -227,9 +230,21 @@ public ResultModel createRegion(
regionConfig.setType(regionShortcut.name());
regionConfig.setRegionAttributes(
new RegionConverter().createRegionAttributesByType(regionShortcut.name()));
RegionAttributesType regionAttributesType = regionConfig.getRegionAttributes();
if (!regionShortcut.isReplicate()) {
return ResultModel
.createError(CliStrings.CREATE_REGION__MSG__SCOPE_CANNOT_BE_SET_ON_PARTITION_REGION);
} else {
regionAttributesType.setScope(scope);
}
}
// get the attributes from the template region
else {
// if not type is provided but a scope is mentioned
if (scope != null) {
return ResultModel
.createError(CliStrings.CREATE_REGION__SCOPE__SCOPE_CANNOT_BE_SET_IF_TYPE_NOT_SET);
}
List<RegionConfig> templateRegionConfigs = new ArrayList<>();
// get the potential template region config from the cluster configuration
if (persistenceService != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public ResultModel describeRegion(
if (regionDescription.isPartition()) {
regionDescription.getCndRegionAttributes().remove(RegionAttributesNames.SCOPE);
} else {
String scope = regionDescription.getCndRegionAttributes().get(RegionAttributesNames.SCOPE);
String scope = regionDescription.getScope().toString();
if (scope != null) {
scope = scope.toLowerCase().replace('_', '-');
regionDescription.getCndRegionAttributes().put(RegionAttributesNames.SCOPE, scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ private Region<Object, Object> createRegionGlobally(String regionPath) {
false,
true, null, null, null, null, null, null, null, null, null, null, null, null, null,
false,
null, null, null, null, null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null, null, null, null, null);

r = cache.getRegion(regionPath);
if (resultModel.getStatus() == Status.ERROR && r == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

import static org.assertj.core.api.Assertions.assertThat;

import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import junitparams.naming.TestCaseName;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;

import org.apache.geode.cache.Region;
import org.apache.geode.test.dunit.IgnoredException;
Expand All @@ -32,6 +36,7 @@
import org.apache.geode.test.junit.rules.serializable.SerializableTestName;

@Category({WanTest.class})
@RunWith(JUnitParamsRunner.class)
public class CreateRegionCommandDUnitTest {
private static MemberVM locator, server1, server2;

Expand All @@ -53,6 +58,63 @@ public void before() throws Exception {
gfsh.connectAndVerify(locator);
}

public Object[] replicatedRegionAndScopePairs() {
String[] replicatedRegions = {"REPLICATE", "REPLICATE_PERSISTENT", "REPLICATE_PROXY",
"REPLICATE_OVERFLOW", "REPLICATE_PERSISTENT_OVERFLOW", "REPLICATE_HEAP_LRU"};
String[] scopes = {"DISTRIBUTED_NO_ACK", "DISTRIBUTED_ACK", "LOCAL", "GLOBAL"};
Object[] pairs = new Object[replicatedRegions.length * scopes.length];
int count = 0;
for (String replicatedRegion : replicatedRegions) {
for (String scope : scopes) {
pairs[count] = new Object[] {replicatedRegion, scope};
count++;
}
}
return pairs;
}

public Object[] nonReplicatedRegionAndScopePairs() {
String[] scopes = {"DISTRIBUTED_NO_ACK", "DISTRIBUTED_ACK", "LOCAL", "GLOBAL"};
String[] nonReplicatedRegions =
{"PARTITION", "PARTITION_PERSISTENT", "PARTITION_PROXY", "PARTITION_REDUNDANT",
"PARTITION_REDUNDANT_PERSISTENT", "PARTITION_OVERFLOW", "PARTITION_REDUNDANT_OVERFLOW",
"PARTITION_PERSISTENT_OVERFLOW", "PARTITION_REDUNDANT_PERSISTENT_OVERFLOW",
"PARTITION_HEAP_LRU", "PARTITION_REDUNDANT_HEAP_LRU", "LOCAL", "LOCAL_PERSISTENT",
"LOCAL_HEAP_LRU", "LOCAL_OVERFLOW", "LOCAL_PERSISTENT_OVERFLOW"};
int count = 0;
Object[] pairs = new Object[scopes.length * nonReplicatedRegions.length];
for (String nonReplicatedRegion : nonReplicatedRegions) {
for (String scope : scopes) {
pairs[count] = new Object[] {nonReplicatedRegion, scope};
count++;
}
}
return pairs;
}

@Test
@TestCaseName("[{index}] {method}(RegionType:{0},Scope:{1})")
@Parameters(method = "replicatedRegionAndScopePairs")
public void createReplicateRegionCommandWithScopeSetsTheScope(String regionType, String scope) {
String regionName = testName.getMethodName();
gfsh.executeAndAssertThat(
"create region --type=" + regionType + " --scope=" + scope + " --name=" + regionName)
.statusIsSuccess();
String describeOutputScope = scope.replace("_", "-").toLowerCase();
gfsh.executeAndAssertThat("describe region --name=" + regionName).statusIsSuccess()
.containsOutput(describeOutputScope);
}

@Test
@TestCaseName("[{index}] {method}(RegionType:{0},Scope:{1})")
@Parameters(method = "nonReplicatedRegionAndScopePairs")
public void createNonReplicatedRegionCommandWithScopeShouldFail(String regionType, String scope) {
String regionName = testName.getMethodName();
gfsh.executeAndAssertThat(
"create region --type=" + regionType + " --scope=" + scope + " --name=" + regionName)
.statusIsError();
}

@Test
public void createReplicatedRegionWithParallelAsynchronousEventQueueShouldThrowExceptionAndPreventTheRegionFromBeingCreated() {
String regionName = testName.getMethodName();
Expand Down