Search in sources :

Example 6 with CommandLineParser

use of com.datastax.oss.dsbulk.runner.cli.CommandLineParser in project dsbulk by datastax.

the class DataStaxBulkLoaderTest method should_process_json_long_options.

@ParameterizedTest
@MethodSource
void should_process_json_long_options(String settingName, String settingValue, Object expected) throws Exception {
    Config result = new CommandLineParser("load", "--" + settingName, settingValue).parse().getConfig();
    assertThat(result.getAnyRef(settingName)).isEqualTo(expected);
}
Also used : Config(com.typesafe.config.Config) CommandLineParser(com.datastax.oss.dsbulk.runner.cli.CommandLineParser) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with CommandLineParser

use of com.datastax.oss.dsbulk.runner.cli.CommandLineParser in project dsbulk by datastax.

the class DataStaxBulkLoaderTest method should_accept_escaped_double_quote_in_complex_type.

@Test
void should_accept_escaped_double_quote_in_complex_type() throws Exception {
    // double quotes should be provided escaped as valid HOCON
    Config result = new CommandLineParser("load", "--codec.booleanStrings", "[\"foo\\\"bar\"]").parse().getConfig();
    assertThat(result.getStringList("dsbulk.codec.booleanStrings")).containsExactly("foo\"bar");
}
Also used : Config(com.typesafe.config.Config) CommandLineParser(com.datastax.oss.dsbulk.runner.cli.CommandLineParser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with CommandLineParser

use of com.datastax.oss.dsbulk.runner.cli.CommandLineParser in project dsbulk by datastax.

the class DataStaxBulkLoaderTest method should_process_csv_long_options.

@ParameterizedTest
@MethodSource
void should_process_csv_long_options(String settingName, String settingValue, Object expected) throws Exception {
    Config result = new CommandLineParser("load", "--" + settingName, settingValue).parse().getConfig();
    assertThat(result.getAnyRef(settingName)).isEqualTo(expected);
}
Also used : Config(com.typesafe.config.Config) CommandLineParser(com.datastax.oss.dsbulk.runner.cli.CommandLineParser) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with CommandLineParser

use of com.datastax.oss.dsbulk.runner.cli.CommandLineParser in project dsbulk by datastax.

the class DataStaxBulkLoader method run.

@NonNull
public ExitStatus run() {
    Workflow workflow = null;
    try {
        AnsiConfigurator.configureAnsi(args);
        CommandLineParser parser = new CommandLineParser(args);
        ParsedCommandLine result = parser.parse();
        Config config = result.getConfig();
        workflow = result.getWorkflowProvider().newWorkflow(config);
        WorkflowThread workflowThread = new WorkflowThread(workflow);
        Runtime.getRuntime().addShutdownHook(new CleanupThread(workflow, workflowThread));
        // start the workflow and wait for its completion
        workflowThread.start();
        workflowThread.join();
        return workflowThread.getExitStatus();
    } catch (GlobalHelpRequestException e) {
        HelpEmitter.emitGlobalHelp(e.getConnectorName());
        return STATUS_OK;
    } catch (SectionHelpRequestException e) {
        try {
            HelpEmitter.emitSectionHelp(e.getSectionName(), e.getConnectorName());
            return STATUS_OK;
        } catch (Exception e2) {
            LOGGER.error(e2.getMessage(), e2);
            return STATUS_CRASHED;
        }
    } catch (VersionRequestException e) {
        // Use the OS charset
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out, Charset.defaultCharset())));
        pw.println(WorkflowUtils.getBulkLoaderNameAndVersion());
        pw.flush();
        return STATUS_OK;
    } catch (Throwable t) {
        return ErrorHandler.handleUnexpectedError(workflow, t);
    }
}
Also used : Config(com.typesafe.config.Config) Workflow(com.datastax.oss.dsbulk.workflow.api.Workflow) GlobalHelpRequestException(com.datastax.oss.dsbulk.runner.cli.GlobalHelpRequestException) SectionHelpRequestException(com.datastax.oss.dsbulk.runner.cli.SectionHelpRequestException) VersionRequestException(com.datastax.oss.dsbulk.runner.cli.VersionRequestException) GlobalHelpRequestException(com.datastax.oss.dsbulk.runner.cli.GlobalHelpRequestException) BufferedWriter(java.io.BufferedWriter) VersionRequestException(com.datastax.oss.dsbulk.runner.cli.VersionRequestException) ParsedCommandLine(com.datastax.oss.dsbulk.runner.cli.ParsedCommandLine) OutputStreamWriter(java.io.OutputStreamWriter) CommandLineParser(com.datastax.oss.dsbulk.runner.cli.CommandLineParser) SectionHelpRequestException(com.datastax.oss.dsbulk.runner.cli.SectionHelpRequestException) PrintWriter(java.io.PrintWriter) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 10 with CommandLineParser

use of com.datastax.oss.dsbulk.runner.cli.CommandLineParser in project dsbulk by datastax.

the class DataStaxBulkLoaderTest method should_accept_escaped_double_quote.

@Test
void should_accept_escaped_double_quote() throws Exception {
    // double quotes should be provided escaped as valid HOCON
    Config result = new CommandLineParser("load", "--connector.csv.escape", "\\\"").parse().getConfig();
    assertThat(result.getString("dsbulk.connector.csv.escape")).isEqualTo("\"");
}
Also used : Config(com.typesafe.config.Config) CommandLineParser(com.datastax.oss.dsbulk.runner.cli.CommandLineParser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CommandLineParser (com.datastax.oss.dsbulk.runner.cli.CommandLineParser)14 Config (com.typesafe.config.Config)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 Test (org.junit.jupiter.api.Test)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 GlobalHelpRequestException (com.datastax.oss.dsbulk.runner.cli.GlobalHelpRequestException)1 ParseException (com.datastax.oss.dsbulk.runner.cli.ParseException)1 ParsedCommandLine (com.datastax.oss.dsbulk.runner.cli.ParsedCommandLine)1 SectionHelpRequestException (com.datastax.oss.dsbulk.runner.cli.SectionHelpRequestException)1 VersionRequestException (com.datastax.oss.dsbulk.runner.cli.VersionRequestException)1 Workflow (com.datastax.oss.dsbulk.workflow.api.Workflow)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1