Search in sources :

Example 1 with Consumer

use of org.talend.daikon.java8.Consumer in project components by Talend.

the class JDBCDatasetOracleTestIT 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(new BigDecimal("1"), record[0].get(0));
    Assert.assertEquals("wangwei", record[0].get(1));
}
Also used : JDBCDatasetRuntime(org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime) IndexedRecord(org.apache.avro.generic.IndexedRecord) Consumer(org.talend.daikon.java8.Consumer) BigDecimal(java.math.BigDecimal)

Example 2 with Consumer

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));
}
Also used : JDBCDatasetRuntime(org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime) IndexedRecord(org.apache.avro.generic.IndexedRecord) Consumer(org.talend.daikon.java8.Consumer)

Example 3 with Consumer

use of org.talend.daikon.java8.Consumer in project components by Talend.

the class ReaderDataProviderTest method testReaderDataProviderWithLimitTo1.

@Test
public void testReaderDataProviderWithLimitTo1() throws IOException {
    Reader<String> reader = spy(new OneTwoReader());
    Consumer consumer = mock(Consumer.class);
    ReaderDataProvider<String> readerDataProvider = new ReaderDataProvider<>(reader, 1, consumer);
    readerDataProvider.retrieveData();
    verify(consumer).accept("1");
    verify(consumer, times(1)).accept(any());
    verify(reader, times(1)).close();
}
Also used : Consumer(org.talend.daikon.java8.Consumer) Test(org.junit.Test)

Example 4 with Consumer

use of org.talend.daikon.java8.Consumer in project components by Talend.

the class ReaderDataProviderTest method testReaderDataProviderWithRecords.

@Test
public void testReaderDataProviderWithRecords() throws IOException {
    Reader<String> reader = spy(new OneTwoReader());
    Consumer consumer = mock(Consumer.class);
    ReaderDataProvider<String> readerDataProvider = new ReaderDataProvider<>(reader, 100, consumer);
    readerDataProvider.retrieveData();
    verify(consumer).accept("1");
    verify(consumer).accept("2");
    verify(consumer, times(2)).accept(any());
    verify(reader, times(1)).close();
}
Also used : Consumer(org.talend.daikon.java8.Consumer) Test(org.junit.Test)

Example 5 with Consumer

use of org.talend.daikon.java8.Consumer in project components by Talend.

the class ReaderDataProviderTest method testProviderEmptyReader.

@Test
public void testProviderEmptyReader() throws IOException {
    Reader readerMock = mock(Reader.class);
    when(readerMock.start()).thenReturn(false);
    Consumer consumer = mock(Consumer.class);
    ReaderDataProvider<Object> readerDataProvider = new ReaderDataProvider<>(readerMock, 100, consumer);
    readerDataProvider.retrieveData();
    verify(consumer, times(0)).accept(any());
    verify(readerMock, times(1)).close();
}
Also used : Consumer(org.talend.daikon.java8.Consumer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 Consumer (org.talend.daikon.java8.Consumer)10 Consumer (com.urbanairship.connect.java8.Consumer)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 StartPosition (com.urbanairship.connect.client.model.request.StartPosition)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 Mockito.doAnswer (org.mockito.Mockito.doAnswer)7 Answer (org.mockito.stubbing.Answer)7 JsonObject (com.google.gson.JsonObject)6 IndexedRecord (org.apache.avro.generic.IndexedRecord)5 ArrayList (java.util.ArrayList)4 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)4 JDBCDatasetRuntime (org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 StreamQueryDescriptor (com.urbanairship.connect.client.model.StreamQueryDescriptor)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1