use of com.urbanairship.connect.java8.Consumer in project components by Talend.
the class SimpleFileIODatasetRuntimeTest method testGetSampleCsv_multipleSources.
@Test
public void testGetSampleCsv_multipleSources() throws Exception {
RecordSet rs1 = getSimpleTestData(0);
writeRandomCsvFile(mini.getFs(), "/user/test/input/part-00000", rs1);
RecordSet rs2 = getSimpleTestData(100);
writeRandomCsvFile(mini.getFs(), "/user/test/input/part-00001", rs2);
RecordSet rs3 = getSimpleTestData(100);
writeRandomCsvFile(mini.getFs(), "/user/test/input/part-00002", rs3);
String fileSpec = mini.getFs().getUri().resolve("/user/test/input/").toString();
// Configure the component.
SimpleFileIODatasetProperties props = createDatasetProperties();
props.format.setValue(SimpleFileIOFormat.CSV);
props.path.setValue(fileSpec);
// Create the runtime.
SimpleFileIODatasetRuntime runtime = new SimpleFileIODatasetRuntime();
runtime.initialize(null, props);
// Attempt to get a sample using the runtime methods.
{
final List<IndexedRecord> actual = new ArrayList<>();
runtime.getSample(15, new Consumer<IndexedRecord>() {
@Override
public void accept(IndexedRecord ir) {
actual.add(ir);
}
});
// Check that the result was limited (15 out of 30 records)
assertThat(actual, hasSize(15));
}
// Run it again to verify that the static state is not retained.
{
final List<IndexedRecord> actual = new ArrayList<>();
runtime.getSample(15, new Consumer<IndexedRecord>() {
@Override
public void accept(IndexedRecord ir) {
actual.add(ir);
}
});
assertThat(actual, hasSize(15));
}
}
use of com.urbanairship.connect.java8.Consumer in project components by Talend.
the class JDBCDatasetTestIT method getSampleAction.
private void getSampleAction(JDBCDatasetProperties dataset) {
JDBCDatasetRuntime runtime = new JDBCDatasetRuntime();
runtime.initialize(null, dataset);
final IndexedRecord[] record = new IndexedRecord[1];
Consumer<IndexedRecord> storeTheRecords = new Consumer<IndexedRecord>() {
@Override
public void accept(IndexedRecord data) {
record[0] = data;
}
};
runtime.getSample(1, storeTheRecords);
Assert.assertEquals("1", record[0].get(0));
Assert.assertEquals("wangwei", record[0].get(1));
}
use of com.urbanairship.connect.java8.Consumer in project components by Talend.
the class SalesforceDatasetRuntimeTestIT method testGetSampleWithRelationshipQuery.
@Test
public void testGetSampleWithRelationshipQuery() {
SalesforceDatastoreDefinition def = new SalesforceDatastoreDefinition();
SalesforceDatastoreProperties datastore = new SalesforceDatastoreProperties("datastore");
CommonTestUtils.setValueForDatastoreProperties(datastore);
SalesforceDatasetProperties dataset = (SalesforceDatasetProperties) def.createDatasetProperties(datastore);
dataset.sourceType.setValue(SalesforceDatasetProperties.SourceType.SOQL_QUERY);
dataset.query.setValue("SELECT Account.Name from Contact");
SalesforceDatasetRuntime runtime = new SalesforceDatasetRuntime();
runtime.initialize(null, dataset);
final IndexedRecord[] record = new IndexedRecord[1];
Consumer<IndexedRecord> storeTheRecords = new Consumer<IndexedRecord>() {
@Override
public void accept(IndexedRecord data) {
record[0] = data;
}
};
runtime.getSample(1, storeTheRecords);
Assert.assertTrue("empty result", record.length > 0);
Assert.assertNotNull(record[0].getSchema().getField("Account_Name"));
}
Aggregations