final String rejoinReason() {
        return rejoinReason;
    }
@Test
    public void testRejoinReason() {
        setupCoordinator();

        String memberId = "memberId";
        int generation = 5;

        // test initial reason
        mockClient.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
        expectJoinGroup("", "", generation, memberId);

        // successful sync group response should reset reason
        expectSyncGroup(generation, memberId);
        ensureActiveGroup(generation, memberId);
        assertEquals("", coordinator.rejoinReason());

        // force a rebalance
        expectJoinGroup(memberId, "Manual test trigger", generation, memberId);
        expectSyncGroup(generation, memberId);
        coordinator.requestRejoin("Manual test trigger");
        ensureActiveGroup(generation, memberId);
        assertEquals("", coordinator.rejoinReason());

        // max group size reached
        mockClient.prepareResponse(joinGroupFollowerResponse(defaultGeneration, memberId, JoinGroupRequest.UNKNOWN_MEMBER_ID, Errors.GROUP_MAX_SIZE_REACHED));
        coordinator.requestRejoin("Manual test trigger 2");
        Throwable e = assertThrows(GroupMaxSizeReachedException.class,
                () -> coordinator.joinGroupIfNeeded(mockTime.timer(100L)));

        // next join group request should contain exception message
        expectJoinGroup(memberId, String.format("rebalance failed due to %s", e.getClass().getSimpleName()), generation, memberId);
        expectSyncGroup(generation, memberId);
        ensureActiveGroup(generation, memberId);
        assertEquals("", coordinator.rejoinReason());

        // check limit length of reason field
        final String reason = "Very looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong reason that is 271 characters long to make sure that length limit logic handles the scenario nicely";
        final String truncatedReason = reason.substring(0, 255);
        expectJoinGroup(memberId, truncatedReason, generation, memberId);
        expectSyncGroup(generation, memberId);
        coordinator.requestRejoin(reason);
        ensureActiveGroup(generation, memberId);
        assertEquals("", coordinator.rejoinReason());
    }