-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add Tests for Storage Extension and File Rotation #1427
Add Tests for Storage Extension and File Rotation #1427
Conversation
5523d4e
to
4e64893
Compare
adot-testbed/app/src/test/java/software/amazon/adot/testbed/LogsTests.java
Outdated
Show resolved
Hide resolved
adot-testbed/app/src/test/java/software/amazon/adot/testbed/LogsTests.java
Outdated
Show resolved
Hide resolved
adot-testbed/app/src/test/java/software/amazon/adot/testbed/LogsTests.java
Outdated
Show resolved
Hide resolved
adot-testbed/app/src/test/java/software/amazon/adot/testbed/LogsTests.java
Show resolved
Hide resolved
} catch (IOException e) { | ||
throw new RuntimeException("Error writing to File A.", e); | ||
} | ||
Thread.sleep(5000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you van validate the log entries so far here so that you don't need to add a sleep. that will block in a safe way before you move with the rest of the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that validation can be done, but the thread here is making sure to give enough time for the file operations to be done. So even if we do the validation without the thread, since the log file is not generated it would lead FileNotFoundException.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is writing to the file a blocking operation? Why do you need to wait? What file operations are you referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what operations needs to be done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File operations i meant here are to create and write data to File A etc. it takes considerable time for creating and writing to file.
So without the thread.sleep the collector is not able to parse log line, since it seems the file testlogA.log didn't have the line written to it yet.
java.lang.AssertionError:
Expecting actual:
["Message in renamed file - line 1",
"Message in renamed file - line 2",
"Message in renamed file - line 3"]
to contain exactly in any order:
["Message in File A",
"Message in renamed file - line 1",
"Message in renamed file - line 2",
"Message in renamed file - line 3"]
but could not find the following elements:
["Message in File A"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is why I suggested that you add a validateLogs
instead of a Thread.sleep
to validate only "Message in File A". It will block until the lines are sent to cwlogs. This will guarantee that it is safe to continue with the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Committed the changes.
adot-testbed/app/src/test/java/software/amazon/adot/testbed/LogsTests.java
Outdated
Show resolved
Hide resolved
adot-testbed/app/src/test/java/software/amazon/adot/testbed/LogsTests.java
Outdated
Show resolved
Hide resolved
adot-testbed/app/src/test/resources/configurations/config-fileRotation.yaml
Outdated
Show resolved
Hide resolved
adot-testbed/app/src/test/resources/configurations/config-fileRotation.yaml
Outdated
Show resolved
Hide resolved
private Path logDirectory; | ||
private GenericContainer<?> collector; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does test parallelism work with the framework we are using? Does having these in the Class scope have a potential to cause conflicts if test cases are ran in parallel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried running with ./gradlew test --rerun-tasks --info --parallel
to have optimal number of threads to use no conlicts were seen. We are also using specific path/file within the directory so parallel wouldn't be a problem IMO
String logStreamName = "storageExtension-logstream-" + uniqueID; | ||
collector = createAndStartCollector("/configurations/config-storageExtension.yaml", logStreamName); | ||
File tempFile = new File(logDirectory.toString(), "storageExtension.log"); | ||
Thread.sleep(5000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why sleep here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sleep is similar as here, its just to wait for the collector to start watching the file.
fileWriter.write("First Message after collector is stopped" + "\n"); | ||
fileWriter.write("Second Message after the collector is stopped" + "\n"); | ||
fileWriter.write("Third Message after the collector is stopped" + "\n"); | ||
fileWriter.flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is flush called inside the try block here but outside of it on line 144?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually no specific reason, modified .
String expectedLogPath = logDirectory.toString(); | ||
logFilePaths.add(expectedLogPath + "/storageExtension.log"); | ||
|
||
validateLogs(logStreamName , logFilePaths); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to validate logs twice? Could we run through the start -> write -> stop -> write -> start -> stop
cycle then validate once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validate is behaving like a sleep here. we need to make sure that logs were read before stopping the collector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to make sure that logs were read before stopping the collector.
I tend to agree with that. After changes now it is doing -start -> write -> validate->stop -> write -> start -> stop
and then it validates again.
} catch (IOException e) { | ||
throw new RuntimeException("Error writing to File A.", e); | ||
} | ||
Thread.sleep(5000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is writing to the file a blocking operation? Why do you need to wait? What file operations are you referring to?
System.out.println("Actual Logs - Log lines From Cloudwatch"); | ||
messageToValidate.forEach(System.out::println); | ||
|
||
System.out.println("Expected logs- Log lines from log file"); | ||
lines.forEach(System.out::println); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be more thoughtful about what we are printing to std out. We should only need to print if there is a failure. And in the case of the failure it should be descriptive to tell us what was expected and what was actually given.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I have added it for easy lookout on whats' validated. if we should only need to print during failure then the assertions will log the actual/expected when in failure, removed the print statements
for (String logFilePath : logFilePaths) { | ||
InputStream inputStream; | ||
//Check whether the filePath is from resource folder. | ||
if (getClass().getResource(logFilePath) != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is still the boolean flag behaviour disguised.....
my suggestion was to change the function signature to use
void validateLogs(String testLogStreamName, List<InputStream> inputStreams) throws Exception {
Another option is to create two functions, one that should only be used for resources paths and another that is used only for local paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, now I see the suggestion. Modified.
printWriter.println("Third Message, collector is running"); | ||
printWriter.flush(); | ||
|
||
Thread.sleep(5000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bet this could be removed and the tests would still succeed.
Description:
PR to add Tests for Storage Extension Restart scenarios and File Rotation
Thread.sleep is used to give enough time for file operations, collector(stop/start).
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.