-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vdk-core: fix ingester error handling
When I added error handling I did not tested properly and it broke ingestion. I am adding tests. In order to test close to end to end I am adding functional test (it basically will execute vdk run as a unit test). Testing Done: the new tests Signed-off-by: Antoni Ivanov <[email protected]>
- Loading branch information
1 parent
5336823
commit de2ecb7
Showing
4 changed files
with
117 additions
and
23 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
25 changes: 25 additions & 0 deletions
25
projects/vdk-core/tests/functional/run/jobs/ingest-job/1_step.py
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) 2021 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from taurus.api.job_input import IJobInput | ||
|
||
|
||
def run(job_input: IJobInput): | ||
obj = dict( | ||
int_key=1, | ||
str_key="str", | ||
bool_key=True, | ||
float_key=1.23, | ||
nested=dict(key="value"), | ||
) | ||
|
||
job_input.send_object_for_ingestion( | ||
payload=obj, destination_table="object_table", method="memory" | ||
) | ||
|
||
rows = [["1", 2], ["11", 22], ["111", 111]] | ||
job_input.send_tabular_data_for_ingestion( | ||
rows=rows, | ||
column_names=["first", "second"], | ||
destination_table="tabular_table", | ||
method="memory", | ||
) |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (c) 2021 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from typing import List | ||
from typing import Optional | ||
|
||
from click.testing import Result | ||
from functional.run import util | ||
from taurus.vdk.test_utils.util_funcs import cli_assert_equal | ||
from taurus.vdk.test_utils.util_funcs import CliEntryBasedTestRunner | ||
from taurus.vdk.test_utils.util_plugins import IngestIntoMemoryPlugin | ||
|
||
|
||
class FailingIngestIntoMemoryPlugin(IngestIntoMemoryPlugin): | ||
def ingest_payload( | ||
self, | ||
payload: List[dict], | ||
destination_table: Optional[str], | ||
target: Optional[str] = None, | ||
collection_id: Optional[str] = None, | ||
): | ||
raise IndexError("Random error from our plugin") | ||
|
||
|
||
def test_run_ingest(): | ||
ingest_plugin = IngestIntoMemoryPlugin() | ||
runner = CliEntryBasedTestRunner(ingest_plugin) | ||
|
||
result: Result = runner.invoke(["run", util.job_path("ingest-job")]) | ||
|
||
cli_assert_equal(0, result) | ||
|
||
expected_object = dict( | ||
int_key=1, | ||
str_key="str", | ||
bool_key=True, | ||
float_key=1.23, | ||
nested=dict(key="value"), | ||
) | ||
assert ingest_plugin.payloads[0].payload[0] == expected_object | ||
assert ingest_plugin.payloads[0].destination_table == "object_table" | ||
|
||
expected_rows_object = {"first": "1", "second": 2} | ||
assert ingest_plugin.payloads[1].payload[0] == expected_rows_object | ||
assert ingest_plugin.payloads[1].destination_table == "tabular_table" | ||
|
||
|
||
def test_run_ingest_fails(): | ||
runner = CliEntryBasedTestRunner(FailingIngestIntoMemoryPlugin()) | ||
|
||
result: Result = runner.invoke(["run", util.job_path("ingest-job")]) | ||
|
||
cli_assert_equal(11, result) |