Skip to content

Commit f2970c6

Browse files
Deprecate --log-success argument and introduce new replacement option --enable-log-success (#3117)
Co-authored-by: Peckstadt Yves <[email protected]>
1 parent 9d6dc1f commit f2970c6

File tree

3 files changed

+106
-3
lines changed

3 files changed

+106
-3
lines changed

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataimport/ImportCommand.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ private void validateDeprecatedOptions() {
286286
DEPRECATED_THREADS_OPTION,
287287
MAX_THREADS_OPTION,
288288
MAX_THREADS_OPTION_SHORT);
289+
validateDeprecatedOptionPair(
290+
spec.commandLine(),
291+
DEPRECATED_LOG_SUCCESS_RECORDS_OPTION,
292+
ENABLE_LOG_SUCCESS_RECORDS_OPTION,
293+
ENABLE_LOG_SUCCESS_RECORDS_OPTION_SHORT);
289294
}
290295

291296
/**
@@ -303,7 +308,7 @@ private ImportOptions createImportOptions(ControlFile controlFile) {
303308
.controlFile(controlFile)
304309
.controlFileValidationLevel(controlFileValidation)
305310
.logRawRecord(logRawRecord)
306-
.logSuccessRecords(logSuccessRecords)
311+
.logSuccessRecords(enableLogSuccessRecords)
307312
.ignoreNullValues(ignoreNullValues)
308313
.namespace(namespace)
309314
.dataChunkSize(dataChunkSize)

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataimport/ImportCommandOptions.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ public class ImportCommandOptions {
1313
public static final String MAX_THREADS_OPTION_SHORT = "-mt";
1414
public static final String DEPRECATED_THREADS_OPTION = "--threads";
1515

16+
public static final String ENABLE_LOG_SUCCESS_RECORDS_OPTION = "--enable-log-success";
17+
public static final String ENABLE_LOG_SUCCESS_RECORDS_OPTION_SHORT = "-ls";
18+
public static final String DEPRECATED_LOG_SUCCESS_RECORDS_OPTION = "--log-success";
19+
1620
@CommandLine.Option(
1721
names = {"--mode", "-m"},
1822
description = "ScalarDB mode (STORAGE, TRANSACTION) (default: STORAGE)",
@@ -69,11 +73,22 @@ public class ImportCommandOptions {
6973
description = "Path to the JSON control file for data mapping")
7074
protected String controlFilePath;
7175

76+
/**
77+
* @deprecated As of release 3.6.2. Will be removed in release 4.0.0. Use --enable-log-success
78+
* instead
79+
*/
80+
@Deprecated
81+
@CommandLine.Option(
82+
names = {"--log-success"},
83+
description = "Deprecated: Use --enable-log-success",
84+
hidden = true)
85+
protected boolean logSuccessRecordsDeprecated;
86+
7287
@CommandLine.Option(
73-
names = {"--log-success", "-ls"},
88+
names = {"--enable-log-success", "-ls"},
7489
description = "Enable logging of successfully processed records (default: false)",
7590
defaultValue = "false")
76-
protected boolean logSuccessRecords;
91+
protected boolean enableLogSuccessRecords;
7792

7893
@CommandLine.Option(
7994
names = {"--log-dir", "-ld"},
@@ -183,5 +198,8 @@ public void applyDeprecatedOptions() {
183198
if (threadsDeprecated != null) {
184199
maxThreads = threadsDeprecated;
185200
}
201+
if (logSuccessRecordsDeprecated) {
202+
enableLogSuccessRecords = true;
203+
}
186204
}
187205
}

data-loader/cli/src/test/java/com/scalar/db/dataloader/cli/command/dataimport/ImportCommandTest.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,84 @@ void call_withOnlyDeprecatedThreads_shouldApplyValue() throws Exception {
149149
// Verify the value was applied to maxThreads
150150
assertEquals(12, command.maxThreads);
151151
}
152+
153+
@Test
154+
void call_withBothLogSuccessAndEnableLogSuccess_shouldThrowException() throws Exception {
155+
Path configFile = tempDir.resolve("config.properties");
156+
Files.createFile(configFile);
157+
Path importFile = tempDir.resolve("import.json");
158+
Files.createFile(importFile);
159+
160+
// Simulate command line parsing with both deprecated and new options
161+
String[] args = {"--file", importFile.toString(), "--log-success", "--enable-log-success"};
162+
ImportCommand command = new ImportCommand();
163+
CommandLine cmd = new CommandLine(command);
164+
// Parse args - this will trigger our validation
165+
cmd.parseArgs(args);
166+
167+
// Now call the command, which should throw the validation error
168+
CommandLine.ParameterException thrown =
169+
assertThrows(
170+
CommandLine.ParameterException.class,
171+
command::call,
172+
"Expected to throw ParameterException when both deprecated and new options are specified");
173+
assertTrue(
174+
thrown
175+
.getMessage()
176+
.contains(
177+
"Cannot specify both deprecated option '--log-success' and new option '--enable-log-success'"));
178+
}
179+
180+
@Test
181+
void call_withOnlyDeprecatedLogSuccess_shouldApplyValue() throws Exception {
182+
Path configFile = tempDir.resolve("config.properties");
183+
Files.createFile(configFile);
184+
Path importFile = tempDir.resolve("import.json");
185+
Files.createFile(importFile);
186+
187+
// Simulate command line parsing with only deprecated option
188+
String[] args = {"--file", importFile.toString(), "--log-success"};
189+
ImportCommand command = new ImportCommand();
190+
CommandLine cmd = new CommandLine(command);
191+
cmd.parseArgs(args);
192+
193+
// Verify the deprecated value was parsed
194+
assertTrue(command.logSuccessRecordsDeprecated);
195+
196+
// Apply deprecated options (this is what the command does after validation)
197+
command.applyDeprecatedOptions();
198+
199+
// Verify the value was applied to enable-log-success
200+
assertTrue(command.enableLogSuccessRecords);
201+
}
202+
203+
@Test
204+
void call_withEnableLogSuccess_shouldSetToTrueWithoutValue() throws Exception {
205+
Path importFile = tempDir.resolve("import.json");
206+
Files.createFile(importFile);
207+
208+
// Simulate command line parsing with the new flag without providing true/false value
209+
String[] args = {"--file", importFile.toString(), "--enable-log-success"};
210+
ImportCommand command = new ImportCommand();
211+
CommandLine cmd = new CommandLine(command);
212+
cmd.parseArgs(args);
213+
214+
// Verify the flag was parsed correctly without requiring a value
215+
assertTrue(command.enableLogSuccessRecords);
216+
}
217+
218+
@Test
219+
void call_withEnableLogSuccessShortForm_shouldSetToTrueWithoutValue() throws Exception {
220+
Path importFile = tempDir.resolve("import.json");
221+
Files.createFile(importFile);
222+
223+
// Simulate command line parsing with the short form flag without providing true/false value
224+
String[] args = {"--file", importFile.toString(), "-ls"};
225+
ImportCommand command = new ImportCommand();
226+
CommandLine cmd = new CommandLine(command);
227+
cmd.parseArgs(args);
228+
229+
// Verify the short form flag was parsed correctly without requiring a value
230+
assertTrue(command.enableLogSuccessRecords);
231+
}
152232
}

0 commit comments

Comments
 (0)