OrcOutput extends BaseStep implements StepInterface { @Override public synchronized boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException { try { meta = (OrcOutputMeta) smi; data = (OrcOutputData) sdi; if ( data.output == null ) { init(); } Object[] currentRow = getRow(); if ( currentRow != null ) { RowMetaInterface outputRMI = new RowMeta(); Object[] outputData = new Object[ meta.getOutputFields().size() ]; for ( int i = 0; i < meta.getOutputFields().size(); i++ ) { int inputRowIndex = getInputRowMeta().indexOfValue( meta.getOutputFields().get( i ).getPentahoFieldName() ); if ( inputRowIndex == -1 ) { throw new KettleException( "Field name [" + meta.getOutputFields().get( i ).getPentahoFieldName() + " ] couldn't be found in the input stream!" ); } else { ValueMetaInterface vmi = ValueMetaFactory.cloneValueMeta( getInputRowMeta().getValueMeta( inputRowIndex ) ); outputRMI.addValueMeta( i, vmi ); outputData[ i ] = currentRow[ inputRowIndex ]; } } RowMetaAndData row = new RowMetaAndData( outputRMI, outputData ); data.writer.write( row ); putRow( row.getRowMeta(), row.getData() ); return true; } else { closeWriter(); pvfsFileAliaser.copyFileToFinalDestination(); pvfsFileAliaser.deleteTempFileAndFolder(); setOutputDone(); return false; } } catch ( IllegalStateException e ) { getLogChannel().logError( e.getMessage() ); setErrors( 1 ); pvfsFileAliaser.deleteTempFileAndFolder(); setOutputDone(); return false; } catch ( KettleException ex ) { throw ex; } catch ( Exception ex ) { throw new KettleException( ex ); } } OrcOutput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
                    Trans trans ); @Override synchronized boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void init(); void closeWriter(); boolean init( StepMetaInterface smi, StepDataInterface sdi );  }
@Test public void testProcessRow() throws Exception { boolean result; int rowsProcessed = 0; ArgumentCaptor<RowMeta> rowMetaCaptor = ArgumentCaptor.forClass( RowMeta.class ); ArgumentCaptor<Object[]> dataCaptor = ArgumentCaptor.forClass( Object[].class ); do { result = orcOutput.processRow( orcOutputMeta, orcOutputData ); if ( result ) { rowsProcessed++; } } while ( result ); assertEquals( 3, rowsProcessed ); verify( mockRowHandler, times( 3 ) ).putRow( rowMetaCaptor.capture(), dataCaptor.capture() ); List<RowMeta> rowMetaCaptured = rowMetaCaptor.getAllValues(); List<Object[]> dataCaptured = dataCaptor.getAllValues(); for ( int rowNum = 0; rowNum < 3; rowNum++ ) { assertEquals( 0, rowMetaCaptured.get( rowNum ).indexOfValue( "StringName" ) ); assertEquals( "string" + ( rowNum % 3 + 1 ), dataCaptured.get( rowNum )[ 0 ] ); } }
@Test public void testProcessRowIllegalState() throws Exception { doThrow( new IllegalStateException( "IllegalStateExceptionMessage" ) ).when( mockPentahoOrcOutputFormat ) .setOutputFile( anyString(), anyBoolean() ); when( orcOutput.getLogChannel() ).thenReturn( mockLogChannelInterface ); assertFalse( orcOutput.processRow( orcOutputMeta, orcOutputData ) ); verify( mockLogChannelInterface, times( 1 ) ).logError( "IllegalStateExceptionMessage" ); }
@Test public void testAliasFile() throws Exception { String aliasPath = Files.createTempDirectory( "testAliasFile" ) + File.separator + "dummyFile"; new File( aliasPath ).createNewFile(); when( mockPentahoOrcOutputFormat.generateAlias( anyString() ) ).thenReturn( aliasPath ); boolean result; int rowsProcessed = 0; ArgumentCaptor<RowMeta> rowMetaCaptor = ArgumentCaptor.forClass( RowMeta.class ); ArgumentCaptor<Object[]> dataCaptor = ArgumentCaptor.forClass( Object[].class ); do { result = orcOutput.processRow( orcOutputMeta, orcOutputData ); if ( result ) { rowsProcessed++; } } while ( result ); assertEquals( 3, rowsProcessed ); verify( mockRowHandler, times( 3 ) ).putRow( rowMetaCaptor.capture(), dataCaptor.capture() ); List<RowMeta> rowMetaCaptured = rowMetaCaptor.getAllValues(); List<Object[]> dataCaptured = dataCaptor.getAllValues(); for ( int rowNum = 0; rowNum < 3; rowNum++ ) { assertEquals( 0, rowMetaCaptured.get( rowNum ).indexOfValue( "StringName" ) ); assertEquals( "string" + ( rowNum % 3 + 1 ), dataCaptured.get( rowNum )[ 0 ] ); } assertFalse( new File( aliasPath ).exists() ); File outputFile = new File( OUTPUT_FILE_NAME ); assertTrue( outputFile.exists() ); outputFile.delete(); }