use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.
the class AbstractMultiRuntimeComponentTests method testMultiRuntimeComponentRuntime.
@Test
public void testMultiRuntimeComponentRuntime() throws Exception {
MultiRuntimeComponentDefinition def = (MultiRuntimeComponentDefinition) getComponentService().getComponentDefinition(MultiRuntimeComponentDefinition.COMPONENT_NAME);
MultiRuntimeComponentProperties props = (MultiRuntimeComponentProperties) getComponentService().getComponentProperties(MultiRuntimeComponentDefinition.COMPONENT_NAME);
props.version.setValue(Version.VERSION_0_1);
try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(def.getRuntimeInfo(ExecutionEngine.DI, props, ConnectorTopology.OUTGOING), props.getClass().getClassLoader())) {
Source source = (Source) sandboxedInstance.getInstance();
source.initialize(null, props);
assertEquals("Me", source.validate(null).getMessage());
}
props.version.setValue(Version.VERSION_0_2);
try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(def.getRuntimeInfo(ExecutionEngine.DI, props, ConnectorTopology.OUTGOING), props.getClass().getClassLoader())) {
Source source2 = (Source) sandboxedInstance.getInstance();
source2.initialize(null, props);
assertEquals("AnotherMe", source2.validate(null).getMessage());
}
}
use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.
the class BigQueryDatasetProperties method beforeBqDataset.
public ValidationResult beforeBqDataset() {
BigQueryDatasetDefinition definition = new BigQueryDatasetDefinition();
RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this);
try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) {
IBigQueryDatasetRuntime runtime = (IBigQueryDatasetRuntime) sandboxedInstance.getInstance();
runtime.initialize(null, this);
List<NamedThing> datasets = new ArrayList<>();
for (String dataset : runtime.listDatasets()) {
datasets.add(new SimpleNamedThing(dataset, dataset));
}
bqDataset.setPossibleValues(datasets);
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 BigQueryDatasetProperties method beforeTableName.
public void beforeTableName() {
BigQueryDatasetDefinition definition = new BigQueryDatasetDefinition();
RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this);
try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) {
IBigQueryDatasetRuntime runtime = (IBigQueryDatasetRuntime) sandboxedInstance.getInstance();
runtime.initialize(null, this);
List<NamedThing> tables = new ArrayList<>();
for (String table : runtime.listTables()) {
tables.add(new SimpleNamedThing(table, table));
}
this.tableName.setPossibleValues(tables);
} catch (Exception e) {
TalendRuntimeException.build(CommonErrorCodes.UNEXPECTED_EXCEPTION).setAndThrow(e.getMessage());
}
}
use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.
the class ElasticsearchDatastoreTestIT method testBasic.
@Test
public void testBasic() throws Exception {
ElasticsearchDatastoreProperties props = createDatastoreProperties();
RuntimeInfo ri = def.getRuntimeInfo(props);
try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
DatastoreRuntime runtime = (DatastoreRuntime) si.getInstance();
runtime.initialize(null, props);
assertThat(runtime, not(nullValue()));
Iterator iterator = runtime.doHealthChecks(null).iterator();
assertTrue(iterator.hasNext());
assertEquals(ValidationResult.OK, iterator.next());
}
}
use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.
the class BigQueryDatasetTestIT method testBasic.
@Test
public void testBasic() throws Exception {
BigQueryDatasetProperties props = createDatasetProperties();
props.sourceType.setValue(SourceType.QUERY);
props.query.setValue("SELECT * FROM [bigquery-public-data:samples.shakespeare] LIMIT 1");
props.useLegacySql.setValue(true);
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));
}
Aggregations