Search in sources :

Example 1 with TaskSource

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

the class TestFileInputRunner method testTransactionAborted.

@Test
public void testTransactionAborted() {
    Buffer[] buffers = new Buffer[] { runtime.getBufferAllocator().allocate(), runtime.getBufferAllocator().allocate() };
    MockFileInputPlugin fileInputPlugin = new MockFileInputPlugin(new LinkedList<Buffer>(Arrays.asList(buffers)));
    final FileInputRunner runner = new FileInputRunner(fileInputPlugin);
    ConfigSource config = Exec.newConfigSource().set("parser", ImmutableMap.of("type", "mock", "columns", ImmutableList.of(ImmutableMap.of("name", "col1", "type", "boolean", "option", ImmutableMap.of()), ImmutableMap.of("name", "col2", "type", "long", "option", ImmutableMap.of()), ImmutableMap.of("name", "col3", "type", "double", "option", ImmutableMap.of()), ImmutableMap.of("name", "col4", "type", "string", "option", ImmutableMap.of()), ImmutableMap.of("name", "col5", "type", "timestamp", "option", ImmutableMap.of()), ImmutableMap.of("name", "col6", "type", "json", "option", ImmutableMap.of()))));
    final MockPageOutput output = new MockPageOutput();
    MockParserPlugin.raiseException = true;
    try {
        runner.transaction(config, new InputPlugin.Control() {

            public List<TaskReport> run(TaskSource inputTaskSource, Schema schema, int taskCount) {
                List<TaskReport> reports = new ArrayList<>();
                reports.add(runner.run(inputTaskSource, schema, 0, output));
                return reports;
            }
        });
    } catch (RuntimeException re) {
    // Just passing through.
    }
    assertEquals(false, fileInputPlugin.transactionCompleted);
    assertEquals(0, output.pages.size());
}
Also used : MockPageOutput(org.embulk.spi.TestPageBuilderReader.MockPageOutput) ConfigSource(org.embulk.config.ConfigSource) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) TaskSource(org.embulk.config.TaskSource) Test(org.junit.Test)

Example 2 with TaskSource

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

the class TestFileInputRunner method testMockParserIteration.

@Test
public void testMockParserIteration() {
    Buffer[] buffers = new Buffer[] { runtime.getBufferAllocator().allocate(), runtime.getBufferAllocator().allocate() };
    MockFileInputPlugin fileInputPlugin = new MockFileInputPlugin(new LinkedList<Buffer>(Arrays.asList(buffers)));
    final FileInputRunner runner = new FileInputRunner(fileInputPlugin);
    ConfigSource config = Exec.newConfigSource().set("parser", ImmutableMap.of("type", "mock", "columns", ImmutableList.of(ImmutableMap.of("name", "col1", "type", "boolean", "option", ImmutableMap.of()), ImmutableMap.of("name", "col2", "type", "long", "option", ImmutableMap.of()), ImmutableMap.of("name", "col3", "type", "double", "option", ImmutableMap.of()), ImmutableMap.of("name", "col4", "type", "string", "option", ImmutableMap.of()), ImmutableMap.of("name", "col5", "type", "timestamp", "option", ImmutableMap.of()), ImmutableMap.of("name", "col6", "type", "json", "option", ImmutableMap.of()))));
    final MockPageOutput output = new MockPageOutput();
    runner.transaction(config, new InputPlugin.Control() {

        public List<TaskReport> run(TaskSource inputTaskSource, Schema schema, int taskCount) {
            List<TaskReport> reports = new ArrayList<>();
            reports.add(runner.run(inputTaskSource, schema, 0, output));
            return reports;
        }
    });
    assertEquals(true, fileInputPlugin.transactionCompleted);
    assertEquals(1, output.pages.size());
    Schema schema = config.getNested("parser").loadConfig(MockParserPlugin.PluginTask.class).getSchemaConfig().toSchema();
    List<Object[]> records = Pages.toObjects(schema, output.pages);
    assertEquals(2, records.size());
    for (Object[] record : records) {
        assertEquals(6, record.length);
        assertEquals(true, record[0]);
        assertEquals(2L, record[1]);
        assertEquals(3.0D, (Double) record[2], 0.01D);
        assertEquals("45", record[3]);
        assertEquals(678L, ((Timestamp) record[4]).toEpochMilli());
        assertEquals("{\"_c2\":10,\"_c1\":true,\"_c4\":{\"k\":\"v\"},\"_c3\":\"embulk\"}", record[5].toString());
    }
}
Also used : MockPageOutput(org.embulk.spi.TestPageBuilderReader.MockPageOutput) ConfigSource(org.embulk.config.ConfigSource) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) TaskSource(org.embulk.config.TaskSource) Test(org.junit.Test)

Example 3 with TaskSource

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

the class TestRenameFilterPlugin method checkConfigExceptionIfUnknownRenamingOperatorName.

@Test
public void checkConfigExceptionIfUnknownRenamingOperatorName() {
    ConfigSource pluginConfig = Exec.newConfigSource().set("rules", ImmutableList.of(ImmutableMap.of("rule", "some_unknown_renaming_operator")));
    try {
        filter.transaction(pluginConfig, SCHEMA, new FilterPlugin.Control() {

            public void run(TaskSource task, Schema schema) {
            }
        });
        fail();
    } catch (Throwable t) {
        assertTrue(t instanceof ConfigException);
    }
}
Also used : ConfigSource(org.embulk.config.ConfigSource) FilterPlugin(org.embulk.spi.FilterPlugin) Schema(org.embulk.spi.Schema) ConfigException(org.embulk.config.ConfigException) SchemaConfigException(org.embulk.spi.SchemaConfigException) TaskSource(org.embulk.config.TaskSource) Test(org.junit.Test)

Example 4 with TaskSource

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

the class TestRenameFilterPlugin method throwSchemaConfigExceptionIfColumnNotFound.

@Test
public void throwSchemaConfigExceptionIfColumnNotFound() {
    ConfigSource pluginConfig = Exec.newConfigSource().set("columns", ImmutableMap.of("not_found", "any_name"));
    try {
        filter.transaction(pluginConfig, SCHEMA, new FilterPlugin.Control() {

            public void run(TaskSource task, Schema schema) {
            }
        });
        fail();
    } catch (Throwable t) {
        assertTrue(t instanceof SchemaConfigException);
    }
}
Also used : ConfigSource(org.embulk.config.ConfigSource) FilterPlugin(org.embulk.spi.FilterPlugin) Schema(org.embulk.spi.Schema) TaskSource(org.embulk.config.TaskSource) SchemaConfigException(org.embulk.spi.SchemaConfigException) Test(org.junit.Test)

Example 5 with TaskSource

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

the class TestRenameFilterPlugin method checkConfigExceptionIfUnknownListTypeOfRenamingOperator.

@Test
public void checkConfigExceptionIfUnknownListTypeOfRenamingOperator() {
    // A list [] shouldn't come as a renaming rule.
    ConfigSource pluginConfig = Exec.newConfigSource().set("rules", ImmutableList.of(ImmutableList.of("listed_operator1", "listed_operator2")));
    try {
        filter.transaction(pluginConfig, SCHEMA, new FilterPlugin.Control() {

            public void run(TaskSource task, Schema schema) {
            }
        });
        fail();
    } catch (Throwable t) {
        assertTrue(t instanceof ConfigException);
    }
}
Also used : ConfigSource(org.embulk.config.ConfigSource) FilterPlugin(org.embulk.spi.FilterPlugin) Schema(org.embulk.spi.Schema) ConfigException(org.embulk.config.ConfigException) SchemaConfigException(org.embulk.spi.SchemaConfigException) TaskSource(org.embulk.config.TaskSource) Test(org.junit.Test)

Aggregations

TaskSource (org.embulk.config.TaskSource)17 ConfigSource (org.embulk.config.ConfigSource)12 Schema (org.embulk.spi.Schema)12 List (java.util.List)9 Test (org.junit.Test)9 ImmutableList (com.google.common.collect.ImmutableList)8 ArrayList (java.util.ArrayList)7 FilterPlugin (org.embulk.spi.FilterPlugin)7 TaskReport (org.embulk.config.TaskReport)5 InputPlugin (org.embulk.spi.InputPlugin)5 SchemaConfigException (org.embulk.spi.SchemaConfigException)4 ConfigDiff (org.embulk.config.ConfigDiff)3 ConfigException (org.embulk.config.ConfigException)3 PageOutput (org.embulk.spi.PageOutput)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 LinkedList (java.util.LinkedList)2 Column (org.embulk.spi.Column)2 ExecutorPlugin (org.embulk.spi.ExecutorPlugin)2 FileInputRunner (org.embulk.spi.FileInputRunner)2 Page (org.embulk.spi.Page)2