@Test
public void failMigrationWhenSourceFactoryNotAvailable() throws Throwable {

    // this test dirties destination host, requires clean up
    clearSourceAndDestInProcessPeers = true;
    URI factoryUri = UriUtils.buildUri(getSourceHost(), ExampleService.FACTORY_LINK);
    this.host.waitForReplicatedFactoryServiceAvailable(factoryUri);
    // set factory availability on factory owner to false
    for (VerificationHost h : this.host.getInProcessHostMap().values()) {
        Utils.setFactoryAvailabilityIfOwner(h, ExampleService.FACTORY_LINK,
                ServiceUriPaths.DEFAULT_NODE_SELECTOR, false);
    }
    // Wait for factory to be not available
    waitForReplicatedFactoryServiceNotAvailable(getSourceHost(), factoryUri,
            ServiceUriPaths.DEFAULT_NODE_SELECTOR);
    // Kick-off migration
    MigrationTaskService.State migrationState = validMigrationState(ExampleService.FACTORY_LINK);
    Operation op = Operation.createPost(this.destinationFactoryUri)
            .setBody(migrationState)
            .setReferer(this.host.getUri());
    String selfLink = getDestinationHost().getTestRequestSender().sendAndWait(op)
            .getBody(State.class).documentSelfLink;
    // Wait for the migration task to fail
    State waitForServiceCompletion = waitForServiceCompletion(selfLink, getDestinationHost());
    assertEquals(waitForServiceCompletion.taskInfo.stage, TaskStage.FAILED);
    // Verify that it failed because of factory service availability check
    assertTrue("Invalid message received: " + waitForServiceCompletion.taskInfo.failure.message,
            waitForServiceCompletion.taskInfo.failure.message.contains(
            "Failed to verify availability of source factory service"));
}