@Override
    public void publishLeaderInformation(String componentId, LeaderInformation leaderInformation) {
        Preconditions.checkState(running.get());

        if (!leaderLatch.hasLeadership()) {
            return;
        }

        final String connectionInformationPath =
                ZooKeeperUtils.generateConnectionInformationPath(componentId);

        LOG.debug(
                "Write leader information {} for component '{}' to {}.",
                leaderInformation,
                componentId,
                ZooKeeperUtils.generateZookeeperPath(
                        curatorFramework.getNamespace(), connectionInformationPath));

        try {
            ZooKeeperUtils.writeLeaderInformationToZooKeeper(
                    leaderInformation,
                    curatorFramework,
                    leaderLatch::hasLeadership,
                    connectionInformationPath);
        } catch (Exception e) {
            leaderElectionListener.onError(e);
        }
    }
@Test
    void testPublishLeaderInformation() throws Exception {
        new Context() {
            {
                runTest(
                        () -> {
                            leaderElectionListener.await(LeaderElectionEvent.IsLeaderEvent.class);

                            final String componentId = "retrieved-component";
                            final DefaultLeaderRetrievalService defaultLeaderRetrievalService =
                                    new DefaultLeaderRetrievalService(
                                            new ZooKeeperLeaderRetrievalDriverFactory(
                                                    curatorFramework.asCuratorFramework(),
                                                    componentId,
                                                    ZooKeeperLeaderRetrievalDriver
                                                            .LeaderInformationClearancePolicy
                                                            .ON_LOST_CONNECTION));

                            final TestingListener leaderRetrievalListener = new TestingListener();
                            defaultLeaderRetrievalService.start(leaderRetrievalListener);

                            final LeaderInformation leaderInformation =
                                    LeaderInformation.known(UUID.randomUUID(), "foobar");
                            leaderElectionDriver.publishLeaderInformation(
                                    componentId, leaderInformation);

                            leaderRetrievalListener.waitForNewLeader();

                            assertThat(leaderRetrievalListener.getLeader())
                                    .isEqualTo(leaderInformation);
                        });
            }
        };
    }