@Test
public void successTaskRestartedByMaintenance() throws Throwable {

    // create object in host
    List<ExampleServiceState> states = createExampleDocuments(this.exampleSourceFactory, getSourceHost(),
            this.serviceCount);
    long expectedUpdateTime = states.stream().map(state -> state.documentUpdateTimeMicros).max(Long::compareTo).get();
    // start migration
    MigrationTaskService.State migrationState = validMigrationState(ExampleService.FACTORY_LINK);
    // start the task as canceled to make sure it does not do anything
    migrationState.taskInfo = TaskState.createAsCancelled();
    migrationState.continuousMigration = Boolean.TRUE;
    getDestinationHost().setMaintenanceIntervalMicros(migrationState.maintenanceIntervalMicros / 10);
    Operation op = Operation.createPost(this.destinationFactoryUri).setBody(migrationState);
    State state = this.sender.sendAndWait(op, State.class);
    Set<TaskStage> finalStages = new HashSet<>(Arrays.asList(TaskStage.FAILED, TaskStage.FINISHED));
    State finalServiceState = waitForServiceCompletion(state.documentSelfLink, getDestinationHost(), finalStages);
    assertEquals(TaskStage.FINISHED, finalServiceState.taskInfo.stage);
    // check stats
    ServiceStats stats = getStats(state.documentSelfLink, getDestinationHost());
    long processedDocuments = (long) stats.entries.get(MigrationTaskService.STAT_NAME_PROCESSED_DOCUMENTS).latestValue;
    boolean processed = this.serviceCount <= processedDocuments;
    assertTrue(format("%d <= %d", this.serviceCount, processedDocuments), processed);
    assertEquals(Long.valueOf(expectedUpdateTime), finalServiceState.latestSourceUpdateTimeMicros);
    // check if object is in new host
    List<URI> uris = getFullUri(getDestinationHost(), states);
    getDestinationHost().getServiceState(EnumSet.noneOf(TestProperty.class),
            ExampleServiceState.class, uris);
}