Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-4771: Defaults in ConfigurePDXCommand
- Refactored `ConfigurePDXCommand` to allow unit testing. - Added a custom `Interceptor` to validate command input. - Added unit and integration tests for `ConfigurePDXCommand`. - Fixed help strings for `auto-serializable-classes` and `portable-auto-serializable-classes`. - Fixed `ConfigurePDXCommand` to set `check-portability=false` when `--auto-serializable-classes` is used.
- Loading branch information
Showing
4 changed files
with
592 additions
and
33 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
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
130 changes: 130 additions & 0 deletions
130
...org/apache/geode/management/internal/cli/commands/ConfigurePDXCommandIntegrationTest.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,130 @@ | ||
/* | ||
* 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.cli.commands; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
import org.apache.geode.test.junit.categories.IntegrationTest; | ||
import org.apache.geode.test.junit.rules.GfshCommandRule; | ||
import org.apache.geode.test.junit.rules.LocatorStarterRule; | ||
|
||
@Category(IntegrationTest.class) | ||
public class ConfigurePDXCommandIntegrationTest { | ||
private static final String BASE_COMMAND_STRING = "configure pdx "; | ||
|
||
@Rule | ||
public GfshCommandRule gfsh = new GfshCommandRule().withTimeout(1); | ||
|
||
@Rule | ||
public LocatorStarterRule locator = new LocatorStarterRule().withAutoStart().withJMXManager(); | ||
|
||
@Before | ||
public void before() throws Exception { | ||
gfsh.connectAndVerify(locator); | ||
} | ||
|
||
@Test | ||
@Ignore("See https://issues.apache.org/jira/browse/GEODE-4794") | ||
public void commandShouldSucceedWhenUsingDefaults() { | ||
gfsh.executeAndAssertThat(BASE_COMMAND_STRING).statusIsSuccess().hasNoFailToPersistError(); | ||
} | ||
|
||
@Test | ||
public void commandShouldFailWhenNotConnected() throws Exception { | ||
gfsh.disconnect(); | ||
gfsh.executeAndAssertThat(BASE_COMMAND_STRING).statusIsError().containsOutput("Command", | ||
"was found but is not currently available"); | ||
} | ||
|
||
@Test | ||
public void commandShouldSucceedWhenConfiguringAutoSerializableClassesWithPersistence() { | ||
gfsh.executeAndAssertThat(BASE_COMMAND_STRING | ||
+ "--read-serialized=true --disk-store=myDiskStore --ignore-unread-fields=true --auto-serializable-classes=com.company.DomainObject.*#identity=id") | ||
.statusIsSuccess().hasNoFailToPersistError(); | ||
|
||
String sharedConfigXml = locator.getLocator().getSharedConfiguration() | ||
.getConfiguration("cluster").getCacheXmlContent(); | ||
assertThat(sharedConfigXml).contains( | ||
"<pdx disk-store-name=\"myDiskStore\" ignore-unread-fields=\"true\" persistent=\"true\" read-serialized=\"true\">"); | ||
assertThat(sharedConfigXml).contains("<pdx-serializer>", | ||
"<class-name>org.apache.geode.pdx.ReflectionBasedAutoSerializer</class-name>", | ||
"<parameter name=\"classes\">", | ||
"<string>com.company.DomainObject.*, com.company.DomainObject.*#identity=id</string>", | ||
"</parameter>", "</pdx-serializer>"); | ||
assertThat(sharedConfigXml).contains("</pdx>"); | ||
} | ||
|
||
@Test | ||
public void commandShouldSucceedWhenConfiguringAutoSerializableClassesWithoutPersistence() { | ||
gfsh.executeAndAssertThat(BASE_COMMAND_STRING | ||
+ "--read-serialized=false --ignore-unread-fields=false --auto-serializable-classes=com.company.DomainObject.*#identity=id") | ||
.statusIsSuccess().hasNoFailToPersistError(); | ||
|
||
String sharedConfigXml = locator.getLocator().getSharedConfiguration() | ||
.getConfiguration("cluster").getCacheXmlContent(); | ||
assertThat(sharedConfigXml).contains("<pdx>"); | ||
assertThat(sharedConfigXml).contains("<pdx-serializer>", | ||
"<class-name>org.apache.geode.pdx.ReflectionBasedAutoSerializer</class-name>", | ||
"<parameter name=\"classes\">", | ||
"<string>com.company.DomainObject.*, com.company.DomainObject.*#identity=id</string>", | ||
"</parameter>", "</pdx-serializer>"); | ||
assertThat(sharedConfigXml).contains("</pdx>"); | ||
} | ||
|
||
@Test | ||
public void commandShouldSucceedWhenConfiguringPortableAutoSerializableClassesWithPersistence() { | ||
gfsh.executeAndAssertThat(BASE_COMMAND_STRING | ||
+ "--read-serialized=true --disk-store=myDiskStore --ignore-unread-fields=true --portable-auto-serializable-classes=com.company.DomainObject.*#identity=id") | ||
.statusIsSuccess().hasNoFailToPersistError(); | ||
|
||
String sharedConfigXml = locator.getLocator().getSharedConfiguration() | ||
.getConfiguration("cluster").getCacheXmlContent(); | ||
assertThat(sharedConfigXml).contains( | ||
"<pdx disk-store-name=\"myDiskStore\" ignore-unread-fields=\"true\" persistent=\"true\" read-serialized=\"true\">"); | ||
assertThat(sharedConfigXml).contains("<parameter name=\"check-portability\">") | ||
.contains("<string>true</string>").contains("</parameter>"); | ||
assertThat(sharedConfigXml).contains("<pdx-serializer>", | ||
"<class-name>org.apache.geode.pdx.ReflectionBasedAutoSerializer</class-name>", | ||
"<parameter name=\"classes\">", | ||
"<string>com.company.DomainObject.*, com.company.DomainObject.*#identity=id</string>", | ||
"</parameter>", "</pdx-serializer>"); | ||
assertThat(sharedConfigXml).contains("</pdx>"); | ||
} | ||
|
||
@Test | ||
public void commandShouldSucceedWhenConfiguringPortableAutoSerializableClassesWithoutPersistence() { | ||
gfsh.executeAndAssertThat(BASE_COMMAND_STRING | ||
+ "--read-serialized=false --ignore-unread-fields=false --portable-auto-serializable-classes=com.company.DomainObject.*#identity=id") | ||
.statusIsSuccess().hasNoFailToPersistError(); | ||
|
||
String sharedConfigXml = locator.getLocator().getSharedConfiguration() | ||
.getConfiguration("cluster").getCacheXmlContent(); | ||
assertThat(sharedConfigXml).contains("<pdx>"); | ||
assertThat(sharedConfigXml).contains("<parameter name=\"check-portability\">") | ||
.contains("<string>true</string>").contains("</parameter>"); | ||
assertThat(sharedConfigXml).contains("<pdx-serializer>", | ||
"<class-name>org.apache.geode.pdx.ReflectionBasedAutoSerializer</class-name>", | ||
"<parameter name=\"classes\">", | ||
"<string>com.company.DomainObject.*, com.company.DomainObject.*#identity=id</string>", | ||
"</parameter>", "</pdx-serializer>"); | ||
assertThat(sharedConfigXml).contains("</pdx>"); | ||
} | ||
} |
Oops, something went wrong.