/** * Output is done. * * @return true, if successful */ public boolean outputIsDone() { int nrstopped = 0; outputRowSetsLock.readLock().lock(); try { for ( RowSet rs : outputRowSets ) { if ( rs.isDone() ) { nrstopped++; } } return nrstopped >= outputRowSets.size(); } finally { outputRowSetsLock.readLock().unlock(); } }
@Override public boolean canProcessOneRow() { inputRowSetsLock.readLock().lock(); try { switch ( inputRowSets.size() ) { case 0: return false; case 1: RowSet set = inputRowSets.get( 0 ); if ( set.isDone() ) { return false; } return set.size() > 0; default: boolean allDone = true; for ( RowSet rowSet : inputRowSets ) { if ( !rowSet.isDone() ) { allDone = false; } if ( rowSet.size() > 0 ) { return true; } } return !allDone; } } finally { inputRowSetsLock.readLock().unlock(); } }
public RowSet getMockInputRowSet( final List<Object[]> rows ) { final AtomicInteger index = new AtomicInteger( 0 ); RowSet rowSet = mock( RowSet.class, Mockito.RETURNS_MOCKS ); Answer<Object[]> answer = new Answer<Object[]>() { @Override public Object[] answer( InvocationOnMock invocation ) throws Throwable { int i = index.getAndIncrement(); return i < rows.size() ? rows.get( i ) : null; } }; when( rowSet.getRowWait( anyLong(), any( TimeUnit.class ) ) ).thenAnswer( answer ); when( rowSet.getRow() ).thenAnswer( answer ); when( rowSet.isDone() ).thenAnswer( new Answer<Boolean>() { @Override public Boolean answer( InvocationOnMock invocation ) throws Throwable { return index.get() >= rows.size(); } } ); return rowSet; }
if ( data.inputs.hasNext() && data.readerRowSet.isDone() ) { try ( InputStream nextIn = data.inputs.next() ) {
public static List<Object[]> execute( BaseStep step, StepMetaInterface meta, StepDataInterface data, int expectedRowsAmount, boolean checkIsDone ) throws Exception { RowSet output = new BlockingRowSet( Math.max( 1, expectedRowsAmount ) ); step.setOutputRowSets( Collections.singletonList( output ) ); int i = 0; List<Object[]> result = new ArrayList<>( expectedRowsAmount ); while ( step.processRow( meta, data ) && i < expectedRowsAmount ) { Object[] row = output.getRowImmediate(); assertNotNull( Integer.toString( i ), row ); result.add( row ); i++; } assertEquals( "The amount of executions should be equal to expected", expectedRowsAmount, i ); if ( checkIsDone ) { assertTrue( output.isDone() ); } return result; }
@Test public void testProcessRow() throws KettleException { GroupByMeta groupByMeta = mock( GroupByMeta.class ); GroupByData groupByData = mock( GroupByData.class ); GroupBy groupBySpy = Mockito.spy( new GroupBy( mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans ) ); doReturn( null ).when( groupBySpy ).getRow(); doReturn( null ).when( groupBySpy ).getInputRowMeta(); RowMetaInterface rowMeta = new RowMeta(); rowMeta.addValueMeta( new ValueMetaInteger( "ROWNR" ) ); List<RowSet> outputRowSets = new ArrayList<RowSet>(); BlockingRowSet rowSet = new BlockingRowSet( 1 ); rowSet.putRow( rowMeta, new Object[] { new Long( 0 ) } ); outputRowSets.add( rowSet ); groupBySpy.setOutputRowSets( outputRowSets ); final String[] sub = { "b" }; doReturn( sub ).when( groupByMeta ).getSubjectField(); final String[] groupField = { "a" }; doReturn( groupField ).when( groupByMeta ).getGroupField(); final String[] aggFields = { "b_g" }; doReturn( aggFields ).when( groupByMeta ).getAggregateField(); final int[] aggType = { GroupByMeta.TYPE_GROUP_CONCAT_COMMA }; doReturn( aggType ).when( groupByMeta ).getAggregateType(); when( mockHelper.transMeta.getPrevStepFields( mockHelper.stepMeta ) ).thenReturn( new RowMeta() ); groupBySpy.processRow( groupByMeta, groupByData ); assertTrue( groupBySpy.getOutputRowSets().get( 0 ).isDone() ); }
Mockito.when( rowSet.getDestinationStepCopy() ).thenReturn( 0 ); Mockito.when( rowSet.getRow() ).thenReturn( new String[] { values } ).thenReturn( null ); Mockito.when( rowSet.isDone() ).thenReturn( true ); RowMetaInterface allowedRowMeta = Mockito.mock( RowMetaInterface.class ); Mockito.when( rowSet.getRowMeta() ).thenReturn( allowedRowMeta );
@Test public void testProcessBinaryInput() throws KettleException { StringOperations step = new StringOperations( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans ); step.addRowSetToInputRowSets( mockInputRowSet() ); RowSet outputRowSet = new QueueRowSet(); step.addRowSetToOutputRowSets( outputRowSet ); StringOperationsMeta meta = mockStepMeta(); StringOperationsData data = mockStepData(); step.init( meta, data ); boolean processResult; do { processResult = step.processRow( meta, data ); } while ( processResult ); Assert.assertTrue( outputRowSet.isDone() ); Assert.assertTrue( "Unexpected output", verifyOutput( new Object[][] { { "Value" } }, outputRowSet ) ); } }