Skip to content

Commit

Permalink
[hotfix][mysql] Fix failed test LegacyMySqlSourceTest#testSnapshotOnF…
Browse files Browse the repository at this point in the history
…ailedSource (apache#2384)

* [hotfix][mysql] fix failed test LegacyMySqlSourceTest#testSnapshotOnFailedSource

* [hotfix][mysql] fix failed test LegacyMySqlSourceTest#testSnapshotOnFailedSource

(cherry picked from commit b8f468e)
  • Loading branch information
ruanhang1993 authored and zhongqishang committed Dec 7, 2023
1 parent 0717756 commit 22da1e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.ververica.cdc.debezium.internal;

import org.apache.flink.annotation.Internal;
import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.util.ExceptionUtils;

import io.debezium.engine.ChangeEvent;
Expand Down Expand Up @@ -223,4 +224,9 @@ public static boolean isGentlyClosedException(Throwable cause) {
&& GENTLY_CLOSED_MESSAGE.equals(((ClosedException) cause).getMessage());
}
}

@VisibleForTesting
public Object getLock() {
return lock;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1028,15 +1028,22 @@ public void go() throws Exception {
assertTrue(historyState.list.size() > 0);
assertTrue(offsetState.list.size() > 0);

// Step-3: mock the engine stop due to underlying debezium exception, trigger a
// checkpoint on failed source
final Handover handover = source.getHandover();
handover.reportError(new DebeziumException("Mocked debezium exception"));
handover.close();
try {
synchronized (sourceContext.getCheckpointLock()) {
// trigger checkpoint-2
source.snapshotState(new StateSnapshotContextSynchronousImpl(102, 102));
// Here need handover's lock to make sure the error will not be sent by method
// pollNext()
// before the method snapshotState() is invoked
synchronized (handover.getLock()) {
// Step-3: mock the engine stop due to underlying debezium exception,
// trigger a
// checkpoint on failed source
handover.reportError(new DebeziumException("Mocked debezium exception"));
handover.close();
synchronized (sourceContext.getCheckpointLock()) {
// trigger checkpoint-2
source.snapshotState(new StateSnapshotContextSynchronousImpl(102, 102));
}
handover.getLock().notifyAll();
}
fail("Should fail.");
} catch (Exception e) {
Expand Down

0 comments on commit 22da1e2

Please sign in to comment.