Sha256: 9ebeb7a8bd8fd78a09dcdcbed3016dd8f305950ffd9926376217a9669f58d9cf

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

package org.embulk.input.oracle;

import com.google.common.base.Throwables;
import com.google.common.io.ByteStreams;
import org.embulk.config.ConfigSource;
import org.embulk.test.EmbulkTests;
import org.embulk.test.TestingEmbulk;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;

import static java.util.Locale.ENGLISH;

public class OracleTests
{
    public static ConfigSource baseConfig()
    {
        return EmbulkTests.config("EMBULK_INPUT_ORACLE_TEST_CONFIG");
    }

    public static void execute(TestingEmbulk embulk, String sql) throws IOException
{
        Path sqlFile = embulk.createTempFile("sql");
        Files.write(sqlFile, Arrays.asList(sql), Charset.forName("UTF8"));

        ConfigSource config = baseConfig();
        String host = config.get(String.class, "host");
        String port = config.get(String.class, "port", "1521");
        String user = config.get(String.class, "user");
        String password = config.get(String.class, "password");
        String database = config.get(String.class, "database");

        ProcessBuilder pb = new ProcessBuilder(
                "sql",
                user + "/" + password + "@" + host + ":" + port + "/" + database,
                "@" + sqlFile.toFile().getAbsolutePath());
        pb.environment().put("JAVA_TOOL_OPTIONS", "-Dfile.encoding=UTF8");
        pb.redirectErrorStream(true);
        int code;
        try {
            Process process = pb.start();
            ByteStreams.copy(process.getInputStream(), System.out);
            code = process.waitFor();
        } catch (IOException | InterruptedException ex) {
            throw Throwables.propagate(ex);
        }
        if (code != 0) {
            throw new RuntimeException(String.format(ENGLISH,
                        "Command finished with non-zero exit code. Exit code is %d.", code));
        }
    }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
embulk-input-oracle-0.8.4 src/test/java/org/embulk/input/oracle/OracleTests.java
embulk-input-oracle-0.8.3 src/test/java/org/embulk/input/oracle/OracleTests.java