@Test
public void idGeneratorService() throws Throwable {

    HashMap<Long, Long> idCountMap = new HashMap<>();
    setUpMultiNode();
    int totalIds = 200;
    int idCount = 0;
    for (int i = 0; i < totalIds / 2; i++) {
        VerificationHost peer = this.host.getPeerHost();
        Operation get = Operation.createGet(peer, IdGeneratorService.SELF_LINK);
        IdGeneratorService.IdGeneratorResponse state = sender.sendAndWait(
                get, IdGeneratorService.IdGeneratorResponse.class);
        this.host.log(Level.INFO, "ID Response: %d - %s", state.uniqueId, state.documentOwner);
        if (state.uniqueId >= 0) {
            assertFalse(idCountMap.containsKey(state.uniqueId));
            idCountMap.put(state.uniqueId, 0L);
            idCount++;
        }
    }
    for (VerificationHost h : this.host.getInProcessHostMap().values()) {
        h.startService(new IdGeneratorService());
    }
    this.host.stopHost(this.host.getPeerHost());
    VerificationHost host = VerificationHost.create(0);
    host.start();
    host.startFactory(new IdRangeService());
    host.startService(new IdGeneratorService());
    this.host.addPeerNode(host );
    this.host.joinNodesAndVerifyConvergence(this.nodeCount);
    for (int i = 0; i < totalIds / 2; i++) {
        VerificationHost peer1 = this.host.getPeerHost();
        Operation get = Operation.createGet(peer1, IdGeneratorService.SELF_LINK);
        IdGeneratorService.IdGeneratorResponse state = sender.sendAndWait(
                get, IdGeneratorService.IdGeneratorResponse.class);
        this.host.log(Level.INFO, "ID Response: %d - %s", state.uniqueId, state.documentOwner);
        if (state.uniqueId >= 0) {
            assertFalse(idCountMap.containsKey(state.uniqueId));
            idCountMap.put(state.uniqueId, 0L);
            idCount++;
        }
    }
    // Verify that we had enough valid Id generated.
    assertTrue(idCount >= totalIds / 2);
    // Verify new ranges
    for (int i = 0; i < 10; i++) {
        URI uri = UriUtils.buildUri(this.host.getPeerHost(), IdRangeService.FACTORY_LINK);
        uri = UriUtils.extendUri(uri, UriUtils.convertPathCharsFromLink(IdGeneratorService.SELF_LINK));
        Operation get = Operation.createGet(uri);
        IdRangeService.State state = sender.sendAndWait(get, IdRangeService.State.class);
        this.host.log(Level.INFO, "Range: %d - %d", state.minId, state.maxId);
        if (state.minId >= 0) {
            assertFalse(idCountMap.containsKey(state.minId));
            idCountMap.put(state.minId, 0L);
        }
    }
}