public void waitUntilFinished() { while ( !isFinished() && !job.isStopped() ) { try { Thread.sleep( 0, 1 ); } catch ( InterruptedException e ) { // Ignore errors } } } }
@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 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 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 ) ); }
@Before public void setUp() throws Exception { parentJob = mock( Job.class ); doReturn( false ).when( parentJob ).isStopped(); jobEntry = new JobEntryWriteToLog(); jobEntry = spy( jobEntry ); }
@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() ); }
public String getStatus() { String message; if ( isActive() ) { if ( isStopped() ) { message = Trans.STRING_HALTING; } else { message = Trans.STRING_RUNNING; } } else if ( isFinished() ) { message = Trans.STRING_FINISHED; if ( getResult().getNrErrors() > 0 ) { message += " (with errors)"; } } else if ( isStopped() ) { message = Trans.STRING_STOPPED; if ( getResult().getNrErrors() > 0 ) { message += " (with errors)"; } } else { message = Trans.STRING_WAITING; } return message; }
@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 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 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(); }
@Before public void setUp() throws Exception { jobEntry = new JobEntryDeleteFiles(); Job parentJob = mock( Job.class ); doReturn( false ).when( parentJob ).isStopped(); jobEntry.setParentJob( parentJob ); JobMeta mockJobMeta = mock( JobMeta.class ); mockNamedClusterEmbedManager = mock( NamedClusterEmbedManager.class ); when( mockJobMeta.getNamedClusterEmbedManager() ).thenReturn( mockNamedClusterEmbedManager ); jobEntry.setParentJobMeta( mockJobMeta ); jobEntry = spy( jobEntry ); doReturn( true ).when( jobEntry ).processFile( anyString(), anyString(), eq( parentJob ) ); }
@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() ); }
LogStatus status; if ( !isActive() ) { if ( isStopped() ) { status = LogStatus.STOP; } else {
private void setupJobMockExecution() { setInternalState( mockedJob, "jobMeta", mockedJobMeta ); setInternalState( mockedJob, "log", mockedLogChannel ); setInternalState( mockedJob, "jobTracker", new JobTracker( mockedJobMeta ) ); setInternalState( mockedJob, "jobEntryListeners", new ArrayList<>( ) ); setInternalState( mockedJob, "jobEntryResults", new LinkedList<>( ) ); setInternalState( mockedJob, "status", new AtomicInteger( 0 ) ); when( mockedJobMeta.findJobEntry( JobMeta.STRING_SPECIAL_START, 0, false ) ).thenReturn( mockedJobEntryCopy ); when( mockedJobEntryCopy.getEntry() ).thenReturn( mockedJobEntrySpecial ); when( mockedJobEntrySpecial.getLogChannel() ).thenReturn( mockedLogChannel ); when( mockedJobEntrySpecial.clone() ).thenReturn( mockedJobEntrySpecial ); when( mockedJob.isStopped() ).thenCallRealMethod(); doCallRealMethod().when( mockedJob ).setStopped( anyBoolean() ); KettleLogStore.init(); }
public Result execute( Result previousResult, int nr ) throws KettleJobException { Result result = previousResult; if ( isStart() ) { try { long sleepTime = getNextExecutionTime(); if ( sleepTime > 0 ) { parentJob.getLogChannel().logBasic( parentJob.getJobname(), "Sleeping: " + ( sleepTime / 1000 / 60 ) + " minutes (sleep time=" + sleepTime + ")" ); long totalSleep = 0L; while ( totalSleep < sleepTime && !parentJob.isStopped() ) { Thread.sleep( 1000L ); totalSleep += 1000L; } } } catch ( InterruptedException e ) { throw new KettleJobException( e ); } result = previousResult; result.setResult( true ); } else if ( isDummy() ) { result = previousResult; } return result; }
final String fileMask = environmentSubstitute( pathToMask.getValue() ); if ( parentJob.isStopped() ) { break;
try { if ( !info.getFile().toString().equals( sourceFolder ) && !parentjob.isStopped() ) {
public void paintControl( PaintEvent event ) { if ( jobGraph.job != null && ( jobGraph.job.isFinished() || jobGraph.job.isStopped() ) ) { refreshImage( event.gc ); if ( image != null && !image.isDisposed() ) { event.gc.drawImage( image, 0, 0 ); } } else { Rectangle bounds = canvas.getBounds(); if ( bounds.width <= 0 || bounds.height <= 0 ) { return; } event.gc.setForeground( GUIResource.getInstance().getColorWhite() ); event.gc.setBackground( GUIResource.getInstance().getColorWhite() ); event.gc.fillRectangle( new Rectangle( 0, 0, bounds.width, bounds.height ) ); event.gc.setForeground( GUIResource.getInstance().getColorBlack() ); String metricsMessage = BaseMessages.getString( PKG, "JobMetricsDelegate.JobIsNotRunning.Message" ); org.eclipse.swt.graphics.Point extent = event.gc.textExtent( metricsMessage ); event.gc.drawText( metricsMessage, ( bounds.width - extent.x ) / 2, ( bounds.height - extent.y ) / 2 ); } } } );
res = execute( nr, result, startpoint, null, BaseMessages.getString( PKG, "Job.Reason.StartOfJobentry" ) ); setActive( false ); } while ( jes.isRepeat() && !isStopped() ); return res;