public void start() {
        checkState(!closed, "The RPC connection is already closed");
        checkState(
                !isConnected() && pendingRegistration == null,
                "The RPC connection is already started");

        final RetryingRegistration<F, G, S, R> newRegistration = createNewRegistration();

        if (REGISTRATION_UPDATER.compareAndSet(this, null, newRegistration)) {
            newRegistration.startRegistration();
        } else {
            // concurrent start operation
            newRegistration.cancel();
        }
    }
@Test
    void testRpcConnectionRejectionCallsOnRegistrationRejection() {
        TestRegistrationGateway testRegistrationGateway =
                DefaultTestRegistrationGateway.newBuilder()
                        .setRegistrationFunction(
                                (uuid, aLong) ->
                                        CompletableFuture.completedFuture(
                                                new TestRegistrationRejection(
                                                        TestRegistrationRejection.RejectionReason
                                                                .REJECTED)))
                        .build();

        rpcService.registerGateway(testRegistrationGateway.getAddress(), testRegistrationGateway);

        TestRpcConnection connection =
                new TestRpcConnection(
                        testRegistrationGateway.getAddress(),
                        UUID.randomUUID(),
                        rpcService.getScheduledExecutor(),
                        rpcService);
        connection.start();

        final Either<TestRegistrationSuccess, TestRegistrationRejection> connectionResult =
                connection.getConnectionFuture().join();

        assertThat(connectionResult.isRight()).isTrue();
        final TestRegistrationRejection registrationRejection = connectionResult.right();

        assertThat(registrationRejection.getRejectionReason())
                .isEqualTo(TestRegistrationRejection.RejectionReason.REJECTED);
    }