@Test
public void create() throws Throwable {

    ServiceHost h = ServiceHost.create("--port=0");
    try {
        h.start();
        h.startDefaultCoreServicesSynchronously();
        // Start the example service factory
        h.startFactory(ExampleService.class, ExampleService::createFactory);
        boolean[] isReady = new boolean[1];
        h.registerForServiceAvailability((o, e) -> {
            isReady[0] = true;
        }, ExampleService.FACTORY_LINK);
        Duration timeout = Duration.of(ServiceHost.ServiceHostState.DEFAULT_MAINTENANCE_INTERVAL_MICROS * 5, ChronoUnit.MICROS);
        TestContext.waitFor(timeout, () -> {
            return isReady[0];
        }, "ExampleService did not start");
        // verify ExampleService exists
        TestRequestSender sender = new TestRequestSender(h);
        Operation get = Operation.createGet(h, ExampleService.FACTORY_LINK);
        sender.sendAndWait(get);
    } finally {
        if (h != null) {
            h.unregisterRuntimeShutdownHook();
            h.stop();
        }
    }
}