Search in sources :

Example 1 with FixedDatasetProperties

use of org.talend.components.localio.fixed.FixedDatasetProperties in project components by Talend.

the class SandboxedFixedInputRuntimeTest method testDatasetGetSample.

@Test
public void testDatasetGetSample() 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 FixedDatasetProperties props = createComponentProperties().getDatasetProperties();
    props.format.setValue(FixedDatasetProperties.RecordFormat.AVRO);
    props.schema.setValue(SampleSchemas.recordSimple().toString());
    props.values.setValue(r1.toString() + r2.toString());
    final List<IndexedRecord> consumed = new ArrayList<>();
    RuntimeInfo ri = new FixedDatasetDefinition().getRuntimeInfo(props);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
        DatasetRuntime<FixedDatasetProperties> runtime = (DatasetRuntime<FixedDatasetProperties>) si.getInstance();
        runtime.initialize(null, props);
        // The functionality of the runtime is tested in its own module.
        runtime.getSample(100, new Consumer<IndexedRecord>() {

            @Override
            public void accept(IndexedRecord ir) {
                consumed.add(ir);
            }
        });
    }
    assertThat(consumed, hasSize(2));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) DatasetRuntime(org.talend.components.common.dataset.runtime.DatasetRuntime) ArrayList(java.util.ArrayList) SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) FixedDatasetDefinition(org.talend.components.localio.fixed.FixedDatasetDefinition) GenericRecord(org.apache.avro.generic.GenericRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) FixedDatasetProperties(org.talend.components.localio.fixed.FixedDatasetProperties) Test(org.junit.Test)

Example 2 with FixedDatasetProperties

use of org.talend.components.localio.fixed.FixedDatasetProperties in project components by Talend.

the class FixedDatasetRuntimeTest method testBasic.

@Test
public void testBasic() {
    // 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 FixedDatasetProperties props = createComponentProperties().getDatasetProperties();
    props.format.setValue(FixedDatasetProperties.RecordFormat.AVRO);
    props.schema.setValue(SampleSchemas.recordSimple().toString());
    props.values.setValue(r1.toString() + r2.toString());
    FixedDatasetRuntime runtime = new FixedDatasetRuntime();
    runtime.initialize(null, props);
    // Get the two records.
    final List<IndexedRecord> consumed = new ArrayList<>();
    runtime.getSample(100, new Consumer<IndexedRecord>() {

        @Override
        public void accept(IndexedRecord ir) {
            consumed.add(ir);
        }
    });
    assertThat(consumed, hasSize(2));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) ArrayList(java.util.ArrayList) GenericRecord(org.apache.avro.generic.GenericRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) FixedDatasetProperties(org.talend.components.localio.fixed.FixedDatasetProperties) Test(org.junit.Test)

Example 3 with FixedDatasetProperties

use of org.talend.components.localio.fixed.FixedDatasetProperties in project components by Talend.

the class FixedInputRuntimeTest method createComponentProperties.

/**
 * @return the properties for this component fully initialized with the default values.
 */
public static FixedInputProperties createComponentProperties() {
    FixedDatastoreProperties datastoreProps = new FixedDatastoreProperties(null);
    datastoreProps.init();
    FixedDatasetProperties datasetProps = new FixedDatasetProperties(null);
    datasetProps.init();
    datasetProps.setDatastoreProperties(datastoreProps);
    FixedInputProperties componentProps = new FixedInputProperties(null);
    componentProps.init();
    componentProps.setDatasetProperties(datasetProps);
    return componentProps;
}
Also used : FixedDatastoreProperties(org.talend.components.localio.fixed.FixedDatastoreProperties) FixedDatasetProperties(org.talend.components.localio.fixed.FixedDatasetProperties) FixedInputProperties(org.talend.components.localio.fixed.FixedInputProperties)

Example 4 with FixedDatasetProperties

use of org.talend.components.localio.fixed.FixedDatasetProperties in project components by Talend.

the class SandboxedFixedInputRuntimeTest method createComponentProperties.

/**
 * @return the properties for this component fully initialized with the default values.
 */
public static FixedInputProperties createComponentProperties() {
    FixedDatastoreProperties datastoreProps = new FixedDatastoreProperties(null);
    datastoreProps.init();
    FixedDatasetProperties datasetProps = new FixedDatasetProperties(null);
    datasetProps.init();
    datasetProps.setDatastoreProperties(datastoreProps);
    FixedInputProperties componentProps = new FixedInputProperties(null);
    componentProps.init();
    componentProps.setDatasetProperties(datasetProps);
    return componentProps;
}
Also used : FixedDatastoreProperties(org.talend.components.localio.fixed.FixedDatastoreProperties) FixedDatasetProperties(org.talend.components.localio.fixed.FixedDatasetProperties) FixedInputProperties(org.talend.components.localio.fixed.FixedInputProperties)

Aggregations

FixedDatasetProperties (org.talend.components.localio.fixed.FixedDatasetProperties)4 ArrayList (java.util.ArrayList)2 GenericRecord (org.apache.avro.generic.GenericRecord)2 IndexedRecord (org.apache.avro.generic.IndexedRecord)2 Test (org.junit.Test)2 FixedDatastoreProperties (org.talend.components.localio.fixed.FixedDatastoreProperties)2 FixedInputProperties (org.talend.components.localio.fixed.FixedInputProperties)2 DatasetRuntime (org.talend.components.common.dataset.runtime.DatasetRuntime)1 FixedDatasetDefinition (org.talend.components.localio.fixed.FixedDatasetDefinition)1 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)1 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)1