void waitUntilFinished( Trans injectTrans ) { injectTrans.waitUntilFinished(); }
protected void executeTrans( Trans trans ) throws KettleException { trans.prepareExecution( null ); trans.startThreads(); trans.waitUntilFinished(); }
private void waitUntilFinished( Trans trans, final long waitMillis ) { if ( trans != null && trans.isRunning() ) { trans.waitUntilFinished(); for ( int i = 0; i < 100; i++ ) { if ( !trans.isRunning() ) { break; } try { Thread.sleep( waitMillis ); } catch ( Exception e ) { break; } } } } }
/** If the transformation has at least one step in a transformation, which writes it's data straight to a servlet output we should wait transformation's termination. Otherwise the servlet's response lifecycle may come to an end and the response will be closed by container while the transformation will be still trying writing data into it. */ @VisibleForTesting void finishProcessing( Trans trans, PrintWriter out ) { if ( trans.getSteps().stream().anyMatch( step -> step.meta.passDataToServletOutput() ) ) { trans.waitUntilFinished(); } else { WebResult webResult = new WebResult( WebResult.STRING_OK, "Transformation started", trans.getContainerObjectId() ); out.println( webResult.getXML() ); out.flush(); } }
@Override public void run() { try { start.await(); } catch ( InterruptedException e ) { throw new RuntimeException(); } // run while ( !isStopped() ) { try { tr.fireTransFinishedListeners(); // clean array blocking queue tr.waitUntilFinished(); } catch ( KettleException e ) { throw new RuntimeException(); } } } }
public Optional<Result> execute( List<RowMetaAndData> rows ) throws KettleException { if ( rows.isEmpty() || stopped ) { return Optional.empty(); } Trans subtrans = this.createSubtrans(); running.add( subtrans ); parentTrans.addActiveSubTransformation( subTransName, subtrans ); // Pass parameter values passParametersToTrans( subtrans, rows.get( 0 ) ); Result result = new Result(); result.setRows( rows ); subtrans.setPreviousResult( result ); subtrans.prepareExecution( this.parentTrans.getArguments() ); List<RowMetaAndData> rowMetaAndData = new ArrayList<>(); subtrans.getSteps().stream() .filter( c -> c.step.getStepname().equalsIgnoreCase( subStep ) ) .findFirst() .ifPresent( c -> c.step.addRowListener( new RowAdapter() { @Override public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) { rowMetaAndData.add( new RowMetaAndData( rowMeta, row ) ); } } ) ); subtrans.startThreads(); subtrans.waitUntilFinished(); updateStatuses( subtrans ); running.remove( subtrans ); Result subtransResult = subtrans.getResult(); subtransResult.setRows( rowMetaAndData ); return Optional.of( subtransResult ); }
@Test public void testFinishProcessingTransWithServletOutputSteps() throws Exception { StepMetaDataCombi stepMetaDataCombi = new StepMetaDataCombi(); StepMetaInterface stepMeta = mock( StepMetaInterface.class ); when( stepMeta.passDataToServletOutput() ).thenReturn( true ); stepMetaDataCombi.meta = stepMeta; stepList.add( stepMetaDataCombi ); doAnswer( new Answer<Void>() { @Override public Void answer( InvocationOnMock invocation ) throws Throwable { Thread.currentThread().sleep( 2000 ); return null; } } ).when( trans ).waitUntilFinished(); runTransServlet.finishProcessing( trans, out ); assertTrue( outData.toString().isEmpty() ); }
@Test public void testDispose() throws KettleException { // Set Up TransMock to return the error when( stepMockHelper.trans.getErrors() ).thenReturn( 0 ); // The step has been already finished when( stepMockHelper.trans.isFinished() ).thenReturn( Boolean.FALSE ); // The step was started simpleMpData.wasStarted = true; smp = new SimpleMapping( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); smp.init( stepMockHelper.initStepMetaInterface, simpleMpData ); smp.dispose( stepMockHelper.processRowsStepMetaInterface, simpleMpData ); verify( stepMockHelper.trans, times( 1 ) ).isFinished(); verify( stepMockHelper.trans, times( 1 ) ).waitUntilFinished(); verify( stepMockHelper.trans, times( 1 ) ).removeActiveSubTransformation( anyString() ); }
@Before public void setUp() throws Exception { executor = StepMockUtil.getStep( TransExecutor.class, TransExecutorMeta.class, "TransExecutorUnitTest" ); executor = spy( executor ); TransMeta internalTransMeta = mock( TransMeta.class ); doReturn( internalTransMeta ).when( executor ).loadExecutorTransMeta(); internalTrans = spy( new Trans() ); internalTrans.setLog( mock( LogChannelInterface.class ) ); doNothing().when( internalTrans ).prepareExecution( any( String[].class ) ); doNothing().when( internalTrans ).startThreads(); doNothing().when( internalTrans ).waitUntilFinished(); doNothing().when( executor ).discardLogLines( any( TransExecutorData.class ) ); doReturn( internalTrans ).when( executor ).createInternalTrans(); internalResult = new Result(); doReturn( internalResult ).when( internalTrans ).getResult(); meta = new TransExecutorMeta(); data = new TransExecutorData(); }
@Test public void testStepShouldProcessError_WhenMappingTransHasError() throws KettleException { // Set Up TransMock to return the error int errorCount = 1; when( stepMockHelper.trans.getErrors() ).thenReturn( errorCount ); // The step has been already finished when( stepMockHelper.trans.isFinished() ).thenReturn( Boolean.TRUE ); // The step was started simpleMpData.wasStarted = true; smp = new SimpleMapping( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); smp.init( stepMockHelper.initStepMetaInterface, simpleMpData ); smp.dispose( stepMockHelper.processRowsStepMetaInterface, simpleMpData ); verify( stepMockHelper.trans, times( 1 ) ).isFinished(); verify( stepMockHelper.trans, never() ).waitUntilFinished(); verify( stepMockHelper.trans, never() ).addActiveSubTransformation( anyString(), any( Trans.class ) ); verify( stepMockHelper.trans, times( 1 ) ).removeActiveSubTransformation( anyString() ); verify( stepMockHelper.trans, never() ).getActiveSubTransformation( anyString() ); verify( stepMockHelper.trans, times( 1 ) ).getErrors(); assertTrue( "The step contains the errors", smp.getErrors() == errorCount ); }
@Test public void doesNotWriteRowOnTimeWhenStopped() throws KettleException, InterruptedException { TransMeta transMeta = new TransMeta( getClass().getResource( "safe-stop.ktr" ).getPath() ); Trans trans = new Trans( transMeta ); trans.prepareExecution( new String[] {} ); trans.getSteps().get( 1 ).step.addRowListener( new RowAdapter() { @Override public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException { trans.safeStop(); } } ); trans.startThreads(); trans.waitUntilFinished(); assertEquals( 1, trans.getSteps().get( 0 ).step.getLinesWritten() ); assertEquals( 1, trans.getSteps().get( 1 ).step.getLinesRead() ); } }
trans.waitUntilFinished(); if ( trans.getErrors() > 0 ) { StringBuffer log = KettleLogStore.getAppender().getBuffer( trans.getLogChannelId(), false );
public void dispose( StepMetaInterface smi, StepDataInterface sdi ) { // Close the running transformation if ( getData().wasStarted ) { if ( !getData().mappingTrans.isFinished() ) { // Wait until the child transformation has finished. getData().mappingTrans.waitUntilFinished(); } // Remove it from the list of active sub-transformations... // getTrans().removeActiveSubTransformation( getStepname() ); // See if there was an error in the sub-transformation, in that case, flag error etc. if ( getData().mappingTrans.getErrors() > 0 ) { logError( BaseMessages.getString( PKG, "SimpleMapping.Log.ErrorOccurredInSubTransformation" ) ); setErrors( 1 ); } } super.dispose( smi, sdi ); }
public void dispose( StepMetaInterface smi, StepDataInterface sdi ) { // Close the running transformation if ( getData().wasStarted ) { if ( !getData().mappingTrans.isFinished() ) { // Wait until the child transformation has finished. getData().getMappingTrans().waitUntilFinished(); } // Remove it from the list of active sub-transformations... // getTrans().removeActiveSubTransformation( getStepname() ); // See if there was an error in the sub-transformation, in that case, flag error etc. if ( getData().getMappingTrans().getErrors() > 0 ) { logError( BaseMessages.getString( PKG, "Mapping.Log.ErrorOccurredInSubTransformation" ) ); setErrors( 1 ); } } super.dispose( smi, sdi ); }
executorTrans.waitUntilFinished();
getData().getMappingTrans().waitUntilFinished();
simpleMappingData.mappingTrans.waitUntilFinished(); setOutputDone(); return false;