use of org.talend.daikon.java8.Consumer in project components by Talend.
the class ReaderDataProviderTest method testReaderDataProviderWithLimitTo0.
@Test
public void testReaderDataProviderWithLimitTo0() throws IOException {
Reader<String> reader = spy(new OneTwoReader());
Consumer consumer = mock(Consumer.class);
ReaderDataProvider<String> readerDataProvider = new ReaderDataProvider<>(reader, 0, consumer);
readerDataProvider.retrieveData();
verify(consumer, never()).accept(any());
verify(reader, times(1)).close();
}
use of org.talend.daikon.java8.Consumer in project components by Talend.
the class ReaderDataProviderTest method testReaderDataProviderWithException.
@Test
public void testReaderDataProviderWithException() throws IOException {
Reader<String> reader = mock(Reader.class);
Consumer consumer = mock(Consumer.class);
ReaderDataProvider<String> readerDataProvider = new ReaderDataProvider<>(reader, 100, consumer);
// reader start throws an IOE
when(reader.start()).thenThrow(new IOException());
try {
readerDataProvider.retrieveData();
fail("the code above should have thrown an exception");
} catch (TalendRuntimeException tre) {
// expected exception
verify(reader, times(1)).close();
}
// reader getCurrent throws an IOE
reset(reader);
when(reader.start()).thenReturn(true);
when(reader.getCurrent()).thenThrow(new NoSuchElementException());
try {
readerDataProvider.retrieveData();
fail("the code above should have thrown an exception");
} catch (TalendRuntimeException tre) {
// expected exception
verify(reader, times(1)).close();
}
// reader close throws an IOE
reset(reader);
when(reader.start()).thenReturn(false);
doThrow(new IOException()).when(reader).close();
try {
readerDataProvider.retrieveData();
fail("the code above should have thrown an exception");
} catch (TalendRuntimeException tre) {
// expected exception
}
}
use of org.talend.daikon.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 org.talend.daikon.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 org.talend.daikon.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