Skip to content

Commit de90b73

Browse files
author
François Delbrayelle
committed
fix: attempt to fix tests
1 parent 7b63225 commit de90b73

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

plugin-debezium-postgres/src/test/java/io/kestra/plugin/debezium/postgres/CaptureTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void run() throws Exception {
6363
.port(Property.ofValue("65432"))
6464
.database(Property.ofValue("postgres"))
6565
.pluginName(Property.ofValue(PostgresInterface.PluginName.PGOUTPUT))
66+
.stateName(Property.ofValue("debezium-state-" + IdUtils.create()))
6667
// SSL is disabled or we cannot test triggers which are very important for Debezium
6768
// .sslMode(TestUtils.sslMode())
6869
// .sslRootCert(TestUtils.ca())

plugin-debezium-postgres/src/test/java/io/kestra/plugin/debezium/postgres/PostgresDebeziumTestHelper.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.kestra.plugin.debezium.AbstractDebeziumTask;
1313

1414
import java.sql.SQLException;
15+
import java.util.Arrays;
1516
import java.util.concurrent.Callable;
1617

1718
final class PostgresDebeziumTestHelper {
@@ -40,14 +41,14 @@ static void dropReplicationArtifacts(Callable<java.sql.Connection> connectionSup
4041
}
4142

4243
static void cleanupTaskState(RunContext runContext, AbstractDebeziumTask task) throws Exception {
43-
KVStore kvStore = runContext.namespaceKv(runContext.flowInfo().namespace());
44-
String taskRunValue = runContext.storage().getTaskStorageContext()
44+
var kvStore = runContext.namespaceKv(runContext.flowInfo().namespace());
45+
var taskRunValue = runContext.storage().getTaskStorageContext()
4546
.map(StorageContext.Task::getTaskRunValue)
4647
.orElse(null);
47-
String stateName = runContext.render(task.getStateName()).as(String.class).orElse("debezium-state");
48+
var stateName = runContext.render(task.getStateName()).as(String.class).orElse("debezium-state");
4849

49-
kvStore.delete(computeKvStoreKey(runContext, stateName, "offsets.dat", taskRunValue));
50-
kvStore.delete(computeKvStoreKey(runContext, stateName, "dbhistory.dat", taskRunValue));
50+
deleteAllVersions(kvStore, computeKvStoreKey(runContext, stateName, "offsets.dat", taskRunValue));
51+
deleteAllVersions(kvStore, computeKvStoreKey(runContext, stateName, "dbhistory.dat", taskRunValue));
5152
}
5253

5354
static void cleanupFlowState(KVStoreService kvStoreService, String namespace, String flowId, String... stateNames) throws Exception {
@@ -58,14 +59,15 @@ static void cleanupFlowState(KVStoreService kvStoreService, String namespace, St
5859
return;
5960
}
6061

61-
String flowPrefix = Slugify.of(flowId) + "_states_";
62+
var flowPrefix = Slugify.of(flowId) + "_states_";
63+
var keysToDelete = kvStore.listAll().stream()
64+
.map(KVEntry::key)
65+
.distinct()
66+
.filter(key -> Arrays.stream(stateNames).anyMatch(stateName -> key.startsWith(flowPrefix + stateName)))
67+
.toList();
6268

63-
for (KVEntry kvEntry : kvStore.listAll()) {
64-
for (String stateName : stateNames) {
65-
if (kvEntry.key().startsWith(flowPrefix + stateName)) {
66-
kvStore.delete(kvEntry.key());
67-
}
68-
}
69+
for (var key : keysToDelete) {
70+
deleteAllVersions(kvStore, key);
6971
}
7072
}
7173

@@ -84,4 +86,10 @@ private static String computeKvStoreKey(RunContext runContext, String stateName,
8486

8587
return prefix + separator + filename;
8688
}
89+
90+
private static void deleteAllVersions(KVStore kvStore, String key) throws Exception {
91+
while (kvStore.delete(key)) {
92+
// Delete all versions to prevent fallback to stale previous entries.
93+
}
94+
}
8795
}

plugin-debezium-postgres/src/test/resources/flows/realtime.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ triggers:
99
port: 65432
1010
username: postgres
1111
password: pg_passwd
12+
stateName: "debezium-state-{{ now() | date('yyyyMMddHHmmssSSS') }}"
1213
includedTables:
1314
- public.events
1415

plugin-debezium-postgres/src/test/resources/flows/trigger.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ triggers:
99
port: 65432
1010
username: postgres
1111
password: pg_passwd
12+
stateName: "debezium-state-{{ now() | date('yyyyMMddHHmmssSSS') }}"
1213
maxRecords: 5
1314
includedTables:
1415
- public.events

0 commit comments

Comments
 (0)