Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made tests a little more robust regarding the asynchronous nature of …

…certain method calls. Also make the service wait a little longer to allow running tasks to be properly cancelled.
  • Loading branch information...
commit db6f064c859630ae709a70ca599f196b0452559d 1 parent 9b12c2d
@jawi authored
View
5 ...execution/src/main/java/nl/lxtreme/ols/task/execution/BackgroundTaskExecutionService.java
@@ -81,7 +81,7 @@ public void close()
{
try
{
- if ( this.executorService.awaitTermination( 100L, TimeUnit.MILLISECONDS ) )
+ if ( this.executorService.awaitTermination( 500L, TimeUnit.MILLISECONDS ) )
{
LOG.fine( "All running threads are terminated ..." );
}
@@ -93,7 +93,7 @@ public void close()
}
}
- LOG.info( "Background task execution service closed ..." );
+ LOG.fine( "Background task execution service closed ..." );
}
/**
@@ -127,6 +127,7 @@ public RESULT_TYPE call() throws Exception
}
catch ( Exception exception )
{
+ LOG.log( Level.FINE, "Task execution failed!", exception );
this.tsl.taskFailed( aTask, exception );
throw exception;
}
View
10 ...ution/src/test/java/nl/lxtreme/ols/task/execution/BackgroundTaskExecutionServiceTest.java
@@ -104,7 +104,7 @@ public void tearDown() throws Exception
@Test( expected = CancellationException.class )
public void testExecuteCancelOk() throws Exception
{
- final Task<Object> task = createMockTask( 200 );
+ final Task<Object> task = createMockTask( 500 );
// Test whether the callback methods are called in the correct order...
InOrder inOrder = inOrder( this.mockTaskStatusListener );
@@ -115,6 +115,8 @@ public void testExecuteCancelOk() throws Exception
future.cancel( true /* mayInterruptIfRunning */);
+ sleep( 50 ); // sleep long enough to allow callbacks to be invoked...
+
inOrder.verify( this.mockTaskStatusListener ).taskStarted( eq( task ) );
inOrder.verify( this.mockTaskStatusListener ).taskFailed( eq( task ), Matchers.<Exception> any() );
inOrder.verifyNoMoreInteractions();
@@ -131,7 +133,7 @@ public void testExecuteCancelOk() throws Exception
@Test( expected = ExecutionException.class )
public void testExecuteCloseCancelsRunningToolsOk() throws Exception
{
- final Task<Object> task = createMockTask( 200 );
+ final Task<Object> task = createMockTask( 500 );
// Test whether the callback methods are called in the correct order...
InOrder inOrder = inOrder( this.mockTaskStatusListener );
@@ -142,6 +144,8 @@ public void testExecuteCloseCancelsRunningToolsOk() throws Exception
this.service.close();
+ sleep( 50 ); // sleep long enough to allow callbacks to be invoked...
+
inOrder.verify( this.mockTaskStatusListener ).taskStarted( eq( task ) );
inOrder.verify( this.mockTaskStatusListener ).taskFailed( eq( task ), Matchers.<Exception> any() );
inOrder.verifyNoMoreInteractions();
@@ -169,6 +173,8 @@ public void testExecuteCloseOk() throws Exception
this.service.close();
+ sleep( 50 ); // sleep long enough to allow callbacks to be invoked...
+
inOrder.verify( this.mockTaskStatusListener ).taskStarted( eq( task ) );
inOrder.verify( this.mockTaskStatusListener ).taskEnded( eq( task ), anyObject() );
inOrder.verifyNoMoreInteractions();
Please sign in to comment.
Something went wrong with that request. Please try again.