XComp commented on a change in pull request #18844:
URL: https://github.com/apache/flink/pull/18844#discussion_r810127140
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/leaderretrieval/ZooKeeperLeaderRetrievalConnectionHandlingTest.java
##########
@@ -291,55 +271,72 @@ private void writeLeaderInformationToZooKeeper(
@Test
public void testNewLeaderAfterReconnectTriggersListenerNotification()
throws Exception {
- final String retrievalPath =
"/testNewLeaderAfterReconnectTriggersListenerNotification";
+ testWithQueueLeaderElectionListener(
+ queueLeaderElectionListener ->
+ new ZooKeeperLeaderRetrievalDriver(
+ zooKeeperClient,
+
"/testNewLeaderAfterReconnectTriggersListenerNotification",
+ queueLeaderElectionListener,
+
ZooKeeperLeaderRetrievalDriver.LeaderInformationClearancePolicy
+ .ON_SUSPENDED_CONNECTION,
+
fatalErrorHandlerResource.getFatalErrorHandler()),
+ (leaderRetrievalDriver, queueLeaderElectionListener) -> {
+ final String leaderAddress = "foobar";
+ final UUID sessionId = UUID.randomUUID();
+ writeLeaderInformationToZooKeeper(
+
leaderRetrievalDriver.getConnectionInformationPath(),
+ leaderAddress,
+ sessionId);
+
+ // pop new leader
+ queueLeaderElectionListener.next();
+
+ testingServer.stop();
+
+ final CompletableFuture<String> connectionSuspension =
+ queueLeaderElectionListener.next();
+
+ // wait until the ZK connection is suspended
+ connectionSuspension.join();
+
+ testingServer.restart();
+
+ final String newLeaderAddress = "barfoo";
+ final UUID newSessionId = UUID.randomUUID();
+ writeLeaderInformationToZooKeeper(
+
leaderRetrievalDriver.getConnectionInformationPath(),
+ newLeaderAddress,
+ newSessionId);
+
+ // check that we find the new leader information eventually
+ CommonTestUtils.waitUntilCondition(
+ () -> {
+ final CompletableFuture<String>
afterConnectionReconnect =
+ queueLeaderElectionListener.next();
+ return
afterConnectionReconnect.get().equals(newLeaderAddress);
+ },
+ Deadline.fromNow(Duration.ofSeconds(30L)));
+ });
+ }
+
+ private void testWithQueueLeaderElectionListener(
+ FunctionWithException<
+ QueueLeaderElectionListener,
ZooKeeperLeaderRetrievalDriver, Exception>
+ driverFactoryMethod,
+ BiConsumerWithException<
+ ZooKeeperLeaderRetrievalDriver,
QueueLeaderElectionListener, Exception>
+ testCallback)
+ throws Exception {
final QueueLeaderElectionListener queueLeaderElectionListener =
Review comment:
It's not possible (as far as I can see) to create an Extension because
the `ZooKeeperRetrievalDriver` is instantiated differently in every test. But
the `QueueLeaderElectionListener` needs to be cleared before closing the
`ZooKeeperRetrievalDriver`.
But I refactored the test to use junit5/assertj and the
`ZooKeeperExtension`. PTAL
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]