Skip to content

Commit 137701a

Browse files
committed
Also fix MySQL NewlyAddedTableITCase
1 parent 9ab6e3b commit 137701a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/test/java/org/apache/flink/cdc/connectors/mysql/source/MySqlSourceTestBase.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.flink.cdc.connectors.mysql.testutils.MySqlVersion;
2323
import org.apache.flink.cdc.connectors.utils.ExternalResourceProxy;
2424
import org.apache.flink.configuration.Configuration;
25+
import org.apache.flink.runtime.highavailability.nonha.embedded.EmbeddedHaServices;
2526
import org.apache.flink.runtime.highavailability.nonha.embedded.HaLeadershipControl;
2627
import org.apache.flink.runtime.minicluster.MiniCluster;
2728
import org.apache.flink.runtime.minicluster.RpcServiceSharing;
@@ -149,11 +150,22 @@ protected static void triggerFailover(
149150
}
150151
}
151152

153+
protected static void ensureJmLeaderServiceExists(
154+
HaLeadershipControl leadershipControl, JobID jobId) throws Exception {
155+
EmbeddedHaServices control = (EmbeddedHaServices) leadershipControl;
156+
157+
// Make sure JM leader service has been created, or an NPE might be thrown when we're
158+
// triggering JM failover later.
159+
control.getJobManagerLeaderElection(jobId).close();
160+
}
161+
152162
protected static void triggerJobManagerFailover(
153163
JobID jobId, MiniCluster miniCluster, Runnable afterFailAction) throws Exception {
154164
final HaLeadershipControl haLeadershipControl = miniCluster.getHaLeadershipControl().get();
165+
ensureJmLeaderServiceExists(haLeadershipControl, jobId);
155166
haLeadershipControl.revokeJobMasterLeadership(jobId).get();
156167
afterFailAction.run();
168+
ensureJmLeaderServiceExists(haLeadershipControl, jobId);
157169
haLeadershipControl.grantJobMasterLeadership(jobId).get();
158170
}
159171

0 commit comments

Comments
 (0)