Search in sources :

Example 66 with Arrays.asList

use of java.util.Arrays.asList in project pentaho-kettle by pentaho.

the class FixedTimeStreamWindowTest method resultsComeBackToParent.

@Test
public void resultsComeBackToParent() throws KettleException {
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("field"));
    Result mockResult = new Result();
    mockResult.setRows(Arrays.asList(new RowMetaAndData(rowMeta, "queen"), new RowMetaAndData(rowMeta, "king")));
    when(subtransExecutor.execute(any())).thenReturn(Optional.of(mockResult));
    when(subtransExecutor.getPrefetchCount()).thenReturn(10);
    FixedTimeStreamWindow<List> window = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, 0, 2, 1);
    window.buffer(Flowable.fromIterable(singletonList(asList("v1", "v2")))).forEach(result -> assertEquals(mockResult, result));
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 67 with Arrays.asList

use of java.util.Arrays.asList in project pentaho-kettle by pentaho.

the class FixedTimeStreamWindowTest method emptyResultsNotPostProcessed.

@Test
public void emptyResultsNotPostProcessed() throws KettleException {
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("field"));
    Result mockResult = new Result();
    mockResult.setRows(Arrays.asList(new RowMetaAndData(rowMeta, "queen"), new RowMetaAndData(rowMeta, "king")));
    when(subtransExecutor.execute(any())).thenReturn(Optional.empty());
    when(subtransExecutor.getPrefetchCount()).thenReturn(10);
    AtomicInteger count = new AtomicInteger();
    FixedTimeStreamWindow<List> window = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, 0, 2, 1, (p) -> count.set(p.getKey().get(0).size()));
    window.buffer(Flowable.fromIterable(singletonList(asList("v1", "v2")))).forEach(result -> assertEquals(mockResult, result));
    assertEquals(0, count.get());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 68 with Arrays.asList

use of java.util.Arrays.asList in project pentaho-kettle by pentaho.

the class FixedTimeStreamWindowTest method testSharedStreamingBatchPoolExecution.

@Test
public void testSharedStreamingBatchPoolExecution() throws Exception {
    /*
    * Tests that there is only 1 thread running inside the pool at all times.
    * */
    final List<String> errors = new ArrayList<String>();
    // Only 1 thread should be present in the pool at a given time.
    System.setProperty(Const.SHARED_STREAMING_BATCH_POOL_SIZE, "1");
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("field"));
    Result mockResult = new Result();
    mockResult.setRows(Arrays.asList(new RowMetaAndData(rowMeta, "queen"), new RowMetaAndData(rowMeta, "king")));
    FixedTimeStreamWindow<List> window1 = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, 0, 10, 10);
    FixedTimeStreamWindow<List> window2 = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, 0, 10, 10);
    Flowable flowable = Flowable.fromIterable(singletonList(asList("v1", "v2")));
    Field field = window1.getClass().getDeclaredField("sharedStreamingBatchPool");
    field.setAccessible(true);
    ThreadPoolExecutor sharedStreamingBatchPool = (ThreadPoolExecutor) field.get(window1);
    when(subtransExecutor.getPrefetchCount()).thenReturn(1000);
    when(subtransExecutor.execute(any())).thenAnswer((InvocationOnMock invocation) -> {
        // The active count should always be 1.
        if (sharedStreamingBatchPool.getActiveCount() != 1) {
            errors.add("Error: Active count should have been 1 at all times. Current value: " + sharedStreamingBatchPool.getActiveCount());
        }
        return Optional.of(mockResult);
    });
    Thread bufferThread1 = new Thread(new BufferThread(window1, flowable, mockResult));
    bufferThread1.start();
    Thread bufferThread2 = new Thread(new BufferThread(window2, flowable, mockResult));
    bufferThread2.start();
    Thread.sleep(10000);
    assertEquals(0, errors.size());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) BaseMessages.getString(org.pentaho.di.i18n.BaseMessages.getString) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Result(org.pentaho.di.core.Result) Field(java.lang.reflect.Field) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Flowable(io.reactivex.Flowable) Test(org.junit.Test)

Example 69 with Arrays.asList

use of java.util.Arrays.asList in project pentaho-kettle by pentaho.

the class FixedTimeStreamWindowTest method supportsPostProcessing.

@Test
public void supportsPostProcessing() throws KettleException {
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("field"));
    Result mockResult = new Result();
    mockResult.setRows(Arrays.asList(new RowMetaAndData(rowMeta, "queen"), new RowMetaAndData(rowMeta, "king")));
    when(subtransExecutor.execute(any())).thenReturn(Optional.of(mockResult));
    when(subtransExecutor.getPrefetchCount()).thenReturn(10);
    AtomicInteger count = new AtomicInteger();
    FixedTimeStreamWindow<List> window = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, 0, 2, 1, (p) -> count.set(p.getKey().get(0).size()));
    window.buffer(Flowable.fromIterable(singletonList(asList("v1", "v2")))).forEach(result -> assertEquals(mockResult, result));
    assertEquals(2, count.get());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 70 with Arrays.asList

use of java.util.Arrays.asList in project cyclops by aol.

the class SpoutsTest method takeWhile.

@Test
public void takeWhile() {
    assertThat(Spouts.of(1, 2, 3).takeWhile(i -> i < 3).toList(), equalTo(Arrays.asList(1, 2)));
    assertThat(Spouts.<Integer>of().takeWhile(i -> i < 3).toList(), equalTo(Arrays.asList()));
    assertThat(Spouts.range(1, 1_000_000).takeWhile(i -> i < 300_000).toList(), Matchers.equalTo(ReactiveSeq.range(1, 300_000).toList()));
    AtomicInteger count = new AtomicInteger(0);
    int size = Spouts.range(1, 1_000_000).peek(i -> count.incrementAndGet()).takeWhile(i -> i < 300_000).toList().size();
    assertThat(count.get(), Matchers.equalTo(300_000));
    assertThat(size, Matchers.equalTo(299999));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) Tuple2(cyclops.data.tuple.Tuple2) java.util(java.util) QueueFactories(com.oath.cyclops.async.QueueFactories) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Topic(com.oath.cyclops.async.adapters.Topic) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Monoids(cyclops.companion.Monoids) AtomicReference(java.util.concurrent.atomic.AtomicReference) Seq(cyclops.data.Seq) IsCollectionContaining.hasItem(org.hamcrest.core.IsCollectionContaining.hasItem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) Collector(java.util.stream.Collector) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Semigroups(cyclops.companion.Semigroups) Before(org.junit.Before) ReactiveSeq.of(cyclops.reactive.ReactiveSeq.of) Matchers.isOneOf(org.hamcrest.Matchers.isOneOf) ReactiveSubscriber(com.oath.cyclops.types.reactive.ReactiveSubscriber) Executor(java.util.concurrent.Executor) Effect(cyclops.function.Effect) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) LAZY(com.oath.cyclops.types.foldable.Evaluation.LAZY) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Flux(reactor.core.publisher.Flux) AtomicLong(java.util.concurrent.atomic.AtomicLong) Stream(java.util.stream.Stream) ForkJoinPool(java.util.concurrent.ForkJoinPool) Subscription(org.reactivestreams.Subscription) IterableX(com.oath.cyclops.types.traversable.IterableX) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) AsyncSubscriber(com.oath.cyclops.types.reactive.AsyncSubscriber) Assert(org.junit.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

Arrays.asList (java.util.Arrays.asList)73 List (java.util.List)66 ArrayList (java.util.ArrayList)49 Test (org.junit.Test)37 Arrays (java.util.Arrays)22 Collections.singletonList (java.util.Collections.singletonList)20 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)18 Test (org.junit.jupiter.api.Test)15 HashMap (java.util.HashMap)14 Before (org.junit.Before)13 Collection (java.util.Collection)12 Stream (java.util.stream.Stream)10 Method (java.lang.reflect.Method)9 Optional (java.util.Optional)9 Collections (java.util.Collections)8 Collections.emptyList (java.util.Collections.emptyList)8 TopicPartition (org.apache.kafka.common.TopicPartition)8 Employee (com.artezio.arttime.datamodel.Employee)6 HourType (com.artezio.arttime.datamodel.HourType)6