@Test
public void testIsAvailableStatAndSuffix() throws Throwable {

    long c = 1;
    URI factoryURI = UriUtils.buildFactoryUri(this.host, ExampleService.class);
    String name = UUID.randomUUID().toString();
    ExampleServiceState s = new ExampleServiceState();
    s.name = name;
    Consumer<Operation> bodySetter = (o) -> {
        o.setBody(s);
    };
    Map<URI, ExampleServiceState> states = this.host.doFactoryChildServiceStart(null, c,
            ExampleServiceState.class, bodySetter, factoryURI);
    // first verify that service that do not explicitly use the setAvailable method,
    // appear available. Both a factory and a child service
    this.host.waitForServiceAvailable(factoryURI);
    // expect 200 from /factory/<child>/available
    TestContext ctx = testCreate(states.size());
    for (URI u : states.keySet()) {
        Operation get = Operation.createGet(UriUtils.buildAvailableUri(u))
                .setCompletion(ctx.getCompletion());
        this.host.send(get);
    }
    testWait(ctx);
    // verify that PUT on /available can make it switch to unavailable (503)
    ServiceStat body = new ServiceStat();
    body.name = Service.STAT_NAME_AVAILABLE;
    body.latestValue = 0.0;
    Operation put = Operation.createPut(
            UriUtils.buildAvailableUri(this.host, factoryURI.getPath()))
            .setBody(body);
    this.host.sendAndWaitExpectSuccess(put);
    // verify factory now appears unavailable
    Operation get = Operation.createGet(UriUtils.buildAvailableUri(factoryURI));
    this.host.sendAndWaitExpectFailure(get);
    // verify PUT on child services makes them unavailable
    ctx = testCreate(states.size());
    for (URI u : states.keySet()) {
        put = put.clone().setUri(UriUtils.buildAvailableUri(u))
                .setBody(body)
                .setCompletion(ctx.getCompletion());
        this.host.send(put);
    }
    testWait(ctx);
    // expect 503 from /factory/<child>/available
    ctx = testCreate(states.size());
    for (URI u : states.keySet()) {
        get = get.clone().setUri(UriUtils.buildAvailableUri(u))
                .setCompletion(ctx.getExpectedFailureCompletion());
        this.host.send(get);
    }
    testWait(ctx);
    // now validate a stateful service that is in memory, and explicitly calls setAvailable
    // sometime after it starts
    Service service = this.host.startServiceAndWait(new SetAvailableValidationService(),
            UUID.randomUUID().toString(), new ExampleServiceState());
    // verify service is NOT available, since we have not yet poked it, to become available
    get = Operation.createGet(UriUtils.buildAvailableUri(service.getUri()));
    this.host.sendAndWaitExpectFailure(get);
    // send a PATCH to this special test service, to make it switch to available
    Operation patch = Operation.createPatch(service.getUri())
            .setBody(new ExampleServiceState());
    this.host.sendAndWaitExpectSuccess(patch);
    // verify service now appears available
    get = Operation.createGet(UriUtils.buildAvailableUri(service.getUri()));
    this.host.sendAndWaitExpectSuccess(get);
}