Search in sources :

Example 46 with MockPipelineConfigurer

use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.

the class TableSinkTest method testTableSinkWithComplexTypeInOutputSchema.

@Test
public void testTableSinkWithComplexTypeInOutputSchema() {
    Schema outputSchema = Schema.recordOf("purchase", Schema.Field.of("rowkey", Schema.of(Schema.Type.STRING)), Schema.Field.of("user", Schema.of(Schema.Type.STRING)), Schema.Field.of("complex", Schema.mapOf(Schema.of(Schema.Type.STRING), Schema.of(Schema.Type.STRING))));
    Schema inputSchema = Schema.recordOf("purchase", Schema.Field.of("rowkey", Schema.of(Schema.Type.STRING)), Schema.Field.of("user", Schema.of(Schema.Type.STRING)), Schema.Field.of("complex", Schema.mapOf(Schema.of(Schema.Type.STRING), Schema.of(Schema.Type.STRING))));
    TableSinkConfig tableSinkConfig = new TableSinkConfig("tableSink", "rowkey", outputSchema.toString());
    TableSink tableSink = new TableSink(tableSinkConfig);
    MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(inputSchema);
    tableSink.configurePipeline(mockPipelineConfigurer);
    FailureCollector collector = mockPipelineConfigurer.getStageConfigurer().getFailureCollector();
    Assert.assertEquals(1, collector.getValidationFailures().size());
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) TableSinkConfig(io.cdap.plugin.common.TableSinkConfig) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Example 47 with MockPipelineConfigurer

use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.

the class TableSinkTest method testTableSinkWithOutputSchemaWithOnlyRowKeyField.

@Test(expected = IllegalArgumentException.class)
public void testTableSinkWithOutputSchemaWithOnlyRowKeyField() {
    Schema outputSchema = Schema.recordOf("purchase", Schema.Field.of("rowkey", Schema.of(Schema.Type.STRING)));
    Schema inputSchema = Schema.recordOf("purchase", Schema.Field.of("rowkey", Schema.of(Schema.Type.STRING)), Schema.Field.of("user", Schema.of(Schema.Type.STRING)), Schema.Field.of("count", Schema.of(Schema.Type.INT)));
    TableSinkConfig tableSinkConfig = new TableSinkConfig("tableSink", "rowkey", outputSchema.toString());
    TableSink tableSink = new TableSink(tableSinkConfig);
    MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(inputSchema);
    tableSink.configurePipeline(mockPipelineConfigurer);
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) TableSinkConfig(io.cdap.plugin.common.TableSinkConfig) Test(org.junit.Test)

Example 48 with MockPipelineConfigurer

use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.

the class TableSinkTest method testTableSinkWithOutputSchemaMissingRowKeyField.

@Test(expected = IllegalArgumentException.class)
public void testTableSinkWithOutputSchemaMissingRowKeyField() {
    Schema outputSchema = Schema.recordOf("purchase", Schema.Field.of("user", Schema.of(Schema.Type.STRING)), Schema.Field.of("count", Schema.of(Schema.Type.INT)));
    Schema inputSchema = Schema.recordOf("purchase", Schema.Field.of("rowkey", Schema.of(Schema.Type.STRING)), Schema.Field.of("user", Schema.of(Schema.Type.STRING)), Schema.Field.of("count", Schema.of(Schema.Type.INT)));
    TableSinkConfig tableSinkConfig = new TableSinkConfig("tableSink", "rowkey", outputSchema.toString());
    TableSink tableSink = new TableSink(tableSinkConfig);
    MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(inputSchema);
    tableSink.configurePipeline(mockPipelineConfigurer);
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) TableSinkConfig(io.cdap.plugin.common.TableSinkConfig) Test(org.junit.Test)

Example 49 with MockPipelineConfigurer

use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.

the class ProjectionTransformTest method testDropFieldsValidations.

@Test
public void testDropFieldsValidations() {
    Schema schema = Schema.recordOf("three", Schema.Field.of("x", Schema.of(Schema.Type.INT)), Schema.Field.of("y", Schema.of(Schema.Type.DOUBLE)), Schema.Field.of("z", Schema.arrayOf(Schema.of(Schema.Type.INT))));
    MockPipelineConfigurer mockConfigurer = new MockPipelineConfigurer(schema, Collections.emptyMap());
    ProjectionTransform.ProjectionTransformConfig config = new ProjectionTransform.ProjectionTransformConfig("x,y,z", null, null, null);
    try {
        new ProjectionTransform(config).configurePipeline(mockConfigurer);
        Assert.fail();
    } catch (ValidationException e) {
        Assert.assertEquals(1, e.getFailures().size());
        Assert.assertEquals(1, e.getFailures().get(0).getCauses().size());
        Cause expectedCause = new Cause();
        expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, ProjectionTransform.ProjectionTransformConfig.DROP);
        expectedCause.addAttribute(STAGE, MOCK_STAGE);
        Assert.assertEquals(expectedCause, e.getFailures().get(0).getCauses().get(0));
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) Test(org.junit.Test)

Example 50 with MockPipelineConfigurer

use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.

the class LogParserTransformTest method testConfigurePipelineSchemaValidationError.

@Test
public void testConfigurePipelineSchemaValidationError() {
    MockPipelineConfigurer mockConfigurer = new MockPipelineConfigurer(Schema.of(Schema.Type.BYTES), Collections.emptyMap());
    S3_TRANSFORM.configurePipeline(mockConfigurer);
    Assert.assertEquals(LOG_SCHEMA, mockConfigurer.getOutputSchema());
    FailureCollector collector = mockConfigurer.getStageConfigurer().getFailureCollector();
    Assert.assertEquals(1, mockConfigurer.getStageConfigurer().getFailureCollector().getValidationFailures().size());
    Assert.assertEquals(0, collector.getValidationFailures().get(0).getCauses().size());
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Aggregations

MockPipelineConfigurer (io.cdap.cdap.etl.mock.common.MockPipelineConfigurer)89 Test (org.junit.Test)89 Schema (io.cdap.cdap.api.data.schema.Schema)56 FailureCollector (io.cdap.cdap.etl.api.FailureCollector)26 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)22 ValidationException (io.cdap.cdap.etl.api.validation.ValidationException)17 Cause (io.cdap.cdap.etl.api.validation.ValidationFailure.Cause)12 ValidationFailure (io.cdap.cdap.etl.api.validation.ValidationFailure)10 TableSinkConfig (io.cdap.plugin.common.TableSinkConfig)10 HBaseSink (io.cdap.plugin.sink.HBaseSink)7 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)5 MockEmitter (io.cdap.cdap.etl.mock.common.MockEmitter)4 TransformContext (io.cdap.cdap.etl.api.TransformContext)3 MockTransformContext (io.cdap.cdap.etl.mock.transform.MockTransformContext)3 SolrSearchSink (io.cdap.plugin.batch.SolrSearchSink)3 PipelineConfigurer (io.cdap.cdap.etl.api.PipelineConfigurer)2 LookupConfig (io.cdap.cdap.etl.api.LookupConfig)1 LookupTableConfig (io.cdap.cdap.etl.api.LookupTableConfig)1 MockFailureCollector (io.cdap.cdap.etl.mock.validation.MockFailureCollector)1