use of org.msgpack.value.ImmutableMapValue in project embulk by embulk.
the class TestFileOutputRunner method testMockFormatterIteration.
@Test
public void testMockFormatterIteration() {
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();
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 {
ImmutableMapValue jsonValue = newMap(newString("_c1"), newBoolean(true), newString("_c2"), newInteger(10), newString("_c3"), newString("embulk"), newString("_c4"), newMap(newString("k"), newString("v")));
for (Page page : PageTestUtils.buildPage(runtime.getBufferAllocator(), schema, true, 2L, 3.0D, "45", Timestamp.ofEpochMilli(678L), jsonValue, true, 2L, 3.0D, "45", Timestamp.ofEpochMilli(678L), jsonValue)) {
tran.add(page);
}
tran.commit();
committed = true;
} finally {
if (!committed) {
tran.abort();
}
tran.close();
}
return new ArrayList<TaskReport>();
}
});
assertEquals(true, fileOutputPlugin.transactionCompleted);
assertEquals(2, MockFormatterPlugin.records.size());
for (List<Object> record : MockFormatterPlugin.records) {
assertEquals(Boolean.TRUE, record.get(0));
assertEquals(2L, record.get(1));
assertEquals(3.0D, (Double) record.get(2), 0.1D);
assertEquals("45", record.get(3));
assertEquals(678L, ((Timestamp) record.get(4)).toEpochMilli());
assertEquals("{\"_c1\":true,\"_c2\":10,\"_c3\":\"embulk\",\"_c4\":{\"k\":\"v\"}}", record.get(5).toString());
}
}
Aggregations