@Test
    public void testPassLeadership() throws Exception {
        try (
            LocalLogManagerTestEnv env = new LocalLogManagerTestEnv.Builder(3).
                    buildWithMockListeners()
        ) {
            LeaderAndEpoch first = env.waitForLeader();
            LeaderAndEpoch cur = first;
            do {
                int currentLeaderId = cur.leaderId().orElseThrow(() ->
                    new AssertionError("Current leader is undefined")
                );
                env.logManagers().get(currentLeaderId).resign(cur.epoch());

                LeaderAndEpoch next = env.waitForLeader();
                while (next.epoch() == cur.epoch()) {
                    Thread.sleep(1);
                    next = env.waitForLeader();
                }
                long expectedNextEpoch = cur.epoch() + 2;
                assertEquals(expectedNextEpoch, next.epoch(), "Expected next epoch to be " + expectedNextEpoch +
                    ", but found  " + next);
                cur = next;
            } while (cur.leaderId().equals(first.leaderId()));
            env.close();
            assertNull(env.firstError.get());
        }
    }
Test that we can pass leadership back and forth between log managers.
metadata/src/test/java/org/apache/kafka/metalog/LocalLogManagerTest.java