Permalink
Browse files

Stabilize IT: Add 'cancellable' parameter to SleepRepositoryTask

  • Loading branch information...
1 parent 59ef7a8 commit 18c7bee43bd139a01ec56fc82763a76fced1ffbd @nabcos nabcos committed with cstamas Nov 15, 2012
@@ -22,10 +22,14 @@
extends AbstractNexusRepositoriesTask<Object>
{
+ private boolean cancellable;
+
@Override
protected Object doRun()
throws Exception
{
+ cancellable = Boolean.parseBoolean( getParameter( "cancellable" ) );
+
getLogger().debug( getMessage() );
final int time = getTime();
@@ -41,7 +45,9 @@ protected void sleep( final int time )
for ( int i = 0; i < time; i++ )
{
Thread.sleep( 1000 / 2 );
- checkInterruption();
+ if ( cancellable ) {
+ checkInterruption();
+ }
}
}
@@ -68,7 +74,7 @@ protected String getAction()
@Override
protected String getMessage()
{
- return "Sleeping for " + getTime() + " seconds!";
+ return "Sleeping for " + getTime() + " seconds (cancellable: "+ cancellable + ")!";
}
}
@@ -14,6 +14,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
+import static org.sonatype.nexus.test.utils.TaskScheduleUtil.newProperty;
import java.io.IOException;
import java.util.Collections;
@@ -130,8 +131,10 @@ private ScheduledServiceListResource createTask( String repo )
{
final String taskName = "SleepRepositoryTask_" + repo + "_" + System.nanoTime();
TaskScheduleUtil.runTask( taskName, "SleepRepositoryTask", 0,
- TaskScheduleUtil.newProperty( "repositoryId", repo ),
- TaskScheduleUtil.newProperty( "time", String.valueOf( 50 ) ) );
+ newProperty( "repositoryId", repo ),
+ newProperty( "time", String.valueOf( 50 ) ),
+ newProperty( "cancellable", Boolean.toString( true ) )
+ );
Thread.sleep( 2000 );
@@ -72,6 +72,7 @@ public void testNoUpdateForRunningTasks()
ScheduledServiceListResource running = createTask();
waitForState( running, "RUNNING" );
+ verifyNoUpdate( running );
ScheduledServiceListResource sleeping = createTask();
@@ -80,12 +81,9 @@ public void testNoUpdateForRunningTasks()
verifyNoUpdate( sleeping );
TaskScheduleUtil.cancel( sleeping.getId() );
- verifyNoUpdate( running );
TaskScheduleUtil.cancel( running.getId() );
-
- ScheduledServiceListResource cancelled = TaskScheduleUtil.getTask( running.getName() );
- assertThat( cancelled.getStatus(), is( "CANCELLING" ) );
- verifyNoUpdate( cancelled );
+ waitForState( running, "CANCELLING" );
+ verifyNoUpdate( running );
}
private void waitForState( ScheduledServiceListResource task, String state )

0 comments on commit 18c7bee

Please sign in to comment.