Search in sources :

Example 1 with FixedFlowInputProperties

use of org.talend.components.localio.fixedflowinput.FixedFlowInputProperties in project components by Talend.

the class FixedFlowInputRuntimeTest method test_TenOutputRow.

@Test
public void test_TenOutputRow() throws Exception {
    String inputAsString = generateInputJSON(inputSchema, inputIndexedRecord1);
    FixedFlowInputProperties properties = new FixedFlowInputProperties("test");
    properties.init();
    properties.schemaFlow.schema.setValue(inputSchema);
    properties.values.setValue(inputAsString);
    properties.nbRows.setValue(10);
    FixedFlowInputRuntime runtime = new FixedFlowInputRuntime();
    runtime.initialize(null, properties);
    PCollection<IndexedRecord> indexRecords = pipeline.apply(runtime);
    try (DirectCollector<IndexedRecord> collector = DirectCollector.of()) {
        indexRecords.apply(collector);
        // Run the pipeline to fill the collectors.
        pipeline.run().waitUntilFinish();
        ;
        // Validate the contents of the collected outputs.
        List<IndexedRecord> outputs = collector.getRecords();
        assertEquals(10, outputs.size());
        for (IndexedRecord output : outputs) {
            assertEquals(inputIndexedRecord1.toString(), output.toString());
        }
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) FixedFlowInputProperties(org.talend.components.localio.fixedflowinput.FixedFlowInputProperties) Test(org.junit.Test)

Example 2 with FixedFlowInputProperties

use of org.talend.components.localio.fixedflowinput.FixedFlowInputProperties in project components by Talend.

the class FixedFlowInputRuntimeTest method test_NoOutputRow.

@Test
public void test_NoOutputRow() throws Exception {
    String inputAsString = generateInputJSON(inputSchema, inputIndexedRecord1);
    FixedFlowInputProperties properties = new FixedFlowInputProperties("test");
    properties.init();
    properties.schemaFlow.schema.setValue(inputSchema);
    properties.values.setValue(inputAsString);
    properties.nbRows.setValue(0);
    FixedFlowInputRuntime runtime = new FixedFlowInputRuntime();
    runtime.initialize(null, properties);
    PCollection<IndexedRecord> indexRecords = pipeline.apply(runtime);
    try (DirectCollector<IndexedRecord> collector = DirectCollector.of()) {
        indexRecords.apply(collector);
        // Run the pipeline to fill the collectors.
        pipeline.run().waitUntilFinish();
        ;
        // Validate the contents of the collected outputs.
        List<IndexedRecord> outputs = collector.getRecords();
        assertEquals(0, outputs.size());
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) FixedFlowInputProperties(org.talend.components.localio.fixedflowinput.FixedFlowInputProperties) Test(org.junit.Test)

Example 3 with FixedFlowInputProperties

use of org.talend.components.localio.fixedflowinput.FixedFlowInputProperties in project components by Talend.

the class FixedFlowInputRuntimeTest method test_MultipleInput_NoOutputRow.

@Test
public void test_MultipleInput_NoOutputRow() throws Exception {
    String inputAsString = generateInputJSON(inputSchema, inputIndexedRecord1) + generateInputJSON(inputSchema, inputIndexedRecord2);
    FixedFlowInputProperties properties = new FixedFlowInputProperties("test");
    properties.init();
    properties.schemaFlow.schema.setValue(inputSchema);
    properties.values.setValue(inputAsString);
    properties.nbRows.setValue(0);
    FixedFlowInputRuntime runtime = new FixedFlowInputRuntime();
    runtime.initialize(null, properties);
    PCollection<IndexedRecord> indexRecords = pipeline.apply(runtime);
    try (DirectCollector<IndexedRecord> collector = DirectCollector.of()) {
        indexRecords.apply(collector);
        // Run the pipeline to fill the collectors.
        pipeline.run().waitUntilFinish();
        ;
        // Validate the contents of the collected outputs.
        List<IndexedRecord> outputs = collector.getRecords();
        assertEquals(0, outputs.size());
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) FixedFlowInputProperties(org.talend.components.localio.fixedflowinput.FixedFlowInputProperties) Test(org.junit.Test)

Example 4 with FixedFlowInputProperties

use of org.talend.components.localio.fixedflowinput.FixedFlowInputProperties in project components by Talend.

the class SandboxedFixedFlowInputRuntimeTest method testBasic.

@Test
public void testBasic() throws Exception {
    // The two records to use as values.
    GenericRecord r1 = new GenericData.Record(SampleSchemas.recordSimple());
    r1.put("id", 1);
    r1.put("name", "one");
    GenericRecord r2 = new GenericData.Record(SampleSchemas.recordSimple());
    r2.put("id", 2);
    r2.put("name", "two");
    final FixedFlowInputProperties props = createComponentProperties();
    props.schemaFlow.schema.setValue(SampleSchemas.recordSimple());
    props.values.setValue(r1.toString());
    props.nbRows.setValue(2);
    RuntimeInfo ri = def.getRuntimeInfo(ExecutionEngine.BEAM, props, ConnectorTopology.OUTGOING);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
        RuntimableRuntime<FixedFlowInputProperties> runtime = (RuntimableRuntime<FixedFlowInputProperties>) si.getInstance();
        runtime.initialize(null, props);
    // The functionality of the runtime is tested in its own module.
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) RuntimableRuntime(org.talend.components.api.component.runtime.RuntimableRuntime) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) FixedFlowInputProperties(org.talend.components.localio.fixedflowinput.FixedFlowInputProperties) GenericRecord(org.apache.avro.generic.GenericRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.junit.Test)

Example 5 with FixedFlowInputProperties

use of org.talend.components.localio.fixedflowinput.FixedFlowInputProperties in project components by Talend.

the class FixedFlowInputRuntimeTest method test_OneOutputRow.

@Test
public void test_OneOutputRow() throws Exception {
    String inputAsString = generateInputJSON(inputSchema, inputIndexedRecord1);
    FixedFlowInputProperties properties = new FixedFlowInputProperties("test");
    properties.init();
    properties.schemaFlow.schema.setValue(inputSchema);
    properties.values.setValue(inputAsString);
    properties.nbRows.setValue(1);
    FixedFlowInputRuntime runtime = new FixedFlowInputRuntime();
    runtime.initialize(null, properties);
    PCollection<IndexedRecord> indexRecords = pipeline.apply(runtime);
    try (DirectCollector<IndexedRecord> collector = DirectCollector.of()) {
        indexRecords.apply(collector);
        // Run the pipeline to fill the collectors.
        pipeline.run().waitUntilFinish();
        ;
        // Validate the contents of the collected outputs.
        List<IndexedRecord> outputs = collector.getRecords();
        assertEquals(1, outputs.size());
        assertEquals(inputIndexedRecord1.toString(), outputs.get(0).toString());
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) FixedFlowInputProperties(org.talend.components.localio.fixedflowinput.FixedFlowInputProperties) Test(org.junit.Test)

Aggregations

FixedFlowInputProperties (org.talend.components.localio.fixedflowinput.FixedFlowInputProperties)8 IndexedRecord (org.apache.avro.generic.IndexedRecord)7 Test (org.junit.Test)7 GenericRecord (org.apache.avro.generic.GenericRecord)1 RuntimableRuntime (org.talend.components.api.component.runtime.RuntimableRuntime)1 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)1 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)1