This is an automated email from the ASF dual-hosted git repository. khowe pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode.git
commit 54b18eded8802561b8607b4bcdc1525915436e85 Author: Juan Jose Ramos Cassella <jujora...@gmail.com> AuthorDate: Wed Mar 14 09:14:25 2018 +0000 GEODE-4771: Changes requested by reviewers. --- .../internal/cli/commands/ConfigurePDXCommand.java | 118 ++++++++++----------- .../ConfigurePDXCommandIntegrationTest.java | 17 +-- .../cli/commands/ConfigurePDXCommandTest.java | 59 ++++++----- 3 files changed, 97 insertions(+), 97 deletions(-) diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommand.java index 43719f9..1868c15 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommand.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommand.java @@ -90,75 +90,68 @@ public class ConfigurePDXCommand extends GfshCommand { help = CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES__HELP) String[] portableClassesPatterns) { Result result; + ReflectionBasedAutoSerializer autoSerializer; + CacheCreation cache = getCacheCreation(true); + InfoResultData ird = ResultBuilder.createInfoResultData(); - try { - ReflectionBasedAutoSerializer autoSerializer; - CacheCreation cache = getCacheCreation(true); - InfoResultData ird = ResultBuilder.createInfoResultData(); + if (!getAllNormalMembers().isEmpty()) { + ird.addLine(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING); + } - if (!getAllNormalMembers().isEmpty()) { - ird.addLine(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING); - } + // Set persistent and the disk-store + if (diskStore != null) { + cache.setPdxPersistent(true); + ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent()); - // Set persistent and the disk-store - if (diskStore != null) { - cache.setPdxPersistent(true); - ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent()); - - if (!diskStore.equals("")) { - cache.setPdxDiskStore(diskStore); - ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + cache.getPdxDiskStore()); - } else { - ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + "DEFAULT"); - } + if (!diskStore.equals("")) { + cache.setPdxDiskStore(diskStore); + ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + cache.getPdxDiskStore()); } else { - cache.setPdxPersistent(CacheConfig.DEFAULT_PDX_PERSISTENT); - ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent()); - } - - // Set read-serialized - if (readSerialized != null) { - cache.setPdxReadSerialized(readSerialized); - } else { - cache.setPdxReadSerialized(CacheConfig.DEFAULT_PDX_READ_SERIALIZED); + ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + "DEFAULT"); } + } else { + cache.setPdxPersistent(CacheConfig.DEFAULT_PDX_PERSISTENT); + ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent()); + } - ird.addLine( - CliStrings.CONFIGURE_PDX__READ__SERIALIZED + " = " + cache.getPdxReadSerialized()); + // Set read-serialized + if (readSerialized != null) { + cache.setPdxReadSerialized(readSerialized); + } else { + cache.setPdxReadSerialized(CacheConfig.DEFAULT_PDX_READ_SERIALIZED); + } - // Set ignoreUnreadFields - if (ignoreUnreadFields != null) { - cache.setPdxIgnoreUnreadFields(ignoreUnreadFields); - } else { - cache.setPdxIgnoreUnreadFields(CacheConfig.DEFAULT_PDX_IGNORE_UNREAD_FIELDS); - } + ird.addLine(CliStrings.CONFIGURE_PDX__READ__SERIALIZED + " = " + cache.getPdxReadSerialized()); - ird.addLine(CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS + " = " - + cache.getPdxIgnoreUnreadFields()); + // Set ignoreUnreadFields + if (ignoreUnreadFields != null) { + cache.setPdxIgnoreUnreadFields(ignoreUnreadFields); + } else { + cache.setPdxIgnoreUnreadFields(CacheConfig.DEFAULT_PDX_IGNORE_UNREAD_FIELDS); + } - // Auto Serializer Configuration - if (portableClassesPatterns != null) { - autoSerializer = createReflectionBasedAutoSerializer(true, portableClassesPatterns); - cache.setPdxSerializer(autoSerializer); - ird.addLine("PDX Serializer = " + cache.getPdxSerializer().getClass().getName()); - ird.addLine("Portable Classes = " + Arrays.toString(portableClassesPatterns)); - } + ird.addLine( + CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS + " = " + cache.getPdxIgnoreUnreadFields()); - if (nonPortableClassesPatterns != null) { - autoSerializer = createReflectionBasedAutoSerializer(false, nonPortableClassesPatterns); - cache.setPdxSerializer(autoSerializer); - ird.addLine("PDX Serializer = " + cache.getPdxSerializer().getClass().getName()); - ird.addLine("Non Portable Classes = " + Arrays.toString(nonPortableClassesPatterns)); - } + // Auto Serializer Configuration + if (portableClassesPatterns != null) { + autoSerializer = createReflectionBasedAutoSerializer(true, portableClassesPatterns); + cache.setPdxSerializer(autoSerializer); + ird.addLine("PDX Serializer = " + cache.getPdxSerializer().getClass().getName()); + ird.addLine("Portable Classes = " + Arrays.toString(portableClassesPatterns)); + } - XmlEntity xmlEntity = createXmlEntity(cache); - result = ResultBuilder.buildResult(ird); - persistClusterConfiguration(result, - () -> getSharedConfiguration().addXmlEntity(xmlEntity, null)); - } catch (Exception e) { - return ResultBuilder.createGemFireErrorResult(e.getMessage()); + if (nonPortableClassesPatterns != null) { + autoSerializer = createReflectionBasedAutoSerializer(false, nonPortableClassesPatterns); + cache.setPdxSerializer(autoSerializer); + ird.addLine("PDX Serializer = " + cache.getPdxSerializer().getClass().getName()); + ird.addLine("Non Portable Classes = " + Arrays.toString(nonPortableClassesPatterns)); } + XmlEntity xmlEntity = createXmlEntity(cache); + result = ResultBuilder.buildResult(ird); + persistClusterConfiguration(result, + () -> getSharedConfiguration().addXmlEntity(xmlEntity, null)); return result; } @@ -169,14 +162,13 @@ public class ConfigurePDXCommand extends GfshCommand { @Override public Result preExecution(GfshParseResult parseResult) { - Object portableClassesPatterns = - parseResult.getParamValue(CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES); - Object nonPortableClassesPatterns = - parseResult.getParamValue(CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES); - - if ((nonPortableClassesPatterns != null && ((String[]) nonPortableClassesPatterns).length > 0) - && (portableClassesPatterns != null && ((String[]) portableClassesPatterns).length > 0)) { + String[] portableClassesPatterns = (String[]) parseResult + .getParamValue(CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES); + String[] nonPortableClassesPatterns = + (String[]) parseResult.getParamValue(CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES); + if ((nonPortableClassesPatterns != null && nonPortableClassesPatterns.length > 0) + && (portableClassesPatterns != null && portableClassesPatterns.length > 0)) { return ResultBuilder.createUserErrorResult(CliStrings.CONFIGURE_PDX__ERROR__MESSAGE); } diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommandIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommandIntegrationTest.java index b1288b0..d5f56c8 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommandIntegrationTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommandIntegrationTest.java @@ -42,12 +42,6 @@ public class ConfigurePDXCommandIntegrationTest { } @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", @@ -55,6 +49,17 @@ public class ConfigurePDXCommandIntegrationTest { } @Test + @Ignore("See https://issues.apache.org/jira/browse/GEODE-4794") + public void commandShouldSucceedWhenUsingDefaults() { + gfsh.executeAndAssertThat(BASE_COMMAND_STRING).statusIsSuccess().hasNoFailToPersistError(); + + String sharedConfigXml = locator.getLocator().getSharedConfiguration() + .getConfiguration("cluster").getCacheXmlContent(); + assertThat(sharedConfigXml).contains( + "<pdx ignore-unread-fields=\"false\" persistent=\"false\" read-serialized=\"false\"></pdx>"); + } + + @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") diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommandTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommandTest.java index bfd5a61..9a4d87d 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommandTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommandTest.java @@ -96,17 +96,20 @@ public class ConfigurePDXCommandTest { doThrow(new RuntimeException("Can't create CacheCreation.")).when(command) .getCacheCreation(anyBoolean()); gfshParserRule.executeAndAssertThat(command, BASE_COMMAND_STRING).statusIsError() - .containsOutput("Could not process command due to error. Can't create CacheCreation."); + .containsOutput("Could not process command due to error.") + .containsOutput("Can't create CacheCreation."); doReturn(cacheCreation).when(command).getCacheCreation(anyBoolean()); doThrow(new RuntimeException("Can't find members.")).when(command).getAllNormalMembers(); gfshParserRule.executeAndAssertThat(command, BASE_COMMAND_STRING).statusIsError() - .containsOutput("Could not process command due to error. Can't find members."); + .containsOutput("Could not process command due to error.") + .containsOutput("Can't find members."); doReturn(Collections.emptySet()).when(command).getAllNormalMembers(); doThrow(new RuntimeException("Can't create XmlEntity.")).when(command).createXmlEntity(any()); gfshParserRule.executeAndAssertThat(command, BASE_COMMAND_STRING).statusIsError() - .containsOutput("Could not process command due to error. Can't create XmlEntity."); + .containsOutput("Could not process command due to error.") + .containsOutput("Can't create XmlEntity."); doReturn(xmlEntity).when(command).createXmlEntity(any()); doThrow(new RuntimeException("Can't create ReflectionBasedAutoSerializer.")).when(command) @@ -114,13 +117,13 @@ public class ConfigurePDXCommandTest { gfshParserRule .executeAndAssertThat(command, BASE_COMMAND_STRING + "--auto-serializable-classes=" + new String[] {}) - .statusIsError().containsOutput( - "Could not process command due to error. Can't create ReflectionBasedAutoSerializer."); + .statusIsError().containsOutput("Could not process command due to error.") + .containsOutput("Can't create ReflectionBasedAutoSerializer."); gfshParserRule .executeAndAssertThat(command, BASE_COMMAND_STRING + "--portable-auto-serializable-classes=" + new String[] {}) - .statusIsError().containsOutput( - "Could not process command due to error. Can't create ReflectionBasedAutoSerializer."); + .statusIsError().containsOutput("Could not process command due to error.") + .containsOutput("Can't create ReflectionBasedAutoSerializer."); verify(command, times(0)).persistClusterConfiguration(any(), any()); } @@ -165,7 +168,7 @@ public class ConfigurePDXCommandTest { .statusIsSuccess().hasNoFailToPersistError() .hasReadSerializedConfigured(DEFAULT_PDX_READ_SERIALIZED, cacheCreation) .hasIgnoreUnreadFieldsConfigured(DEFAULT_PDX_IGNORE_UNREAD_FIELDS, cacheCreation) - .hasPersistenseConfigured(true, "DEFAULT", cacheCreation); + .hasPersistenceConfigured(true, "DEFAULT", cacheCreation); verify(cacheCreation, times(0)).setPdxSerializer(any()); verify(command, times(1)).persistClusterConfiguration(any(), any()); @@ -179,7 +182,7 @@ public class ConfigurePDXCommandTest { .statusIsSuccess().hasNoFailToPersistError() .hasReadSerializedConfigured(DEFAULT_PDX_READ_SERIALIZED, cacheCreation) .hasIgnoreUnreadFieldsConfigured(DEFAULT_PDX_IGNORE_UNREAD_FIELDS, cacheCreation) - .hasPersistenseConfigured(true, "myDiskStore", cacheCreation); + .hasPersistenceConfigured(true, "myDiskStore", cacheCreation); verify(cacheCreation, times(0)).setPdxSerializer(any()); verify(command, times(1)).persistClusterConfiguration(any(), any()); @@ -193,7 +196,7 @@ public class ConfigurePDXCommandTest { .statusIsSuccess().hasNoFailToPersistError() .hasReadSerializedConfigured(true, cacheCreation) .hasIgnoreUnreadFieldsConfigured(DEFAULT_PDX_IGNORE_UNREAD_FIELDS, cacheCreation) - .hasPersistenseConfigured(DEFAULT_PDX_PERSISTENT, null, cacheCreation); + .hasPersistenceConfigured(DEFAULT_PDX_PERSISTENT, null, cacheCreation); verify(cacheCreation, times(0)).setPdxSerializer(any()); verify(command, times(1)).persistClusterConfiguration(any(), any()); @@ -207,7 +210,7 @@ public class ConfigurePDXCommandTest { .statusIsSuccess().hasNoFailToPersistError() .hasReadSerializedConfigured(false, cacheCreation) .hasIgnoreUnreadFieldsConfigured(DEFAULT_PDX_IGNORE_UNREAD_FIELDS, cacheCreation) - .hasPersistenseConfigured(DEFAULT_PDX_PERSISTENT, null, cacheCreation); + .hasPersistenceConfigured(DEFAULT_PDX_PERSISTENT, null, cacheCreation); verify(cacheCreation, times(0)).setPdxSerializer(any()); verify(command, times(1)).persistClusterConfiguration(any(), any()); @@ -222,7 +225,7 @@ public class ConfigurePDXCommandTest { .statusIsSuccess().hasNoFailToPersistError() .hasReadSerializedConfigured(DEFAULT_PDX_READ_SERIALIZED, cacheCreation) .hasIgnoreUnreadFieldsConfigured(true, cacheCreation) - .hasPersistenseConfigured(DEFAULT_PDX_PERSISTENT, null, cacheCreation); + .hasPersistenceConfigured(DEFAULT_PDX_PERSISTENT, null, cacheCreation); verify(cacheCreation, times(0)).setPdxSerializer(any()); verify(command, times(1)).persistClusterConfiguration(any(), any()); @@ -237,7 +240,7 @@ public class ConfigurePDXCommandTest { .statusIsSuccess().hasNoFailToPersistError() .hasReadSerializedConfigured(DEFAULT_PDX_READ_SERIALIZED, cacheCreation) .hasIgnoreUnreadFieldsConfigured(false, cacheCreation) - .hasPersistenseConfigured(DEFAULT_PDX_PERSISTENT, null, cacheCreation); + .hasPersistenceConfigured(DEFAULT_PDX_PERSISTENT, null, cacheCreation); verify(cacheCreation, times(0)).setPdxSerializer(any()); verify(command, times(1)).persistClusterConfiguration(any(), any()); @@ -255,7 +258,7 @@ public class ConfigurePDXCommandTest { .statusIsSuccess().hasNoFailToPersistError() .hasReadSerializedConfigured(DEFAULT_PDX_READ_SERIALIZED, cacheCreation) .hasIgnoreUnreadFieldsConfigured(DEFAULT_PDX_IGNORE_UNREAD_FIELDS, cacheCreation) - .hasPersistenseConfigured(DEFAULT_PDX_PERSISTENT, null, cacheCreation) + .hasPersistenceConfigured(DEFAULT_PDX_PERSISTENT, null, cacheCreation) .containsOutput("Portable Classes = [com.company.DomainObject.*#identity=id]") .containsOutput("PDX Serializer = org.apache.geode.pdx.ReflectionBasedAutoSerializer"); @@ -276,7 +279,7 @@ public class ConfigurePDXCommandTest { .hasReadSerializedConfigured(CacheConfig.DEFAULT_PDX_READ_SERIALIZED, cacheCreation) .hasIgnoreUnreadFieldsConfigured(CacheConfig.DEFAULT_PDX_IGNORE_UNREAD_FIELDS, cacheCreation) - .hasPersistenseConfigured(CacheConfig.DEFAULT_PDX_PERSISTENT, null, cacheCreation) + .hasPersistenceConfigured(CacheConfig.DEFAULT_PDX_PERSISTENT, null, cacheCreation) .containsOutput("Non Portable Classes = [com.company.DomainObject.*#identity=id]") .containsOutput("PDX Serializer = org.apache.geode.pdx.ReflectionBasedAutoSerializer"); @@ -287,47 +290,47 @@ public class ConfigurePDXCommandTest { static class CustomGfshParserRule extends GfshParserRule { @Override - public <T> CustomResultAssert executeAndAssertThat(T instance, String command) { + public <T> PDXCommandResultAssert executeAndAssertThat(T instance, String command) { CommandResultAssert resultAssert = super.executeAndAssertThat(instance, command);; - return new CustomResultAssert(resultAssert.getCommandResult()); + return new PDXCommandResultAssert(resultAssert.getCommandResult()); } } - static class CustomResultAssert extends CommandResultAssert { - public CustomResultAssert(CommandResult commandResult) { + static class PDXCommandResultAssert extends CommandResultAssert { + public PDXCommandResultAssert(CommandResult commandResult) { super(commandResult); } @Override - public CustomResultAssert statusIsError() { + public PDXCommandResultAssert statusIsError() { super.statusIsError(); return this; } @Override - public CustomResultAssert statusIsSuccess() { + public PDXCommandResultAssert statusIsSuccess() { super.statusIsSuccess(); return this; } @Override - public CustomResultAssert containsOutput(String... expectedOutputs) { + public PDXCommandResultAssert containsOutput(String... expectedOutputs) { super.containsOutput(expectedOutputs); return this; } @Override - public CustomResultAssert hasNoFailToPersistError() { + public PDXCommandResultAssert hasNoFailToPersistError() { super.hasNoFailToPersistError(); return this; } - public CustomResultAssert hasPersistenseConfigured(boolean persistenceEnabled, + public PDXCommandResultAssert hasPersistenceConfigured(boolean persistenceEnabled, String diskStoreName, CacheCreation cache) { assertThat(actual.getOutput()).contains("persistent = " + persistenceEnabled); @@ -345,7 +348,7 @@ public class ConfigurePDXCommandTest { } - public CustomResultAssert hasReadSerializedConfigured(boolean readSerializedEnabled, + public PDXCommandResultAssert hasReadSerializedConfigured(boolean readSerializedEnabled, CacheCreation cache) { assertThat(actual.getOutput()).contains("read-serialized = " + readSerializedEnabled); verify(cache, times(1)).setPdxReadSerialized(readSerializedEnabled); @@ -353,7 +356,7 @@ public class ConfigurePDXCommandTest { return this; } - public CustomResultAssert hasIgnoreUnreadFieldsConfigured(boolean ignoreUnreadFieldsEnabled, + public PDXCommandResultAssert hasIgnoreUnreadFieldsConfigured(boolean ignoreUnreadFieldsEnabled, CacheCreation cache) { assertThat(actual.getOutput()) .contains("ignore-unread-fields = " + ignoreUnreadFieldsEnabled); @@ -362,12 +365,12 @@ public class ConfigurePDXCommandTest { return this; } - public CustomResultAssert hasDefaultsConfigured(ConfigurePDXCommand command, + public PDXCommandResultAssert hasDefaultsConfigured(ConfigurePDXCommand command, CacheCreation cacheCreation) { hasNoFailToPersistError(); hasReadSerializedConfigured(DEFAULT_PDX_READ_SERIALIZED, cacheCreation); hasIgnoreUnreadFieldsConfigured(DEFAULT_PDX_IGNORE_UNREAD_FIELDS, cacheCreation); - hasPersistenseConfigured(DEFAULT_PDX_PERSISTENT, null, cacheCreation); + hasPersistenceConfigured(DEFAULT_PDX_PERSISTENT, null, cacheCreation); verify(cacheCreation, times(0)).setPdxSerializer(any()); verify(command, times(1)).persistClusterConfiguration(any(), any()); -- To stop receiving notification emails like this one, please contact kh...@apache.org.