-
Notifications
You must be signed in to change notification settings - Fork 93
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 scenario tests with fragment input validation #7159
base: staging
Are you sure you want to change the base?
Fix scenario tests with fragment input validation #7159
Conversation
WalkthroughThe changes in this pull request involve enhancements to the testing capabilities in the Changes
Sequence Diagram(s)sequenceDiagram
participant Test as FlinkTestMainSpec
participant Fragment as Fragment
participant Process as ProcessWithValidation
Test->>Fragment: Setup fragment with validation
Fragment->>Process: Validate parameters
Process-->>Test: No exceptions thrown
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
8a7be19
to
c7832ab
Compare
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (2)
engine/flink/executor/src/test/scala/pl/touk/nussknacker/engine/process/runner/FlinkTestMainSpec.scala (2)
667-682
: Enhance the test with specific assertions for fragment behaviorWhile the test verifies that no exceptions are thrown when a process fragment with parameter validation is defined, it would be more robust to include assertions that check the actual behavior of the fragment. This ensures that not only does the process run without exceptions, but it also produces the expected results.
739-766
: Consolidateobject
andclass
to improve code organizationDefining an
object FlinkTestMainSpec
separately in the same file asclass FlinkTestMainSpec
can be confusing. Consider moving the contents of theobject
into theclass
asprivate
members. This aligns with Scala best practices and enhances readability.Apply this diff to move the definitions into the class:
-class FlinkTestMainSpec extends AnyWordSpec with Matchers with Inside with BeforeAndAfterEach with OptionValues { +class FlinkTestMainSpec extends AnyWordSpec with Matchers with Inside with BeforeAndAfterEach with OptionValues { + private val fragmentWithValidationName = "fragmentWithValidation" + + private val processWithFragmentParameterValidation: CanonicalProcess = { + // existing code from the object + } + // Rest of the class code... -} - -object FlinkTestMainSpec { - private val fragmentWithValidationName = "fragmentWithValidation" - - private val processWithFragmentParameterValidation: CanonicalProcess = { - // existing code... - } -}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
engine/flink/executor/src/test/scala/pl/touk/nussknacker/engine/process/runner/FlinkTestMainSpec.scala
(4 hunks)utils/utils/src/main/scala/pl/touk/nussknacker/engine/util/json/ToJsonEncoder.scala
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- utils/utils/src/main/scala/pl/touk/nussknacker/engine/util/json/ToJsonEncoder.scala
import pl.touk.nussknacker.engine.process.runner.FlinkTestMainSpec.{ | ||
fragmentWithValidationName, | ||
processWithFragmentParameterValidation | ||
} |
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.
🛠️ Refactor suggestion
Avoid unnecessary self-imports within the same file
Importing FlinkTestMainSpec.{fragmentWithValidationName, processWithFragmentParameterValidation}
in the same file where they are defined can lead to confusion and is unnecessary. You can access these members directly since they are in the same scope.
Apply this diff to remove the unnecessary import:
-import pl.touk.nussknacker.engine.process.runner.FlinkTestMainSpec.{
- fragmentWithValidationName,
- processWithFragmentParameterValidation
-}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
import pl.touk.nussknacker.engine.process.runner.FlinkTestMainSpec.{ | |
fragmentWithValidationName, | |
processWithFragmentParameterValidation | |
} |
validationExpression = Expression.spel("true"), | ||
validationFailedMessage = Some("param validation failed") | ||
) |
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.
Provide a meaningful validationExpression
for effective validation
The validationExpression
is currently set to Expression.spel("true")
, which means it will always pass validation. To properly test the parameter validation mechanism, consider using an expression that actually evaluates the parameter value. For example, you can check if the parameter is not empty or meets certain criteria.
Apply this diff to use a meaningful validation expression:
valueCompileTimeValidation = Some(
ParameterValueCompileTimeValidation(
- validationExpression = Expression.spel("true"),
+ validationExpression = Expression.spel("#param != null and #param != ''"),
validationFailedMessage = Some("param validation failed")
)
)
Committable suggestion skipped: line range outside the PR's diff.
Describe your changes
Currently when we try to test a scenario which uses a fragment which has some validation set on parameter's expression there is an exception during serialization.
This happens as deep down there is a classloader passed which cannot be serialized. The problem does not occur when there is a fragment without validation as
variableEncoder
is not passed and is thereforenull
which we can see on the right side of a screenshot. On the left side we can see the problematic situation with classloaderI added a test replicating the issue. It passes with the proposed change but would fail in the same way as on the environment without it:
In the proposed change i just add
@transient
to the problematic classloader as it's not needed during test execution. I'm not putting that annotation on the whole encoder as it seems that it's neededChecklist before merge
Summary by CodeRabbit
New Features
Bug Fixes
ToJsonEncoder
to prevent serialization ofclassLoader
, improving handling in distributed contexts.