@Test public void testRunSetsResult() throws Exception { when( mockJob.isStopped() ).thenReturn( false ); when( mockJob.getParentJob() ).thenReturn( parentJob ); when( parentJob.isStopped() ).thenReturn( false ); when( mockJob.execute( Mockito.anyInt(), Mockito.any( Result.class ) ) ).thenReturn( mockResult ); jobRunner.run(); verify( mockJob, times( 1 ) ).setResult( Mockito.any( Result.class ) ); }
@Test public void testRunWithExceptionOnExecuteAndFireJobSetsResult() throws KettleException { when( mockJob.isStopped() ).thenReturn( false ); when( mockJob.getParentJob() ).thenReturn( parentJob ); when( parentJob.isStopped() ).thenReturn( false ); when( mockJob.execute( Mockito.anyInt(), Mockito.any( Result.class ) ) ).thenReturn( mockResult ); doThrow( KettleException.class ).when( mockJob ).execute( anyInt(), any( Result.class ) ); doThrow( Exception.class ).when( mockJob ).fireJobFinishListeners(); jobRunner.run(); verify( mockJob, times( 1 ) ).setResult( Mockito.any( Result.class ) ); assertTrue( jobRunner.isFinished() ); }
@Test public void testRunWithExceptionOnExecuteSetsResult() throws Exception { when( mockJob.isStopped() ).thenReturn( false ); when( mockJob.getParentJob() ).thenReturn( parentJob ); when( parentJob.isStopped() ).thenReturn( false ); doThrow( KettleException.class ).when( mockJob ).execute( anyInt(), any( Result.class ) ); jobRunner.run(); verify( mockJob, times( 1 ) ).setResult( Mockito.any( Result.class ) ); }
@Test public void testWaitUntilFinished() throws Exception { when( mockJob.isStopped() ).thenReturn( true ); when( mockJob.getParentJob() ).thenReturn( parentJob ); when( parentJob.isStopped() ).thenReturn( false ); when( mockJob.execute( Mockito.anyInt(), Mockito.any( Result.class ) ) ).thenReturn( mockResult ); jobRunner.waitUntilFinished(); } }
@Test public void testRunWithException() throws Exception { when( mockJob.isStopped() ).thenReturn( false ); when( mockJob.getParentJob() ).thenReturn( parentJob ); when( mockJob.getJobMeta() ).thenReturn( mockJobMeta ); when( parentJob.isStopped() ).thenReturn( false ); doThrow( KettleException.class ).when( mockJob ).execute( anyInt(), any( Result.class ) ); jobRunner.run(); verify( mockResult, times( 1 ) ).setNrErrors( Mockito.anyInt() ); //[PDI-14981] catch more general exception to prevent thread hanging doThrow( Exception.class ).when( mockJob ).fireJobFinishListeners(); jobRunner.run(); }
@Test public void testRunWithExceptionOnFireJobSetsResult() throws KettleException { when( mockJob.isStopped() ).thenReturn( false ); when( mockJob.getParentJob() ).thenReturn( parentJob ); when( parentJob.isStopped() ).thenReturn( false ); when( mockJob.execute( Mockito.anyInt(), Mockito.any( Result.class ) ) ).thenReturn( mockResult ); doThrow( Exception.class ).when( mockJob ).fireJobFinishListeners(); jobRunner.run(); verify( mockJob, times( 1 ) ).setResult( Mockito.any( Result.class ) ); assertTrue( jobRunner.isFinished() ); }
@Test public void testIsFinished() throws Exception { assertFalse( jobRunner.isFinished() ); when( mockJob.isStopped() ).thenReturn( false ); when( mockJob.getParentJob() ).thenReturn( parentJob ); when( parentJob.isStopped() ).thenReturn( false ); when( mockJob.execute( Mockito.anyInt(), Mockito.any( Result.class ) ) ).thenReturn( mockResult ); jobRunner.run(); assertTrue( jobRunner.isFinished() ); }
private void executeWithPreviousResultsTest( boolean repeat ) { setupJobMockExecution(); try { when( mockedJobEntrySpecial.execute( any( Result.class ), anyInt() ) ).thenReturn( new Result( ) ); when( mockedJob.execute( anyInt(), any( Result.class ) ) ).thenCallRealMethod(); when( mockedJobEntrySpecial.isRepeat() ).thenReturn( repeat ); if ( repeat ) { //The job will repeat its execution until it is stopped scheduleStopJobExecution(); } mockedJob.execute( 0, new Result( ) ); //Test expected invocations. If repeat setActive(false) will be called at least twice. With no repeat, only once. verify( mockedJob, repeat ? atLeast( 2 ) : times( 1 ) ).setActive( false ); } catch ( KettleException e ) { Assert.fail( "Could not execute job" ); } }
@Test public void testRun() throws Exception { // Call all the NO-OP paths when( mockJob.isStopped() ).thenReturn( true ); jobRunner.run(); when( mockJob.isStopped() ).thenReturn( false ); when( mockJob.getParentJob() ).thenReturn( null ); when( mockJob.getJobMeta() ).thenReturn( mockJobMeta ); jobRunner.run(); when( parentJob.isStopped() ).thenReturn( true ); when( mockJob.getParentJob() ).thenReturn( parentJob ); jobRunner.run(); when( parentJob.isStopped() ).thenReturn( false ); when( mockJob.execute( Mockito.anyInt(), Mockito.any( Result.class ) ) ).thenReturn( mockResult ); jobRunner.run(); }
res = execute( nr + 1, newResult, nextEntry, jobEntryCopy, nextComment ); } catch ( Throwable e ) { log.logError( Const.getStackTracker( e ) );
Result res; do { res = execute( nr, result, startpoint, null, BaseMessages.getString( PKG, "Job.Reason.StartOfJobentry" ) ); setActive( false ); } while ( jes.isRepeat() && !isStopped() );
result = job.execute( entryNr + 1, result ); } catch ( KettleException e ) { e.printStackTrace();
result = data.executorJob.execute( 0, result ); } catch ( KettleException e ) { log.logError( "An error occurred executing the job: ", e );
result = execute(); } catch ( Throwable je ) { log.logError( BaseMessages.getString( PKG, "Job.Log.ErrorExecJob", je.getMessage() ), je );
while ( ( jes.isRepeat() || isFirst ) && !isStopped() ) { isFirst = false; res = execute( 0, null, startpoint, null, BaseMessages.getString( PKG, "Job.Reason.Started" ) ); BaseMessages.getString( PKG, "Job.Reason.Finished" ), null, 0, null ); } else { res = execute( 0, res, startpoint, null, BaseMessages.getString( PKG, "Job.Reason.Started" ) ); jerEnd = new JobEntryResult( res, startpoint.getEntry().getLogChannel().getLogChannelId(), BaseMessages.getString(