use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.
the class KafkaDatasetTestIT method testBasic.
@Test
public void testBasic() throws Exception {
KafkaDatasetProperties props = createDatasetProperties();
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(0));
}
use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.
the class KafkaDatasetProperties method beforeTopic.
public ValidationResult beforeTopic() {
KafkaDatasetDefinition definition = new KafkaDatasetDefinition();
RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this);
try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) {
IKafkaDatasetRuntime runtime = (IKafkaDatasetRuntime) sandboxedInstance.getInstance();
runtime.initialize(null, this);
this.topic.setPossibleValues(new ArrayList(runtime.listTopic()));
return ValidationResult.OK;
} catch (Exception e) {
return new ValidationResult(new ComponentException(e));
}
}
use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.
the class PubSubDatasetProperties method beforeSubscription.
public ValidationResult beforeSubscription() {
PubSubDatasetDefinition definition = new PubSubDatasetDefinition();
RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this);
try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) {
IPubSubDatasetRuntime runtime = (IPubSubDatasetRuntime) sandboxedInstance.getInstance();
runtime.initialize(null, this);
List<NamedThing> topics = new ArrayList<>();
for (String topicName : runtime.listSubscriptions()) {
topics.add(new SimpleNamedThing(topicName, topicName));
}
subscription.setPossibleValues(topics);
return ValidationResult.OK;
} catch (Exception e) {
return new ValidationResult(new ComponentException(e));
}
}
use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.
the class S3DatasetProperties method afterRegion.
public void afterRegion() {
refreshLayout(getForm(Form.MAIN));
S3DatasetDefinition definition = new S3DatasetDefinition();
RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this);
try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) {
IS3DatasetRuntime runtime = (IS3DatasetRuntime) sandboxedInstance.getInstance();
runtime.initialize(null, this);
this.bucket.setPossibleValues(new ArrayList<String>(runtime.listBuckets()));
} catch (Exception e) {
TalendRuntimeException.build(ComponentsErrorCode.IO_EXCEPTION, e).throwIt();
}
}
use of org.talend.daikon.sandbox.SandboxedInstance 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.
}
}
Aggregations