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);
}
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)));
}
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"));
}
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"));
}
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());
}
Aggregations