Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Integer call() throws Exception {
FileUtils.validateFilePath(scalarDbPropertiesFilePath);
validatePositiveValue(
spec.commandLine(), dataChunkSize, DataLoaderError.INVALID_DATA_CHUNK_SIZE);
validatePositiveValue(spec.commandLine(), maxThreads, DataLoaderError.INVALID_MAX_THREADS);
validatePositiveValue(spec.commandLine(), threadCount, DataLoaderError.INVALID_THREAD_COUNT);

StorageFactory storageFactory = StorageFactory.create(scalarDbPropertiesFilePath);
TableMetadataService metaDataService =
Expand Down Expand Up @@ -126,6 +126,8 @@ private void validateDeprecatedOptions() {
DEPRECATED_END_EXCLUSIVE_OPTION,
END_INCLUSIVE_OPTION,
END_INCLUSIVE_OPTION_SHORT);
validateDeprecatedOptionPair(
spec.commandLine(), DEPRECATED_MAX_THREADS_OPTION, THREADS_OPTION, null);
}

private String getScalarDbPropertiesFilePath() {
Expand Down Expand Up @@ -170,7 +172,7 @@ private ExportOptions buildExportOptions(Key partitionKey, ScanRange scanRange)
.includeTransactionMetadata(includeTransactionMetadata)
.delimiter(delimiter)
.limit(limit)
.maxThreadCount(maxThreads)
.maxThreadCount(threadCount)
.dataChunkSize(dataChunkSize)
.prettyPrintJson(prettyPrintJson)
.scanRange(scanRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class ExportCommandOptions {
public static final String END_INCLUSIVE_OPTION = "--end-inclusive";
public static final String END_INCLUSIVE_OPTION_SHORT = "-ei";
public static final String DEPRECATED_END_EXCLUSIVE_OPTION = "--end-exclusive";
public static final String THREADS_OPTION = "--threads";
public static final String DEPRECATED_MAX_THREADS_OPTION = "--max-threads";

@CommandLine.Option(
names = {"--config", "-c"},
Expand Down Expand Up @@ -73,11 +75,20 @@ public class ExportCommandOptions {
protected boolean includeTransactionMetadata;

@CommandLine.Option(
names = {"--max-threads", "-mt"},
paramLabel = "<MAX_THREADS>",
names = {"--threads"},
paramLabel = "<THREADS>",
description =
"Maximum number of threads to use for parallel processing (default: number of available processors)")
protected int maxThreads;
"Number of threads to use for parallel processing (default: number of available processors)")
protected int threadCount;

// Deprecated option - kept for backward compatibility
@CommandLine.Option(
names = {DEPRECATED_MAX_THREADS_OPTION, "-mt"},
paramLabel = "<MAX_THREADS>",
description = "Deprecated: Use --threads instead",
hidden = true)
@Deprecated
protected Integer maxThreadsDeprecated;

@CommandLine.Option(
names = {"--start-key", "-sk"},
Expand Down Expand Up @@ -184,5 +195,10 @@ public void applyDeprecatedOptions() {
if (endExclusiveDeprecated != null) {
scanEndInclusive = !endExclusiveDeprecated;
}

// If the deprecated option is set, use its value
if (maxThreadsDeprecated != null) {
threadCount = maxThreadsDeprecated;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Integer call() throws Exception {
spec.commandLine(), dataChunkSize, DataLoaderError.INVALID_DATA_CHUNK_SIZE);
validatePositiveValue(
spec.commandLine(), transactionSize, DataLoaderError.INVALID_TRANSACTION_SIZE);
validatePositiveValue(spec.commandLine(), maxThreads, DataLoaderError.INVALID_MAX_THREADS);
validatePositiveValue(spec.commandLine(), threadCount, DataLoaderError.INVALID_THREAD_COUNT);
validatePositiveValue(
spec.commandLine(), dataChunkQueueSize, DataLoaderError.INVALID_DATA_CHUNK_QUEUE_SIZE);
ControlFile controlFile = parseControlFileFromPath(controlFilePath).orElse(null);
Expand Down Expand Up @@ -282,10 +282,7 @@ private Optional<ControlFile> parseControlFileFromPath(String controlFilePath) {
*/
private void validateDeprecatedOptions() {
validateDeprecatedOptionPair(
spec.commandLine(),
DEPRECATED_THREADS_OPTION,
MAX_THREADS_OPTION,
MAX_THREADS_OPTION_SHORT);
spec.commandLine(), DEPRECATED_MAX_THREADS_OPTION, THREADS_OPTION, null);
}

/**
Expand All @@ -308,7 +305,7 @@ private ImportOptions createImportOptions(ControlFile controlFile) {
.namespace(namespace)
.dataChunkSize(dataChunkSize)
.transactionBatchSize(transactionSize)
.maxThreads(maxThreads)
.threadCount(threadCount)
.dataChunkQueueSize(dataChunkQueueSize)
.tableName(tableName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
public class ImportCommandOptions {

public static final String FILE_OPTION_NAME_LONG_FORMAT = "--file";
public static final String MAX_THREADS_OPTION = "--max-threads";
public static final String MAX_THREADS_OPTION_SHORT = "-mt";
public static final String DEPRECATED_THREADS_OPTION = "--threads";
public static final String THREADS_OPTION = "--threads";
public static final String DEPRECATED_MAX_THREADS_OPTION = "--max-threads";

@CommandLine.Option(
names = {"--mode", "-m"},
Expand All @@ -35,21 +34,21 @@ public class ImportCommandOptions {
protected String sourceFilePath;

@CommandLine.Option(
names = {"--max-threads", "-mt"},
paramLabel = "<MAX_THREADS>",
names = {"--threads"},
paramLabel = "<THREADS>",
description =
"Maximum number of threads to use for parallel processing (default: number of available processors)",
"Number of threads to use for parallel processing (default: number of available processors)",
defaultValue = "16")
protected int maxThreads;
protected int threadCount;

// Deprecated option - kept for backward compatibility
@CommandLine.Option(
names = {DEPRECATED_THREADS_OPTION},
paramLabel = "<THREADS>",
description = "Deprecated: Use --max-threads instead",
names = {DEPRECATED_MAX_THREADS_OPTION, "-mt"},
paramLabel = "<MAX_THREADS>",
description = "Deprecated: Use --threads instead",
hidden = true)
@Deprecated
protected Integer threadsDeprecated;
protected Integer maxThreadsDeprecated;

@CommandLine.Option(
names = {"--namespace", "-ns"},
Expand Down Expand Up @@ -180,8 +179,8 @@ public class ImportCommandOptions {
*/
public void applyDeprecatedOptions() {
// If the deprecated option is set, use its value
if (threadsDeprecated != null) {
maxThreads = threadsDeprecated;
if (maxThreadsDeprecated != null) {
threadCount = maxThreadsDeprecated;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void removeFileIfCreated() {
void call_withBlankScalarDBConfigurationFile_shouldThrowException() {
exportCommand.configFilePath = "";
exportCommand.dataChunkSize = 100;
exportCommand.maxThreads = 4;
exportCommand.threadCount = 4;
exportCommand.namespace = "scalar";
exportCommand.table = "asset";
exportCommand.outputDirectory = "";
Expand All @@ -62,7 +62,7 @@ void call_withBlankScalarDBConfigurationFile_shouldThrowException() {
void call_withInvalidScalarDBConfigurationFile_shouldReturnOne() throws Exception {
exportCommand.configFilePath = "scalardb.properties";
exportCommand.dataChunkSize = 100;
exportCommand.maxThreads = 4;
exportCommand.threadCount = 4;
exportCommand.namespace = "scalar";
exportCommand.table = "asset";
exportCommand.outputDirectory = "";
Expand Down Expand Up @@ -190,4 +190,94 @@ void call_withOnlyDeprecatedEndExclusive_shouldApplyInvertedValue() {
// end-exclusive=false should become end-inclusive=true
assertEquals(true, command.scanEndInclusive);
}

@Test
void call_withBothThreadsAndMaxThreads_shouldThrowException() {
assertBothDeprecatedAndNewOptionsThrowException(
"--max-threads=8", "--threads=16", "--max-threads", "--threads");
}

@Test
void call_withOnlyDeprecatedMaxThreads_shouldApplyValue() {
// Simulate command line parsing with only deprecated option
String[] args = {
"--config",
"scalardb.properties",
"--namespace",
"scalar",
"--table",
"asset",
"--format",
"JSON",
"--max-threads",
"12"
};
ExportCommand command = new ExportCommand();
CommandLine cmd = new CommandLine(command);
cmd.parseArgs(args);

// Verify the deprecated value was parsed
assertEquals(12, command.maxThreadsDeprecated);

// Apply deprecated options
command.applyDeprecatedOptions();

// Verify the value was applied to threadCount
assertEquals(12, command.threadCount);
}

@Test
void call_withOnlyThreads_shouldUseValue() {
// Simulate command line parsing with only new --threads option
String[] args = {
"--config",
"scalardb.properties",
"--namespace",
"scalar",
"--table",
"asset",
"--format",
"JSON",
"--threads",
"20"
};
ExportCommand command = new ExportCommand();
CommandLine cmd = new CommandLine(command);
cmd.parseArgs(args);

// Verify the value was set to threadCount
assertEquals(20, command.threadCount);

// Verify the deprecated value was not set
assertEquals(null, command.maxThreadsDeprecated);
}

@Test
void call_withDeprecatedShortOption_shouldApplyValue() {
// Simulate command line parsing with deprecated short option -mt
String[] args = {
"--config",
"scalardb.properties",
"--namespace",
"scalar",
"--table",
"asset",
"--format",
"JSON",
"-mt",
"15"
};
ExportCommand command = new ExportCommand();
CommandLine cmd = new CommandLine(command);
cmd.parseArgs(args);

// Verify the deprecated value was parsed
assertEquals(15, command.maxThreadsDeprecated);

// Apply deprecated options
command.applyDeprecatedOptions();

// Verify the value was applied to threadCount
assertEquals(15, command.threadCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void call_WithoutValidConfigFile_ShouldThrowException() throws Exception {
importCommand.importMode = ImportMode.UPSERT;
importCommand.dataChunkSize = 100;
importCommand.transactionSize = 10;
importCommand.maxThreads = 4;
importCommand.threadCount = 4;
importCommand.dataChunkQueueSize = 64;
assertThrows(IllegalArgumentException.class, () -> importCommand.call());
}
Expand Down Expand Up @@ -93,9 +93,9 @@ void call_withBothThreadsAndMaxThreads_shouldThrowException() throws Exception {
"sample",
"--table",
"table",
"--threads",
"8",
"--max-threads",
"8",
"--threads",
"16"
};
ImportCommand command = new ImportCommand();
Expand All @@ -113,11 +113,11 @@ void call_withBothThreadsAndMaxThreads_shouldThrowException() throws Exception {
thrown
.getMessage()
.contains(
"Cannot specify both deprecated option '--threads' and new option '--max-threads'"));
"Cannot specify both deprecated option '--max-threads' and new option '--threads'"));
}

@Test
void call_withOnlyDeprecatedThreads_shouldApplyValue() throws Exception {
void call_withOnlyDeprecatedMaxThreads_shouldApplyValue() throws Exception {
Path configFile = tempDir.resolve("config.properties");
Files.createFile(configFile);
Path importFile = tempDir.resolve("import.json");
Expand All @@ -133,20 +133,85 @@ void call_withOnlyDeprecatedThreads_shouldApplyValue() throws Exception {
"sample",
"--table",
"table",
"--threads",
"--max-threads",
"12"
};
ImportCommand command = new ImportCommand();
CommandLine cmd = new CommandLine(command);
cmd.parseArgs(args);

// Verify the deprecated value was parsed
assertEquals(12, command.threadsDeprecated);
assertEquals(12, command.maxThreadsDeprecated);

// Apply deprecated options (this is what the command does after validation)
command.applyDeprecatedOptions();

// Verify the value was applied to maxThreads
assertEquals(12, command.maxThreads);
// Verify the value was applied to threadCount
assertEquals(12, command.threadCount);
}

@Test
void call_withOnlyThreads_shouldUseValue() throws Exception {
Path configFile = tempDir.resolve("config.properties");
Files.createFile(configFile);
Path importFile = tempDir.resolve("import.json");
Files.createFile(importFile);

// Simulate command line parsing with only new --threads option
String[] args = {
"--config",
configFile.toString(),
"--file",
importFile.toString(),
"--namespace",
"sample",
"--table",
"table",
"--threads",
"20"
};
ImportCommand command = new ImportCommand();
CommandLine cmd = new CommandLine(command);
cmd.parseArgs(args);

// Verify the value was set to threadCount
assertEquals(20, command.threadCount);

// Verify the deprecated value was not set
assertEquals(null, command.maxThreadsDeprecated);
}

@Test
void call_withDeprecatedShortOption_shouldApplyValue() throws Exception {
Path configFile = tempDir.resolve("config.properties");
Files.createFile(configFile);
Path importFile = tempDir.resolve("import.json");
Files.createFile(importFile);

// Simulate command line parsing with deprecated short option -mt
String[] args = {
"--config",
configFile.toString(),
"--file",
importFile.toString(),
"--namespace",
"sample",
"--table",
"table",
"-mt",
"15"
};
ImportCommand command = new ImportCommand();
CommandLine cmd = new CommandLine(command);
cmd.parseArgs(args);

// Verify the deprecated value was parsed
assertEquals(15, command.maxThreadsDeprecated);

// Apply deprecated options
command.applyDeprecatedOptions();

// Verify the value was applied to threadCount
assertEquals(15, command.threadCount);
}
}
Loading
Loading