Search in sources :

Example 6 with Consumer

use of com.urbanairship.connect.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 7 with Consumer

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

Example 8 with Consumer

use of com.urbanairship.connect.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 9 with Consumer

use of com.urbanairship.connect.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 10 with Consumer

use of com.urbanairship.connect.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)13 Consumer (org.talend.daikon.java8.Consumer)10 Consumer (com.urbanairship.connect.java8.Consumer)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 StartPosition (com.urbanairship.connect.client.model.request.StartPosition)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 Mockito.doAnswer (org.mockito.Mockito.doAnswer)6 Answer (org.mockito.stubbing.Answer)6 JsonObject (com.google.gson.JsonObject)5 IndexedRecord (org.apache.avro.generic.IndexedRecord)5 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)4 ArrayList (java.util.ArrayList)3 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