Search in sources :

Example 41 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestFileOutputRunner method testTransactionAborted.

@Test
public void testTransactionAborted() {
    MockFileOutputPlugin fileOutputPlugin = new MockFileOutputPlugin();
    final FileOutputRunner runner = new FileOutputRunner(fileOutputPlugin);
    ImmutableList<ImmutableMap<String, Object>> columns = ImmutableList.of(ImmutableMap.<String, Object>of("name", "col1", "type", "boolean", "option", ImmutableMap.of()), ImmutableMap.<String, Object>of("name", "col2", "type", "long", "option", ImmutableMap.of()), ImmutableMap.<String, Object>of("name", "col3", "type", "double", "option", ImmutableMap.of()), ImmutableMap.<String, Object>of("name", "col4", "type", "string", "option", ImmutableMap.of()), ImmutableMap.<String, Object>of("name", "col5", "type", "timestamp", "option", ImmutableMap.of()), ImmutableMap.<String, Object>of("name", "col6", "type", "json", "option", ImmutableMap.of()));
    ConfigSource config = Exec.newConfigSource().set("type", "unused?").set("formatter", ImmutableMap.of("type", "mock", "columns", columns));
    final Schema schema = config.getNested("formatter").loadConfig(MockParserPlugin.PluginTask.class).getSchemaConfig().toSchema();
    try {
        runner.transaction(config, schema, 1, new OutputPlugin.Control() {

            public List<TaskReport> run(final TaskSource outputTask) {
                TransactionalPageOutput tran = runner.open(outputTask, schema, 1);
                boolean committed = false;
                try {
                    tran.add(null);
                    tran.commit();
                    committed = true;
                } finally {
                    if (!committed) {
                        tran.abort();
                    }
                    tran.close();
                }
                return new ArrayList<TaskReport>();
            }
        });
    } catch (NullPointerException npe) {
    // Just passing through.
    }
    assertEquals(false, fileOutputPlugin.transactionCompleted);
}
Also used : TaskReport(org.embulk.config.TaskReport) ImmutableMap(com.google.common.collect.ImmutableMap) ConfigSource(org.embulk.config.ConfigSource) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TaskSource(org.embulk.config.TaskSource) Test(org.junit.Test)

Example 42 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestTimestampFormatterParser method testSimpleFormat.

@Test
public void testSimpleFormat() throws Exception {
    ConfigSource config = Exec.newConfigSource().set("default_timestamp_format", // %Z is OS-dependent
    "%Y-%m-%d %H:%M:%S.%9N %z");
    FormatterTestTask task = config.loadConfig(FormatterTestTask.class);
    TimestampFormatter formatter = TimestampFormatter.of(task, Optional.<TimestampFormatter.TimestampColumnOption>absent());
    assertEquals("2014-11-19 02:46:29.123456000 +0000", formatter.format(Timestamp.ofEpochSecond(1416365189, 123456 * 1000)));
}
Also used : ConfigSource(org.embulk.config.ConfigSource) Test(org.junit.Test)

Example 43 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestTimestampFormatterParser method testSimpleParse.

@Test
public void testSimpleParse() throws Exception {
    ConfigSource config = Exec.newConfigSource().set("default_timestamp_format", // %Z is OS-dependent
    "%Y-%m-%d %H:%M:%S %z");
    ParserTestTask task = config.loadConfig(ParserTestTask.class);
    TimestampParser parser = TimestampParserLegacy.createTimestampParserForTesting(task);
    assertEquals(Timestamp.ofEpochSecond(1416365189, 0), parser.parse("2014-11-19 02:46:29 +0000"));
}
Also used : ConfigSource(org.embulk.config.ConfigSource) Test(org.junit.Test)

Example 44 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestTimestampFormatterParser method testUnixtimeFormat.

@Test
public void testUnixtimeFormat() throws Exception {
    ConfigSource config = Exec.newConfigSource().set("default_timestamp_format", "%s");
    FormatterTestTask ftask = config.loadConfig(FormatterTestTask.class);
    TimestampFormatter formatter = TimestampFormatter.of(ftask, Optional.<TimestampFormatter.TimestampColumnOption>absent());
    assertEquals("1416365189", formatter.format(Timestamp.ofEpochSecond(1416365189)));
    ParserTestTask ptask = config.loadConfig(ParserTestTask.class);
    TimestampParser parser = TimestampParserLegacy.createTimestampParserForTesting(ptask);
    assertEquals(Timestamp.ofEpochSecond(1416365189), parser.parse("1416365189"));
}
Also used : ConfigSource(org.embulk.config.ConfigSource) Test(org.junit.Test)

Example 45 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestLineDecoder method testDefaultValues.

@Test
public void testDefaultValues() {
    ConfigSource config = Exec.newConfigSource();
    LineDecoder.DecoderTask task = config.loadConfig(LineDecoder.DecoderTask.class);
    assertEquals(StandardCharsets.UTF_8, task.getCharset());
    assertEquals(Newline.CRLF, task.getNewline());
}
Also used : ConfigSource(org.embulk.config.ConfigSource) Test(org.junit.Test)

Aggregations

ConfigSource (org.embulk.config.ConfigSource)50 Test (org.junit.Test)33 TaskSource (org.embulk.config.TaskSource)12 Schema (org.embulk.spi.Schema)9 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)6 List (java.util.List)6 ConfigDiff (org.embulk.config.ConfigDiff)6 FilterPlugin (org.embulk.spi.FilterPlugin)6 ImmutableList (com.google.common.collect.ImmutableList)5 SchemaConfigException (org.embulk.spi.SchemaConfigException)4 ConfigException (org.embulk.config.ConfigException)3 Column (org.embulk.spi.Column)3 InputPlugin (org.embulk.spi.InputPlugin)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 LinkedList (java.util.LinkedList)2 DataSource (org.embulk.config.DataSource)2 TaskReport (org.embulk.config.TaskReport)2