use of org.talend.components.common.dataset.runtime.DatasetRuntime in project components by Talend.
the class SandboxedSimpleFileIODatasetRuntimeTest method testBasic.
@Test
public void testBasic() throws Exception {
File input = folder.newFile("stuff.csv");
try (FileWriter fw = new FileWriter(input)) {
fw.write("1;one");
}
SimpleFileIODatasetProperties props = createDatasetProperties();
props.path.setValue(input.toURI().toString());
final List<IndexedRecord> consumed = new ArrayList<>();
RuntimeInfo ri = def.getRuntimeInfo(props);
try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
DatasetRuntime runtime = (DatasetRuntime) si.getInstance();
runtime.initialize(null, props);
assertThat(runtime, not(nullValue()));
Schema s = runtime.getSchema();
assertThat(s, not(nullValue()));
runtime.getSample(100, new Consumer<IndexedRecord>() {
@Override
public void accept(IndexedRecord ir) {
consumed.add(ir);
}
});
}
assertThat(consumed, hasSize(1));
assertThat(consumed.get(0).get(0), is((Object) "1"));
assertThat(consumed.get(0).get(1), is((Object) "one"));
}
use of org.talend.components.common.dataset.runtime.DatasetRuntime in project components by Talend.
the class SimpleFileIODatasetRuntimeTest method testBasic.
@Test
public void testBasic() throws Exception {
File input = folder.newFile("stuff.csv");
try (FileWriter fw = new FileWriter(input)) {
fw.write("1;one");
}
SimpleFileIODatasetProperties props = createDatasetProperties();
props.path.setValue(input.toURI().toString());
final List<IndexedRecord> consumed = new ArrayList<>();
RuntimeInfo ri = def.getRuntimeInfo(props);
try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
DatasetRuntime runtime = (DatasetRuntime) si.getInstance();
runtime.initialize(null, props);
assertThat(runtime, not(nullValue()));
Schema s = runtime.getSchema();
assertThat(s, not(nullValue()));
runtime.getSample(100, new Consumer<IndexedRecord>() {
@Override
public void accept(IndexedRecord ir) {
consumed.add(ir);
}
});
}
assertThat(consumed, hasSize(1));
assertThat(consumed.get(0).get(0), is((Object) "1"));
assertThat(consumed.get(0).get(1), is((Object) "one"));
}
use of org.talend.components.common.dataset.runtime.DatasetRuntime in project components by Talend.
the class JDBCDatasetProperties method updateSchema.
public void updateSchema() {
JDBCDatasetDefinition definition = new JDBCDatasetDefinition();
RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this);
try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) {
DatasetRuntime<JDBCDatasetProperties> runtime = (DatasetRuntime) sandboxedInstance.getInstance();
runtime.initialize(null, this);
Schema schema = runtime.getSchema();
main.schema.setValue(schema);
}
}
Aggregations