forked from apache/geode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-2764: Addition checks on region name
* If a region name contains function calls like entrySet() * The from clause is substring-ed at '.' from the right * Each substing is checked to see if the region name is valid. This closes apache#449
- Loading branch information
1 parent
ed300c5
commit 0714c27
Showing
2 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...e/management/internal/configuration/ClusterConfigurationIndexWithFromClauseDUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||
* agreements. See the NOTICE file distributed with this work for additional information regarding | ||
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. You may obtain a | ||
* copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package org.apache.geode.management.internal.configuration; | ||
|
||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.apache.geode.cache.RegionShortcut; | ||
import org.apache.geode.management.cli.Result; | ||
import org.apache.geode.management.internal.cli.i18n.CliStrings; | ||
import org.apache.geode.management.internal.cli.result.CommandResult; | ||
import org.apache.geode.management.internal.cli.util.CommandStringBuilder; | ||
import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; | ||
import org.apache.geode.test.dunit.rules.LocatorServerStartupRule; | ||
import org.apache.geode.test.dunit.rules.MemberVM; | ||
import org.apache.geode.test.junit.categories.DistributedTest; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.util.Properties; | ||
import junitparams.JUnitParamsRunner; | ||
import junitparams.Parameters; | ||
|
||
@Category(DistributedTest.class) | ||
@RunWith(JUnitParamsRunner.class) | ||
public class ClusterConfigurationIndexWithFromClauseDUnitTest { | ||
|
||
final String REGION_NAME = "region"; | ||
final String INDEX_NAME = "index"; | ||
|
||
protected RegionShortcut[] getRegionTypes() { | ||
return new RegionShortcut[] {RegionShortcut.PARTITION, RegionShortcut.PARTITION_PERSISTENT, | ||
RegionShortcut.PARTITION_REDUNDANT, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT, | ||
RegionShortcut.REPLICATE, RegionShortcut.REPLICATE_PERSISTENT}; | ||
|
||
} | ||
|
||
@Rule | ||
public LocatorServerStartupRule lsRule = new LocatorServerStartupRule(); | ||
|
||
@Rule | ||
public GfshShellConnectionRule gfshShellConnectionRule = new GfshShellConnectionRule(); | ||
|
||
private MemberVM locator = null; | ||
|
||
@Before | ||
public void before() throws Exception { | ||
locator = lsRule.startLocatorVM(0); | ||
} | ||
|
||
@Test | ||
@Parameters(method = "getRegionTypes") | ||
public void indexCreatedWithEntrySetInFromClauseMustPersist(RegionShortcut regionShortcut) | ||
throws Exception { | ||
MemberVM vm1 = lsRule.startServerVM(1, locator.getPort()); | ||
gfshShellConnectionRule.connectAndVerify(locator); | ||
createRegionUsingGfsh(REGION_NAME, regionShortcut, null); | ||
createIndexUsingGfsh("\"" + REGION_NAME + ".entrySet() z\"", "z.key", INDEX_NAME); | ||
String serverName = vm1.getName(); | ||
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.LIST_MEMBER); | ||
gfshShellConnectionRule.executeAndVerifyCommand(csb.toString()); | ||
lsRule.stopMember(1); | ||
lsRule.startServerVM(1, lsRule.getMember(0).getPort());; | ||
verifyIndexRecreated(INDEX_NAME); | ||
} | ||
|
||
private void verifyIndexRecreated(String indexName) throws Exception { | ||
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.LIST_INDEX); | ||
CommandResult commandResult = gfshShellConnectionRule.executeAndVerifyCommand(csb.toString()); | ||
String resultAsString = commandResultToString(commandResult); | ||
assertEquals(Result.Status.OK, commandResult.getStatus()); | ||
assertTrue(resultAsString.contains(indexName)); | ||
} | ||
|
||
private String commandResultToString(final CommandResult commandResult) { | ||
assertNotNull(commandResult); | ||
commandResult.resetToFirstLine(); | ||
StringBuilder buffer = new StringBuilder(commandResult.getHeader()); | ||
while (commandResult.hasNextLine()) { | ||
buffer.append(commandResult.nextLine()); | ||
} | ||
buffer.append(commandResult.getFooter()); | ||
return buffer.toString(); | ||
} | ||
|
||
private void createIndexUsingGfsh(String regionName, String expression, String indexName) | ||
throws Exception { | ||
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_INDEX); | ||
csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, expression); | ||
csb.addOption(CliStrings.CREATE_INDEX__REGION, regionName); | ||
csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName); | ||
gfshShellConnectionRule.executeAndVerifyCommand(csb.toString()); | ||
} | ||
|
||
private void createRegionUsingGfsh(String regionName, RegionShortcut regionShortCut, String group) | ||
throws Exception { | ||
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_REGION); | ||
csb.addOption(CliStrings.CREATE_REGION__REGION, regionName); | ||
csb.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, regionShortCut.name()); | ||
csb.addOptionWithValueCheck(CliStrings.CREATE_REGION__GROUP, group); | ||
gfshShellConnectionRule.executeAndVerifyCommand(csb.toString()); | ||
} | ||
} |