Skip to content

HDDS-1886. Use ArrayList#clear to address audit failure scenario #1205

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -153,7 +153,7 @@ private void verifyLog(String expected) throws IOException {
assertTrue(lines.size() != 0);
assertTrue(expected.equalsIgnoreCase(lines.get(0)));
//empty the file
lines.remove(0);
lines.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

@dineshchitlangia good idea to avoid unnecessary assumptions.

Here are some further suggestions:

  1. Wrap assertions and cleanup in try and finally, respectively. Otherwise a failed assertion would cause all further independent test cases to also fail due to leftover content in the file. (This one is not specific to multi-line cases.)
  2. Make verifyLog accept String... and check each expected line. Also, retry reading the file until it has enough lines instead of being non-empty.
  3. I think using assertEquals would make it easier to spot differences between expected and actual values. (I'm not sure case-ignorance is really important. Currently the test passes with strict case check, too.)

Copy link
Contributor Author

@dineshchitlangia dineshchitlangia Aug 1, 2019

Choose a reason for hiding this comment

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

@adoroszlai Thanks for review & suggestions.

  1. Wrap assertions and cleanup in try and finally, respectively. Otherwise a failed assertion would cause all further independent test cases to also fail due to leftover content in the file. (This one is not specific to multi-line cases.)

Yes, that was the original approach, however, the review at the time preferred to throw the Exception instead of catching it. This is because we won't accept a few failures, the criteria required is all tests must pass.

  1. Make verifyLog accept String... and check each expected line. Also, retry reading the file until it has enough lines instead of being non-empty.

In this test for the base framework of audit logging, we invoke verifyLog each time a log worthy event has occurred. So at any time, the recent event is the only event in the audit log. Hence we verify only one line at a time as they are invoked by different tests.

  1. I think using assertEquals would make it easier to spot differences between expected and actual values. (I'm not sure case-ignorance is really important. Currently the test passes with strict case check, too.)
    Again, since the test was for base audit logging framework, strict checking was required in the original.

That said, the goal of current jira is only to move away from using ArrayList#remove.
I have filed HDDS-1889 to address the multi-line log scenario that will cover your suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adoroszlai Could please you let me know if there are any other concerns based on my response above and follow up jira? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

@dineshchitlangia Thanks for clarifying the scope and filing the follow-up Jira. I don't have any other concerns.

Copy link
Contributor

Choose a reason for hiding this comment

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

@adoroszlai Thanks for the review. I will commit this now.

FileUtils.writeLines(file, lines, false);
}

Expand Down