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));
}
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());
}
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());
}
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());
}
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));
}
Aggregations