@Test
public void synchronizationServiceNotFoundOnNewOwner() throws Throwable {

    this.isPeerSynchronizationEnabled = false;
    setUp(this.nodeCount);
    this.host.joinNodesAndVerifyConvergence(this.host.getPeerCount());
    this.host.setNodeGroupQuorum(this.nodeCount);
    this.host.waitForNodeGroupConvergence(this.nodeCount);
    VerificationHost peer = this.host.getPeerHost();
    List<URI> exampleUris = this.host.createExampleServices(peer, this.serviceCount * 5, null);
    List<ServiceHost> inMemoryHosts = new ArrayList<>();
    this.host.getInProcessHostMap().values().forEach(h -> inMemoryHosts.add(h));
    // Add a new host
    this.host.testStart(1);
    VerificationHost newHost = this.host.setUpLocalPeerHost(
            0, peer.getMaintenanceIntervalMicros(), inMemoryHosts);
    this.host.testWait();
    List<URI> peerUris = new ArrayList<>();
    peerUris.add(peer.getUri());
    newHost.joinPeers(peerUris, ServiceUriPaths.DEFAULT_NODE_GROUP);
    this.host.setNodeGroupQuorum(this.nodeCount + 1);
    this.host.waitForNodeGroupConvergence(this.nodeCount + 1);
    // Find the services that should be owned by the new host we added.
    List<URI> filteredUris = exampleUris.stream()
            .filter(u -> newHost.isOwner(u.getPath(), this.replicationNodeSelector))
            .collect(Collectors.toList());
    if (filteredUris.size() == 0) {
        // Consistent hashing is un-predictable. Despite that we create
        // serviceCount * 5 services, it is still possible that the fourth
        // host added does not own any of the services.
        this.host.log("New host does not own any service.");
        return;
    }
    // Patch the documents that are owned by the new host. Since none of these
    // documents exist on the new-host on-demand synch should kick-in and PATCHes
    // should succeed.
    if (filteredUris.size() > 1) {
        TestContext ctx = this.host.testCreate(filteredUris.size() - 1);
        int i = 0;
        for (; i < filteredUris.size() / 2; i++) {
            URI exampleUri = filteredUris.get(i);
            ExampleServiceState state = new ExampleServiceState();
            state.name = UUID.randomUUID().toString();
            state.counter = 100L;
            Operation patchOp = Operation
                    .createPatch(exampleUri)
                    .setBody(state)
                    .setReferer(this.host.getUri())
                    .setCompletion(ctx.getCompletion());
            this.host.send(patchOp);
        }
        // Test scenario when the service URI ends with the utility path (i.e. examples/example1/stats).
        // On-demand sync should strip utility path from the end of the uri and then
        // synchronize the child service.
        for (; i < filteredUris.size(); i++) {
            URI exampleUri = UriUtils.buildStatsUri(filteredUris.get(i));
            Operation patchOp = Operation
                    .createGet(exampleUri)
                    .setReferer(this.host.getUri())
                    .setCompletion(ctx.getCompletion());
            this.host.send(patchOp);
        }
        ctx.await();
    }
}