From aa3a1b4347630910ef926886894a90ab45e9479a Mon Sep 17 00:00:00 2001 From: Benoit Moriceau Date: Mon, 13 Jun 2022 13:26:04 -1000 Subject: [PATCH] Fail the connection state instead of throwing an exception (#13728) * Fail the connection state instead of throwin exception * Fix test * rm import * Update airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultCheckConnectionWorker.java Co-authored-by: Evan Tahler Co-authored-by: Evan Tahler --- .../general/DefaultCheckConnectionWorker.java | 12 ++++++++++-- .../general/DefaultCheckConnectionWorkerTest.java | 11 +++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultCheckConnectionWorker.java b/airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultCheckConnectionWorker.java index 3831e506b93e25..d3604a9f6bf473 100644 --- a/airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultCheckConnectionWorker.java +++ b/airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultCheckConnectionWorker.java @@ -79,11 +79,19 @@ public StandardCheckConnectionOutput run(final StandardCheckConnectionInput inpu LOGGER.debug("Check connection job received output: {}", output); return output; } else { - throw new WorkerException(String.format("Error checking connection, status: %s, exit code: %d", status, exitCode)); + String message = String.format("Error checking connection, status: %s, exit code: %d", status, exitCode); + + LOGGER.error(message); + return new StandardCheckConnectionOutput() + .withStatus(Status.FAILED) + .withMessage(message); } } catch (final Exception e) { - throw new WorkerException("Error while getting checking connection.", e); + LOGGER.error("Error while checking connection: ", e); + return new StandardCheckConnectionOutput() + .withStatus(Status.FAILED) + .withMessage("Error while getting checking connection, because of: " + e.getMessage()); } } diff --git a/airbyte-workers/src/test/java/io/airbyte/workers/general/DefaultCheckConnectionWorkerTest.java b/airbyte-workers/src/test/java/io/airbyte/workers/general/DefaultCheckConnectionWorkerTest.java index 93bc92a7752e3a..c76ae6f730cf89 100644 --- a/airbyte-workers/src/test/java/io/airbyte/workers/general/DefaultCheckConnectionWorkerTest.java +++ b/airbyte-workers/src/test/java/io/airbyte/workers/general/DefaultCheckConnectionWorkerTest.java @@ -6,7 +6,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -101,11 +100,13 @@ public void testFailedConnection() throws WorkerException { } @Test - public void testProcessFail() { + public void testProcessFail() throws WorkerException { when(process.exitValue()).thenReturn(1); final DefaultCheckConnectionWorker worker = new DefaultCheckConnectionWorker(workerConfigs, integrationLauncher, failureStreamFactory); - assertThrows(WorkerException.class, () -> worker.run(input, jobRoot)); + final StandardCheckConnectionOutput output = worker.run(input, jobRoot); + + assertEquals(Status.FAILED, output.getStatus()); } @Test @@ -113,7 +114,9 @@ public void testExceptionThrownInRun() throws WorkerException { doThrow(new RuntimeException()).when(integrationLauncher).check(jobRoot, WorkerConstants.SOURCE_CONFIG_JSON_FILENAME, Jsons.serialize(CREDS)); final DefaultCheckConnectionWorker worker = new DefaultCheckConnectionWorker(workerConfigs, integrationLauncher, failureStreamFactory); - assertThrows(WorkerException.class, () -> worker.run(input, jobRoot)); + final StandardCheckConnectionOutput output = worker.run(input, jobRoot); + + assertEquals(Status.FAILED, output.getStatus()); } @Test