From ea82ca94709adad2a2ab5b7e95f14f5d06c96ce2 Mon Sep 17 00:00:00 2001 From: Dawid Wysakowicz Date: Fri, 25 Feb 2022 09:05:40 +0100 Subject: [PATCH] [FLINK-26354] -restoreMode should be --restoreMode and should have a shorthand --- .../flink/client/cli/CliFrontendParser.java | 1 + .../flink/client/cli/CliFrontendRunTest.java | 59 ++++++++----------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java b/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java index ef202f69a9705..d9b23706e321a 100644 --- a/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java +++ b/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java @@ -134,6 +134,7 @@ public class CliFrontendParser { public static final Option SAVEPOINT_RESTORE_MODE = new Option( + "rm", "restoreMode", true, "Defines how should we restore from the given savepoint. Supported options: " diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendRunTest.java b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendRunTest.java index 2d10ad111e2f7..ea82cc9bc1f0d 100644 --- a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendRunTest.java +++ b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendRunTest.java @@ -133,50 +133,37 @@ public void testRun() throws Exception { @Test public void testClaimRestoreModeParsing() throws Exception { - // test configure savepoint with claim mode - String[] parameters = { - "-s", "expectedSavepointPath", "-n", "-restoreMode", "claim", getTestJarPath() - }; - - CommandLine commandLine = - CliFrontendParser.parse(CliFrontendParser.RUN_OPTIONS, parameters, true); - ProgramOptions programOptions = ProgramOptions.create(commandLine); - ExecutionConfigAccessor executionOptions = - ExecutionConfigAccessor.fromProgramOptions(programOptions, Collections.emptyList()); - - SavepointRestoreSettings savepointSettings = executionOptions.getSavepointRestoreSettings(); - assertTrue(savepointSettings.restoreSavepoint()); - assertEquals(RestoreMode.CLAIM, savepointSettings.getRestoreMode()); - assertEquals("expectedSavepointPath", savepointSettings.getRestorePath()); - assertTrue(savepointSettings.allowNonRestoredState()); + testRestoreMode("-rm", "claim", RestoreMode.CLAIM); } @Test public void testLegacyRestoreModeParsing() throws Exception { - // test configure savepoint with claim mode - String[] parameters = { - "-s", "expectedSavepointPath", "-n", "-restoreMode", "legacy", getTestJarPath() - }; + testRestoreMode("-rm", "legacy", RestoreMode.LEGACY); + } - CommandLine commandLine = - CliFrontendParser.parse(CliFrontendParser.RUN_OPTIONS, parameters, true); - ProgramOptions programOptions = ProgramOptions.create(commandLine); - ExecutionConfigAccessor executionOptions = - ExecutionConfigAccessor.fromProgramOptions(programOptions, Collections.emptyList()); + @Test + public void testNoClaimRestoreModeParsing() throws Exception { + testRestoreMode("-rm", "no_claim", RestoreMode.NO_CLAIM); + } - SavepointRestoreSettings savepointSettings = executionOptions.getSavepointRestoreSettings(); - assertTrue(savepointSettings.restoreSavepoint()); - assertEquals(RestoreMode.LEGACY, savepointSettings.getRestoreMode()); - assertEquals("expectedSavepointPath", savepointSettings.getRestorePath()); - assertTrue(savepointSettings.allowNonRestoredState()); + @Test + public void testClaimRestoreModeParsingLongOption() throws Exception { + testRestoreMode("--restoreMode", "claim", RestoreMode.CLAIM); } @Test - public void testNoClaimRestoreModeParsing() throws Exception { - // test configure savepoint with claim mode - String[] parameters = { - "-s", "expectedSavepointPath", "-n", "-restoreMode", "no_claim", getTestJarPath() - }; + public void testLegacyRestoreModeParsingLongOption() throws Exception { + testRestoreMode("--restoreMode", "legacy", RestoreMode.LEGACY); + } + + @Test + public void testNoClaimRestoreModeParsingLongOption() throws Exception { + testRestoreMode("--restoreMode", "no_claim", RestoreMode.NO_CLAIM); + } + + private void testRestoreMode(String flag, String arg, RestoreMode expectedMode) + throws Exception { + String[] parameters = {"-s", "expectedSavepointPath", "-n", flag, arg, getTestJarPath()}; CommandLine commandLine = CliFrontendParser.parse(CliFrontendParser.RUN_OPTIONS, parameters, true); @@ -186,7 +173,7 @@ public void testNoClaimRestoreModeParsing() throws Exception { SavepointRestoreSettings savepointSettings = executionOptions.getSavepointRestoreSettings(); assertTrue(savepointSettings.restoreSavepoint()); - assertEquals(RestoreMode.NO_CLAIM, savepointSettings.getRestoreMode()); + assertEquals(expectedMode, savepointSettings.getRestoreMode()); assertEquals("expectedSavepointPath", savepointSettings.getRestorePath()); assertTrue(savepointSettings.allowNonRestoredState()); }