use of org.talend.components.localio.fixed.FixedDatasetDefinition 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));
}
Aggregations