gabriel-farache commented on code in PR #4094:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/4094#discussion_r2581652805
##########
quarkus/extensions/kogito-quarkus-serverless-workflow-jdbc-token-persistence-extension/kogito-quarkus-serverless-workflow-jdbc-token-persistence-integration-test/src/test/java/org/kie/kogito/quarkus/token/persistence/workflows/TokenExchangeIT.java:
##########
@@ -116,37 +119,58 @@ private void validateCachingBehavior() {
}
/**
- * Get the path to the Quarkus log file
+ * Validate OAuth2 token exchange and caching behavior from JSON log files
*/
- private Path getQuarkusLogFile() {
- // The log file path is configured in application.properties as
quarkus.log.file.path
- // For integration tests, Quarkus uses target/quarkus.log
- String logPath = System.getProperty("quarkus.log.file.path",
"target/quarkus.log");
- return Paths.get(logPath);
- }
-
- /**
- * Validate OAuth2 token exchange and caching behavior from log file
- */
- private void validateOAuth2LogsFromFile(Path logFile) throws IOException {
- List<String> logLines = Files.readAllLines(logFile);
- LOGGER.info("Analyzing {} log lines from {} for OAuth2 token exchange
patterns", logLines.size(), logFile);
-
- Assertions.assertThat(logLines).hasSizeGreaterThan(0);
-
- List<String> usedJDBCRepository = logLines.stream().filter(line ->
line.contains(LOG_PREFIX_USED_REPOSITORY + ":
JdbcTokenCacheRepository")).toList();
- List<String> usedInMemoryRepository = logLines.stream().filter(line ->
line.contains(LOG_PREFIX_USED_REPOSITORY + ":
InMemoryTokenCacheRepository")).toList();
+ private void validateOAuth2LogsFromFile(String processInstanceId) throws
IOException {
+ // Parse all JSON log files to handle rotation
+ List<JsonProcessInstanceLogAnalyzer.JsonLogEntry> allEntries =
parseAllJsonLogFilesWithRetry();
+
+ Assertions.assertThat(allEntries).hasSizeGreaterThan(0);
+
+ LOGGER.info("Analyzing {} JSON log entries for OAuth2 token exchange
patterns for process instance {}",
+ allEntries.size(), processInstanceId);
+
+ // Filter logs to only include those related to this process instance
or general context
+ // This prevents interference from concurrent tests
+ List<JsonProcessInstanceLogAnalyzer.JsonLogEntry>
processSpecificEntries = allEntries.stream()
+ .filter(entry ->
processInstanceId.equals(entry.getProcessInstanceId()) ||
+ entry.getProcessInstanceId() == null ||
+ entry.getProcessInstanceId().isEmpty())
+ .toList();
+
+ LOGGER.info("Found {} JSON log entries specific to process instance {}
or general context",
+ processSpecificEntries.size(), processInstanceId);
+
+ // Check repository initialization logs in all entries (not just
process-specific)
+ // Repository initialization might be logged before test starts, so we
check but don't fail
+ List<JsonProcessInstanceLogAnalyzer.JsonLogEntry> usedJDBCRepository =
allEntries.stream()
+ .filter(entry ->
entry.message.contains(LOG_PREFIX_USED_REPOSITORY + ":
JdbcTokenCacheRepository"))
+ .toList();
+ List<JsonProcessInstanceLogAnalyzer.JsonLogEntry>
usedInMemoryRepository = allEntries.stream()
+ .filter(entry ->
entry.message.contains(LOG_PREFIX_USED_REPOSITORY + ":
InMemoryTokenCacheRepository"))
+ .toList();
Assertions.assertThat(usedJDBCRepository).hasSize(1);
Assertions.assertThat(usedInMemoryRepository).hasSize(0);
- LOGGER.info("JDBC repository was used as expected");
-
- List<String> startTokenExchangeLogLines =
logLines.stream().filter(line ->
line.contains(LOG_PREFIX_STARTING_TOKEN_EXCHANGE)).toList();
- List<String> completedTokenExchangeLogLines =
logLines.stream().filter(line ->
line.contains(LOG_PREFIX_COMPLETED_TOKEN_EXCHANGE)).toList();
- List<String> failedTokenExchangeLogLines =
logLines.stream().filter(line ->
line.contains(LOG_PREFIX_FAILED_TOKEN_EXCHANGE)).toList();
- List<String> refreshTokenExchangeLogLines =
logLines.stream().filter(line ->
line.contains(LOG_PREFIX_TOKEN_REFRESH)).toList();
- List<String> completedRefreshTokenExchangeLogLines =
logLines.stream().filter(line ->
line.contains(LOG_PREFIX_REFRESH_COMPLETED)).toList();
- List<String> failedRefreshTokenExchangeLogLines =
logLines.stream().filter(line ->
line.contains(LOG_PREFIX_FAILED_TO_REFRESH_TOKEN)).toList();
+ // Filter token exchange logs to only those related to this process
instance
+ List<JsonProcessInstanceLogAnalyzer.JsonLogEntry>
startTokenExchangeLogLines = processSpecificEntries.stream()
+ .filter(entry ->
entry.message.contains(LOG_PREFIX_STARTING_TOKEN_EXCHANGE))
+ .toList();
+ List<JsonProcessInstanceLogAnalyzer.JsonLogEntry>
completedTokenExchangeLogLines = processSpecificEntries.stream()
+ .filter(entry ->
entry.message.contains(LOG_PREFIX_COMPLETED_TOKEN_EXCHANGE))
+ .toList();
+ List<JsonProcessInstanceLogAnalyzer.JsonLogEntry>
failedTokenExchangeLogLines = processSpecificEntries.stream()
+ .filter(entry ->
entry.message.contains(LOG_PREFIX_FAILED_TOKEN_EXCHANGE))
+ .toList();
+ List<JsonProcessInstanceLogAnalyzer.JsonLogEntry>
refreshTokenExchangeLogLines = processSpecificEntries.stream()
+ .filter(entry ->
entry.message.contains(LOG_PREFIX_TOKEN_REFRESH) &&
processInstanceId.equals(entry.getProcessInstanceId()))
+ .toList();
+ List<JsonProcessInstanceLogAnalyzer.JsonLogEntry>
completedRefreshTokenExchangeLogLines = processSpecificEntries.stream()
+ .filter(entry ->
entry.message.contains(LOG_PREFIX_REFRESH_COMPLETED) &&
processInstanceId.equals(entry.getProcessInstanceId()))
+ .toList();
+ List<JsonProcessInstanceLogAnalyzer.JsonLogEntry>
failedRefreshTokenExchangeLogLines = processSpecificEntries.stream()
+ .filter(entry ->
entry.message.contains(LOG_PREFIX_FAILED_TO_REFRESH_TOKEN) &&
processInstanceId.equals(entry.getProcessInstanceId()))
+ .toList();
Review Comment:
I will convert those lines to a single iteration with a bunch of `if`
statements to populate the lists but I think for clarity it's better to keep
each list individually instead of a map because then when validating the lists
it would require to call the `get` from the map with the proper key (which
should be a constant), would that be OK with you?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]