-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jdbc): be resilient to DataException
We usually fail fast, but when a DataException is thrown it means the JDBC driver throws an exception with error code 22: data exception. As the exception is from the data not the database or the network, there is no point of failfast, we throw a QueueException that may or may not be handled gracefully by the call site.
- Loading branch information
1 parent
bd6937a
commit 69f91a1
Showing
2 changed files
with
45 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,47 @@ | ||
package io.kestra.jdbc.runner; | ||
|
||
import io.kestra.core.models.executions.TaskRun; | ||
import io.kestra.core.models.flows.FlowWithSource; | ||
import io.kestra.core.models.flows.State; | ||
import io.kestra.core.models.property.Property; | ||
import io.kestra.core.queues.QueueException; | ||
import io.kestra.core.queues.QueueFactoryInterface; | ||
import io.kestra.core.queues.QueueInterface; | ||
import io.kestra.core.runners.Indexer; | ||
import io.kestra.core.runners.WorkerTaskResult; | ||
import io.kestra.core.utils.TestsUtils; | ||
import io.kestra.plugin.core.debug.Return; | ||
import io.kestra.core.utils.IdUtils; | ||
import io.kestra.jdbc.JdbcTestUtils; | ||
import io.kestra.core.junit.annotations.KestraTest; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
import org.jooq.exception.DataException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static io.kestra.core.utils.Rethrow.throwConsumer; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
@KestraTest | ||
abstract public class JdbcQueueTest { | ||
@Inject | ||
@Named(QueueFactoryInterface.FLOW_NAMED) | ||
protected QueueInterface<FlowWithSource> flowQueue; | ||
|
||
@Inject | ||
@Named(QueueFactoryInterface.WORKERTASKRESULT_NAMED) | ||
protected QueueInterface<WorkerTaskResult> workerTaskResultQueue; | ||
|
||
@Inject | ||
JdbcTestUtils jdbcTestUtils; | ||
|
||
|
@@ -128,6 +139,25 @@ void withGroupAndType() throws InterruptedException, QueueException { | |
assertThat(receive.blockLast().getNamespace(), is("io.kestra.f2")); | ||
} | ||
|
||
@Test | ||
void invalidWorkerTaskShouldThrowDataException() throws QueueException { | ||
var workerTaskResult = WorkerTaskResult.builder() | ||
.taskRun(TaskRun.builder() | ||
.taskId("taskId") | ||
.id(IdUtils.create()) | ||
.namespace("namespace") | ||
.flowId("flowId") | ||
.state(new State().withState(State.Type.SUCCESS)) | ||
.outputs(Map.of("value", "\u0000")) | ||
.build() | ||
) | ||
.build(); | ||
|
||
var exception = assertThrows(QueueException.class, () -> workerTaskResultQueue.emit(workerTaskResult)); | ||
Check failure on line 156 in jdbc/src/test/java/io/kestra/jdbc/runner/JdbcQueueTest.java
|
||
assertThat(exception.getMessage(), is("Unable to emit a message to the queue")); | ||
assertThat(exception.getCause(), instanceOf(DataException.class)); | ||
} | ||
|
||
private static FlowWithSource builder(String namespace) { | ||
return FlowWithSource.builder() | ||
.id(IdUtils.create()) | ||
|