@Test
    public void testKeepsDirectoriesAfterReassignment() {
        PartitionRegistration registration = new PartitionRegistration.Builder().
                setReplicas(new int[]{2, 1, 3}).
                setDirectories(new Uuid[]{
                        Uuid.fromString("v1PVrX6uS5m8CByXlLfmWg"),
                        Uuid.fromString("iU2znv45Q9yQkOpkTSy3jA"),
                        Uuid.fromString("fM5NKyWTQHqEihjIkUl99Q")
                }).
                setIsr(new int[]{2, 1, 3}).
                setLeader(1).
                setLeaderRecoveryState(LeaderRecoveryState.RECOVERED).
                setLeaderEpoch(100).
                setPartitionEpoch(200).
                build();
        Optional<ApiMessageAndVersion> built = new PartitionChangeBuilder(registration, FOO_ID,
                0, r -> true, MetadataVersion.IBP_3_7_IV2, 2).
                setTargetReplicas(Arrays.asList(3, 1, 5, 4)).
                setDirectory(5, Uuid.fromString("RNJ5oFjjSSWMMFRwqdCfJg")).
                setDefaultDirProvider(DEFAULT_DIR_PROVIDER).
                build();
        Optional<ApiMessageAndVersion> expected = Optional.of(new ApiMessageAndVersion(
                new PartitionChangeRecord().
                        setTopicId(FOO_ID).
                        setPartitionId(0).
                        setLeader(1).
                        setReplicas(Arrays.asList(3, 1, 5, 4)).
                        setDirectories(Arrays.asList(
                                Uuid.fromString("fM5NKyWTQHqEihjIkUl99Q"),
                                Uuid.fromString("iU2znv45Q9yQkOpkTSy3jA"),
                                Uuid.fromString("RNJ5oFjjSSWMMFRwqdCfJg"),
                                DirectoryId.UNASSIGNED
                        )),
                (short) 1
        ));
        assertEquals(expected, built);
    }
Regression test for KAFKA-16624. Tests that when targetIsr is the empty list, but we
cannot actually change the ISR, triggerLeaderEpochBumpForIsrShrinkIfNeeded does not engage.
metadata/src/test/java/org/apache/kafka/controller/PartitionChangeBuilderTest.java