ShardedJobSettings settings =
new ShardedJobSettings.Builder().setSliceTimeoutMillis(0).build();
final String jobId = startNewTask(settings);
//Run task
final TaskStateInfo taskFromQueue = grabNextTaskFromQueue(queueName);
assertEquals(0, getShardRetryCount(taskFromQueue));
SettableFuture<Void> result = runInNewThread(taskFromQueue);
assertEquals(1, StaticBlockingTask.timesRun.get());
ShardedJobState state = service.getJobState(jobId);
assertEquals(new Status(RUNNING), state.getStatus());
assertEquals(1, state.getActiveTaskCount());
assertEquals(1, state.getTotalTaskCount());
assertEquals("Something was left in the queue", 0, getTasks(queueName).size());
assertEquals(0, getShardRetryCount(taskFromQueue));
//Duplicate task
executeTask(jobId, taskFromQueue); //Should not block because will not execute run.
assertEquals(1, getShardRetryCount(taskFromQueue));
state = service.getJobState(jobId);
assertEquals(new Status(RUNNING), state.getStatus());
assertEquals(1, state.getActiveTaskCount());
assertEquals(1, state.getTotalTaskCount());
assertEquals(1, StaticBlockingTask.timesRun.get());
//First task completion should not update state
IncrementalTaskState<IncrementalTask> taskState = lookupTaskState(taskFromQueue);
StaticBlockingTask.finishRun.release();
result.get();
assertAreEqual(taskState, lookupTaskState(taskFromQueue));
state = service.getJobState(jobId);
assertEquals(new Status(RUNNING), state.getStatus());
//Run next task in queue (Which is a re-try of the shard)
TaskStateInfo retry = grabNextTaskFromQueue(queueName);
result = runInNewThread(retry);
assertEquals(2, StaticBlockingTask.timesRun.get());
state = service.getJobState(jobId);
assertEquals(new Status(RUNNING), state.getStatus());
assertEquals(1, state.getActiveTaskCount());