-
Notifications
You must be signed in to change notification settings - Fork 9
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: handle valid JSON messages which are not GreengrassLogMessages #214
Merged
+20
−34
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion
3
src/test/resources/com/aws/greengrass/logmanager/testlogs1.log
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{"contexts":{"component":"demo","device":"asdf"},"eventType":"th1-event","level":"INFO","loggerName":"com.aws.greengrass.logging.examples.LoggerDemo","message":"test th1 info","timestamp":1608292800000} | ||
{"contexts":{"component":"demo","device":"asdf"},"eventType":"th1-event","level":null,"loggerName":"com.aws.greengrass.logging.examples.LoggerDemo","message":"test th1 info","timestamp":1608292800000} | ||
{"contexts":{"component":"demo","device":"asdf"},"eventType":"th2-event","level":"INFO","loggerName":"com.aws.greengrass.logging.examples.LoggerDemo","message":"test th2 info","timestamp":1608292800000} | ||
{"contexts":{"component":"th1-override","device":"asdf"},"level":"DEBUG","loggerName":"com.aws.greengrass.logging.examples.LoggerDemo","message":"test th1 debug","timestamp":1608292800000} | ||
{"contexts":{"component":"demo","device":"asdf"},"level":"INFO","loggerName":"com.aws.greengrass.logging.examples.LoggerDemo","message":"test main info","timestamp":1608292800000} | ||
{"cause":{"localizedMessage":"some error","message":"some error","stackTrace":[{"className":"com.aws.greengrass.logging.examples.LoggerDemo","fileName":"LoggerDemo.java","lineNumber":56,"methodName":"main","nativeMethod":false}],"suppressed":[]},"contexts":{"key2":"value2","component":"demo","device":"asdf"},"eventType":"error-event","level":"ERROR","loggerName":"com.aws.greengrass.logging.examples.LoggerDemo","message":"test error","timestamp":1608292800000} | ||
{"something which parses": "as json, but isn't a GreengrassStructuredLogMessage"} |
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 |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
import org.junit.jupiter.api.io.TempDir; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.function.Consumer; | ||
|
@@ -17,19 +16,18 @@ public class LogGeneratorTest { | |
@TempDir | ||
static Path tempPath; | ||
String logFileName = "localtest"; | ||
String logFileExtention = "log"; | ||
String logWriteFreqSeconds = "0.1"; | ||
String logWriteFreqMs = "100"; | ||
String totalLogNumbers = "50"; | ||
String fileSizeBytes = "1024"; | ||
String fileSizeUnit = "KB"; | ||
String componentName = "com.aws.greengrass.artifacts.LogGenerator"; | ||
String activeFileName = logFileName + "." + logFileExtention; | ||
String activeFileName = logFileName + ".log"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we moving from a variable to a hard coded string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a test (for a test), variable wasn't a variable but a constant. |
||
|
||
@Test | ||
void GIVEN_request_THEN_log_file_Created() | ||
throws ClassNotFoundException, IllegalAccessException, InstantiationException { | ||
|
||
String[] args = {logFileName, logFileExtention, fileSizeBytes, fileSizeUnit, logWriteFreqSeconds, | ||
String[] args = {logFileName, fileSizeBytes, fileSizeUnit, logWriteFreqMs, | ||
totalLogNumbers, tempPath.toString()}; | ||
((Consumer<String[]>) Class.forName(componentName).newInstance()).accept(args); | ||
|
||
|
@@ -39,25 +37,4 @@ void GIVEN_request_THEN_log_file_Created() | |
assertTrue(Arrays.asList(pathnames).contains(activeFileName)); | ||
assertTrue(tempPath.resolve(activeFileName).toFile().length() > 0); | ||
} | ||
|
||
/* | ||
if tempPath is empty string, then the log files would be generated in your local machine. ' | ||
This can be used for manually testing if logs are correctly written | ||
*/ | ||
@Test | ||
void GIVEN_empty_targetFilePath_in_Paras_THEN_default_path_is_local() | ||
throws ClassNotFoundException, InstantiationException, IllegalAccessException { | ||
|
||
String[] args = {logFileName, logFileExtention, fileSizeBytes, fileSizeUnit, logWriteFreqSeconds, | ||
totalLogNumbers, ""}; | ||
((Consumer<String[]>) Class.forName(componentName).newInstance()).accept(args); | ||
|
||
String localPath = System.getProperty("user.dir"); | ||
File directory = new File(localPath); | ||
String[] pathnames = directory.list(); | ||
assertTrue(pathnames.length >= 1); | ||
assertTrue(Arrays.asList(pathnames).contains(activeFileName)); | ||
assertTrue(new File(localPath + "/" + activeFileName).length() > 0); | ||
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 someone going to think this is milliseconds and not messages per second?
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.
It is milliseconds. 0.1 seconds is 100 milliseconds.