Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix-16573][alert] SQL task alert sending failed #16595

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
import lombok.extern.slf4j.Slf4j;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;

@Slf4j
public class SqlTask extends AbstractTask {
Expand Down Expand Up @@ -253,9 +255,18 @@ private String resultProcess(ResultSet resultSet) throws Exception {
: JSONUtils.toJsonString(resultJSONArray);

if (Boolean.TRUE.equals(sqlParameters.getSendEmail())) {
resultJSONArray.forEach(row -> {
row.fields().forEachRemaining(field -> {
if (field.getValue() instanceof NullNode) {
field.setValue(new TextNode("null"));
}
});
});
String sendResult = resultJSONArray.isEmpty() ? JSONUtils.toJsonString(generateEmptyRow(resultSet))
: JSONUtils.toJsonString(resultJSONArray);
Comment on lines +258 to +266
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some unit-test for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to write a unit test for this piece.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started all the projects and tested them with simulated data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to write a unit test for this piece.

You can take a look at other UT.

I started all the projects and tested them with simulated data.

Testing is used to ensure the normal operation in the future, and the current normal operation cannot guarantee that the future will not be affected by other factors.

sendAttachment(sqlParameters.getGroupId(), StringUtils.isNotEmpty(sqlParameters.getTitle())
? sqlParameters.getTitle()
: taskExecutionContext.getTaskName() + " query result sets", result);
: taskExecutionContext.getTaskName() + " query result sets", sendResult);
}
log.debug("execute sql result : {}", result);
return result;
Expand Down
Loading