showuon commented on code in PR #15732: URL: https://github.com/apache/kafka/pull/15732#discussion_r1572018203
########## metadata/src/test/java/org/apache/kafka/metadata/migration/KRaftMigrationDriverTest.java: ########## @@ -881,10 +937,18 @@ public List<List<ApiMessageAndVersion>> recordBatches() { new LeaderAndEpoch(OptionalInt.of(3000), 1)).build()); TestUtils.waitForCondition(() -> driver.migrationState().get(1, TimeUnit.MINUTES).equals(MigrationDriverState.DUAL_WRITE), - "Waiting for KRaftMigrationDriver to enter ZK_MIGRATION state"); + "Waiting for KRaftMigrationDriver to enter DUAL_WRITE state"); assertEquals(expectedBatchCount, batchesPassedToController.size()); assertEquals(expectedRecordCount, batchesPassedToController.stream().mapToInt(List::size).sum()); } } + + // Wait until the driver has recovered MigrationState From ZK. This is to simulate the driver needs to be installed as the metadata publisher + // so that it can receive onControllerChange (KRaftLeaderEvent) and onMetadataUpdate (MetadataChangeEvent) events. + private void startAndWaitForRecoveringMigrationStateFromZK(KRaftMigrationDriver driver) throws InterruptedException { + driver.start(); + TestUtils.waitForCondition(() -> driver.migrationState().get(1, TimeUnit.MINUTES).equals(MigrationDriverState.INACTIVE), + "Waiting for KRaftMigrationDriver to enter INACTIVE state"); Review Comment: This is necessary now because in the test suite, we might invoke `onControllerChange` to append `KRaftLeaderEvent` before the `RecoverMigrationStateFromZKEvent` is appended. This won't happen in practice because the driver needs to wait until `RecoverMigrationStateFromZKEvent` completed to register metadata publisher to receive `KRaftLeaderEvent` and `MetadataChangeEvent`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org