@Override
    public void start() {
        try {
            createAndStartGrpcServer();
        } catch (final IOException e) {
            throw new IllegalStateException("Failed to start the grpc server", e);
        }
    }
@Test
    void testGracefulShutdown() {

        // The server takes 2s seconds to shutdown
        final TestServer server = new TestServer(2000);
        when(this.factory.createServer()).thenReturn(server);

        // And we give it 5s to shutdown
        final GrpcServerLifecycle lifecycle =
                new GrpcServerLifecycle(this.factory, ofMillis(5000), this.eventPublisher);

        lifecycle.start();
        verify(this.eventPublisher).publishEvent(ArgumentMatchers.any(GrpcServerStartedEvent.class));

        assertFalse(server.isShutdown());
        assertFalse(server.isTerminated());

        // So it should finish within 5.1 seconds
        assertTimeout(ofMillis(5100), (Executable) lifecycle::stop);
        verify(this.eventPublisher).publishEvent(ArgumentMatchers.any(GrpcServerShutdownEvent.class));
        verify(this.eventPublisher).publishEvent(ArgumentMatchers.any(GrpcServerTerminatedEvent.class));

        assertTrue(server.isShutdown());
        assertTrue(server.isTerminated());

    }