July 30, 2023

tAssert – Docs for ESB 7.x

tAssert

Generates the boolean evaluation on the concern for the Job execution status and
provides the Job status messages to tAssertCatcher.

The status includes:

  • Ok: the Job execution succeeds.

  • Fail: the Job execution fails.

The tested Job’s result does not match the expectation or an execution error
occurred at runtime.

The tAssert component works alongside
tAssertCatcher to evaluate the status of a Job execution. It
concludes with the boolean result based on an assertive statement related to the
execution and feed the result to tAssertCatcher for proper Job status
presentation.

tAssert Standard properties

These properties are used to configure tAssert running in the Standard Job framework.

The Standard
tAssert component belongs to the Logs & Errors family.

The component in this framework is available in all Talend
products
.

Basic settings

Description

Type in your descriptive message to help identify the assertion of
a tAssert.

Expression

Type in the assertive statement you base the evaluation on.

Global Variables

Global Variables

ERROR_MESSAGE: the error message generated by the
component when an error occurs. This is an After variable and it returns a string. This
variable functions only if the Die on error check box is
cleared, if the component has this check box.

A Flow variable functions during the execution of a component while an After variable
functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl +
Space
to access the variable list and choose the variable to use from it.

For further information about variables, see
Talend Studio

User Guide.

Usage

Usage rule

This component follows the action the assertive condition is
directly related to. It can be the intermediate or end component of
the main Job, or the start, intermediate or end component of the
secondary Job.

Limitation

The evaluation of tAssert is
captured only by tAssertCatcher.

Viewing product orders status (on a daily basis) against a benchmark
number

This scenario allows you to insert the orders information into a database table and to
evaluate the orders status (every day once scheduled to run) by using tAssert to compare the orders against a fixed number and
tAssertCatcher to indicate the results. In this
case, Ok is returned if the number of orders is greater
than 20 and Failed is returned if the number of orders
is less than 20.

In practice, this Job can be scheduled to run every day for the daily orders report
and tFixedFlowInput as well as tLogRow are replaced by input and output components in the Database/File
families.

Linking the components

  1. Drop tFixedFlowInput, tMysqlOutput, tAssert, tAssertCatcher,
    and tLogRow onto the workspace.
  2. Rename tFixedFlowInput as orders, tAssert
    as orders >=20, tAssertCatcher as catch comparison
    result
    and tLogRow as
    ok or failed.
  3. Link tFixedFlowInput to tMysqlOutput using a Row > Main
    connection.
  4. Link tFixedFlowInput to tAssert using the Trigger > On Subjob OK
    connection.
  5. Link tAssertCatcher to tLogRow using a Row > Main
    connection.

    tAssert_1.png

Configuring the components

  1. Double-click tFixedFlowInput to open its
    Basic settings view.

    tAssert_2.png

    Select Use Inline Content (delimited
    file)
    in the Mode
    area.
    In the Content field, enter the data to
    write to the Mysql database, for example:
    Note that the orders listed are just for illustration of how tAssert functions and the number here is less
    than 20.
  2. Click the Edit schema button to open the
    schema editor.

    tAssert_3.png

  3. Click the [+] button to add four columns,
    namely product_id, product_name, date and price, of the
    String, Date, Float types
    respectively.

    Click OK to validate the setup and close
    the editor.
  4. Double-click tMysqlOutput to display the
    Basic settings view.

    tAssert_4.png

  5. In the Host, Port, Database, Username and Password fields, enter the connection details and the
    authentication credentials.
  6. In the Table field, enter the name of the
    table, for example order.
  7. In the Action on table list, select the
    option Drop table if exists and
    create
    .
  8. In the Action on data list, select the
    option Insert.
  9. Double-click tAssert to display the
    Basic settings view.

    tAssert_5.png

  10. In the description field, enter the
    descriptive information for the purpose of tAssert in this case.
  11. In the expression field, enter the
    expression allowing you to compare the data to a fixed number:

  12. Double-click tLogRow to display the
    Basic settings view.

    tAssert_6.png

  13. In the Mode area, select Table (print values in cells of a table) for a
    better display.

Executing the Job

  1. Press Ctrl + S to save the Job.
  2. Press F6 to run the Job.

    tAssert_7.png

    As shown above, the orders status indicates Failed as the number of orders is less than 20.

Setting up the assertive condition for a Job execution

This scenario describes how to set up an assertive condition in tAssert in order to evaluate that a Job execution succeeds
or not. Moreover, you can also find out how the two different evaluation results display
and the way to read them. Apart from tAssert, the
scenario uses the following components as well:

  • tFileInputDelimited and tFileOutputDelimited. The two components compose
    the main Job of which the execution status is evaluated. For the detailed
    information on the two components, see tFileInputDelimited and tFileOutputDelimited.

  • tFileCompare. It realizes the comparison
    between the output file of the main Job and a standard reference file. The
    comparative result is evaluated by tAssert
    against the assertive condition set up in its settings. For more detailed
    information on tFileCompare, see tFileCompare.

  • tAssertCatcher. It captures the evaluation
    generated by tAssert. For more information
    on tAssertCatcher, see tAssertCatcher.

  • tLogRow. It allows you to read the
    captured evaluation. For more information on tLogRow, see tLogRow.

First proceed as follows to design the main Job:

  • Prepare a delimited .csv file as the source
    file read by your main Job.

  • Edit two rows in the delimited file. The contents you edit are not
    important, so feel free to simplify them.

  • Name it source.csv.

  • In
    Talend Studio
    , create a new job JobAssertion.

  • Place tFileInputDelimited
    and tFileOutputDelimited on the
    workspace.

  • Connect them with a Row
    Main
    link to create the main Job.

tAssert_8.png
  • Double-click tFileInputDelimited to open its Component view.

  • In the File Name field of
    the Component view, fill in the path or
    browse to source.csv.

tAssert_9.png
  • Still in the Component
    view, set Property Type to Built-In and click tAssert_10.png next
    to Edit schema to define the data to pass
    on to tFileOutputDelimited. In the
    scenario, define the data presented in source.csv you
    created.

For more information about schema types, see
Talend Studio User Guide
.

  • Define the other parameters in the corresponding fields according
    to source.csv you created.

  • Double-click tFileOutputDelimited to open its Component view.

  • In the File Name field of
    the Component view, fill in or browse to
    specify the path to the output file, leaving the other fields as they are by
    default.

tAssert_11.png
  • Press F6 to execute the
    main Job. It reads source.csv, pass the data to tFileOutputDelimited and output an delimited
    file, out.csv.

Then contine to edit the Job to see how tAssert evaluates the execution status of the main Job.

  • Rename out.csv as reference.csv.This file is used as the expected result the main Job
    should output.

  • Place tFileCompare,
    tAssert and tLogRow on the workspace.

  • Connect them with Row Main
    link.

  • Connect tFileInputDelimited to tFileCompare with OnSubjobOk link.

tAssert_12.png
  • Double-click tFileCompare
    to open its Component view.

  • In the Component view,
    fill in the corresponding file paths in the File to
    compare
    field and the Reference
    file
    field, leaving the other fields as default.

tAssert_13.png

For more information on the tFileCompare component, see tFileCompare.

  • Then click tAssert and
    click the Component tab on the lower side
    of the workspace.

tAssert_14.png
  • In the Component view,
    edit the assertion row2.differ==0 in the
    expression field and the descriptive
    message of the assertion in description
    field.

In the expression field, row2 is the data flow transmissing from tFileCompare to
tAssert
, differ is one of the columns
of the tFileCompare schema and presents whether
the compared files are identical, and 0 means no
difference is detected between the out.csv and reference.csv by tFileCompare. Hence
when the compared files are identical, the assertive condition is thus fulfilled,
tAssert concludes that the main Job succeeds;
otherwise, it concludes failure.

Note:

The differ column is in the read-only
tFileCompare schema. For more information
on its schema, see tFileCompare.

  • Press F6 to execute the
    Job.

  • Check the result presented in the Run view

tAssert_15.png

The console shows the comparison result of tFileCompare: Files are identical. But
you find nowhere the evaluation result of tAssert.

So you need tAssertCatcher to
capture the evaluation.

  • Place tAssertCatcher and
    tLogRow on the workspace.

  • Connect them with Row Main
    link.

tAssert_16.png
  • Use the default configuration in the Component view of tAssertCatcher.

tAssert_17.png
  • Press F6 to execute the
    Job.

  • Check the result presented in the Run view. You will see the Job status information is added
    in:

    .
tAssert_18.png

The descriptive information on JobAssertion in the
console is organized according to the tAssertCatcher schema. This schema includes, in the following order,
the execution time, the process ID, the project name, the Job name, the code language,
the evaluation origin, the evaluation result, detailed information of the evaluation,
descriptive message of the assertion. For more information on the schema of tAssertCatcher, see tAssertCatcher.

The console indicates that the execution status of Job JobAssertion is Ok. In addition to the evalution, you
can still see other descriptive information about JobAssertion
including the descriptive message you have edited in the Basic settings of tAssert.

Then you will perform operations to make the main Job fail to generate
the expected file. To do so, proceed as follows in the same Job you have executed:

  • Delete a row in reference.csv.

  • Press F6 to execute the
    Job again.

  • Check the result presented in Run view.

    .
tAssert_19.png

The console shows that the execution status of the main Job is Failed. The detailed explanation for this status is closely
behind it, reading Test logically failed.

You can thus get a basic idea about your present Job status: it fails to
generate the expected file because of a logical failure. This logical failure could come
from a logical mistake during the Job design.

The status and its explanatory information are presented respectively in
the status and the substatus columns of
the tAssertCatcher schema. For more information
on the columns, see tAssertCatcher.


Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x