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-6365: Add server group support for JDBC List Mapping and Destroy Mapping Commands #3228

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
Expand Up @@ -208,10 +208,6 @@ public void listsRegionMappingForServerGroup() throws Exception {
+ IdAndName.class.getName();
gfsh.executeAndAssertThat(mapping).statusIsSuccess();

CommandStringBuilder csbd = new CommandStringBuilder(
"describe jdbc-mapping --region=" + regionName + " --groups=" + TEST_GROUP1);
gfsh.executeAndAssertThat(csbd.toString());

CommandStringBuilder csb =
new CommandStringBuilder(LIST_MAPPING + " --groups=" + TEST_GROUP1);
CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
Expand Down Expand Up @@ -331,15 +327,80 @@ public void listsRegionMappingForMultiServerGroup() throws Exception {
@Test
public void reportsNoRegionMappingsFound() throws Exception {
locator = startupRule.startLocatorVM(0);
server1 = startupRule.startServerVM(1, locator.getPort());
server1 = startupRule.startServerVM(1, TEST_GROUP1, locator.getPort());
gfsh.connectAndVerify(locator);
gfsh.executeAndAssertThat("create region --name=" + regionName + " --type=REPLICATE")
gfsh.executeAndAssertThat(
"create data-source --name=connection --url=\"jdbc:derby:memory:newDB;create=true\"")
.statusIsSuccess();
gfsh.executeAndAssertThat(
"create region --name=" + regionName + " --groups=" + TEST_GROUP1 + " --type=REPLICATE")
.statusIsSuccess();
createTable();
try {
String mapping =
"create jdbc-mapping --region=" + regionName + " --groups=" + TEST_GROUP1
+ " --data-source=connection --schema=mySchema --table=myTable --pdx-name="
+ IdAndName.class.getName();
gfsh.executeAndAssertThat(mapping).statusIsSuccess();

CommandStringBuilder csb = new CommandStringBuilder(LIST_MAPPING);
CommandStringBuilder csb =
new CommandStringBuilder(LIST_MAPPING + " --groups=" + TEST_GROUP1);
CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());

commandResultAssert.statusIsSuccess();
commandResultAssert.tableHasRowCount(LIST_OF_MAPPINGS, 1);
commandResultAssert.tableHasColumnOnlyWithValues(LIST_OF_MAPPINGS, regionName);

csb = new CommandStringBuilder(LIST_MAPPING);
commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
commandResultAssert.statusIsSuccess();
commandResultAssert.tableHasRowCount(LIST_OF_MAPPINGS, 0);
} finally {
dropTable();
}
}

CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
commandResultAssert.statusIsSuccess();
commandResultAssert.containsOutput("No JDBC mappings found");
@Test
public void testDestroyRegionFailsWithExistingJdbcMapping() throws Exception {
locator = startupRule.startLocatorVM(0);
server1 = startupRule.startServerVM(1, TEST_GROUP1, locator.getPort());
server2 = startupRule.startServerVM(2, TEST_GROUP2, locator.getPort());

gfsh.connectAndVerify(locator);
gfsh.executeAndAssertThat(
"create data-source --name=connection --url=\"jdbc:derby:memory:newDB;create=true\"")
.statusIsSuccess();
gfsh.executeAndAssertThat(
"create region --name=" + GROUP1_REGION + " --groups=" + TEST_GROUP1 + " --type=REPLICATE")
.statusIsSuccess();
gfsh.executeAndAssertThat(
"create region --name=" + GROUP2_REGION + " --groups=" + TEST_GROUP2 + " --type=REPLICATE")
.statusIsSuccess();
createTable();
try {
String mapping =
"create jdbc-mapping --region=" + GROUP1_REGION + " --groups=" + TEST_GROUP1
+ " --data-source=connection --schema=mySchema --table=myTable --pdx-name="
+ IdAndName.class.getName();
gfsh.executeAndAssertThat(mapping).statusIsSuccess();

mapping =
"create jdbc-mapping --region=" + GROUP2_REGION + " --groups=" + TEST_GROUP2
+ " --data-source=connection --schema=mySchema --table=myTable --pdx-name="
+ IdAndName.class.getName();
gfsh.executeAndAssertThat(mapping).statusIsSuccess();

CommandStringBuilder csb = new CommandStringBuilder("destroy region --name=" + GROUP1_REGION);
gfsh.executeAndAssertThat(csb.toString()).statusIsError()
.containsOutput("Cannot destroy region \"" + GROUP1_REGION
+ "\" because JDBC mapping exists. Use \"destroy jdbc-mapping\" first.");

csb = new CommandStringBuilder("destroy region --name=" + GROUP2_REGION);
gfsh.executeAndAssertThat(csb.toString()).statusIsError()
.containsOutput("Cannot destroy region \"" + GROUP2_REGION
+ "\" because JDBC mapping exists. Use \"destroy jdbc-mapping\" first.");
} finally {
dropTable();
}
}
}
Expand Up @@ -102,18 +102,16 @@ void checkForJDBCMapping(String regionPath) {
groupNames.add("cluster");
for (String groupName : groupNames) {
CacheConfig cacheConfig = ccService.getCacheConfig(groupName);
if (cacheConfig == null) {
return;
}
RegionConfig regionConfig = CacheElement.findElement(cacheConfig.getRegions(), regionName);
if (regionConfig == null) {
return;
}
CacheElement element =
CacheElement.findElement(regionConfig.getCustomRegionElements(), "jdbc-mapping");
if (element != null) {
throw new IllegalStateException("Cannot destroy region \"" + regionName
+ "\" because JDBC mapping exists. Use \"destroy jdbc-mapping\" first.");
if (cacheConfig != null) {
RegionConfig regionConfig = CacheElement.findElement(cacheConfig.getRegions(), regionName);
if (regionConfig != null) {
CacheElement element =
CacheElement.findElement(regionConfig.getCustomRegionElements(), "jdbc-mapping");
if (element != null) {
throw new IllegalStateException("Cannot destroy region \"" + regionName
+ "\" because JDBC mapping exists. Use \"destroy jdbc-mapping\" first.");
}
}
}
}
}
Expand Down