Skip to content

Commit fc6b7d4

Browse files
committed
tests fix
1 parent 81ddd4c commit fc6b7d4

File tree

8 files changed

+52
-39
lines changed

8 files changed

+52
-39
lines changed

engine/flink/components/base-tests/src/test/scala/pl/touk/nussknacker/engine/flink/util/transformer/aggregate/TransformersTest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ class TransformersTest extends AnyFunSuite with FlinkSpec with Matchers with Ins
494494
val ex = the[IllegalArgumentException] thrownBy {
495495
runScenario(model, resolvedScenario)
496496
}
497-
ex should have message "Compilation errors: ExpressionParserCompilationError(Unresolved reference 'input',inputVarAccessTest,Some(ParameterName($expression)),#input,None)"
497+
ex should have message "Compilation errors: ExpressionParserCompilationError(Unresolved reference 'input',inputVarAccessTest,Some($expression),#input,None)"
498498
}
499499

500500
}

engine/flink/executor/src/test/scala/pl/touk/nussknacker/engine/process/functional/CustomNodeProcessSpec.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class CustomNodeProcessSpec extends AnyFunSuite with Matchers with ProcessTestHe
261261
val thrown = the[IllegalArgumentException] thrownBy processInvoker.invokeWithSampleData(process, data)
262262

263263
thrown.getMessage should startWith(
264-
"Compilation errors: ExpressionParserCompilationError(Unresolved reference 'input',proc2,Some(ParameterName(all)),#input.id,None)"
264+
"Compilation errors: ExpressionParserCompilationError(Unresolved reference 'input',proc2,Some(all),#input.id,None)"
265265
)
266266
}
267267

@@ -276,7 +276,7 @@ class CustomNodeProcessSpec extends AnyFunSuite with Matchers with ProcessTestHe
276276

277277
val thrown = the[IllegalArgumentException] thrownBy processInvoker.invokeWithSampleData(process, List.empty)
278278

279-
thrown.getMessage shouldBe s"Compilation errors: ExpressionParserCompilationError(There is no property 'value999' in type: SimpleRecord,delta,Some(ParameterName($$expression)),#outRec.record.value999 > #outRec.previous + 5,None)"
279+
thrown.getMessage shouldBe s"Compilation errors: ExpressionParserCompilationError(There is no property 'value999' in type: SimpleRecord,delta,Some($$expression),#outRec.record.value999 > #outRec.previous + 5,None)"
280280
}
281281

282282
test("should evaluate blank expression used in lazy parameter as a null") {

engine/flink/schemed-kafka-components-utils/src/test/scala/pl/touk/nussknacker/engine/schemedkafka/KafkaAvroPayloadIntegrationSpec.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class KafkaAvroPayloadIntegrationSpec extends KafkaAvroSpecMixin with BeforeAndA
9696
runAndVerifyResultSingleEvent(process, topicConfig, "fooBar", "fooBar")
9797
}.getMessage
9898

99-
message should include("InvalidPropertyFixedValue(ParameterName(Topic),None,'invalid-topic',")
99+
message should include("InvalidPropertyFixedValue(Topic,None,'invalid-topic',")
100100
}
101101

102102
test("should handle null value for mandatory parameter") {
@@ -110,7 +110,7 @@ class KafkaAvroPayloadIntegrationSpec extends KafkaAvroSpecMixin with BeforeAndA
110110
}.getMessage
111111

112112
message should include(
113-
"EmptyMandatoryParameter(This field is mandatory and can not be empty,Please fill field for this parameter,ParameterName(Topic),start"
113+
"EmptyMandatoryParameter(This field is mandatory and can not be empty,Please fill field for this parameter,Topic,start"
114114
)
115115
}
116116

engine/flink/schemed-kafka-components-utils/src/test/scala/pl/touk/nussknacker/engine/schemedkafka/source/flink/DelayedUniversalKafkaSourceAvroPayloadIntegrationSpec.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class DelayedUniversalKafkaSourceAvroPayloadIntegrationSpec
146146
intercept[IllegalArgumentException] {
147147
runAndVerify(topicConfig, process, LongFieldV1.record)
148148
}.getMessage should include(
149-
"LowerThanRequiredParameter(This field value has to be a number greater than or equal to 0,Please fill field with proper number,ParameterName(delayInMillis),start)"
149+
"LowerThanRequiredParameter(This field value has to be a number greater than or equal to 0,Please fill field with proper number,delayInMillis,start)"
150150
)
151151
}
152152

engine/flink/tests/src/test/scala/pl/touk/nussknacker/engine/flink/minicluster/scenariotesting/FlinkMiniClusterScenarioTestRunnerSpec.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ class FlinkMiniClusterScenarioTestRunnerSpec
833833
}.getCause
834834
inside(dictEditorException) { case _: IllegalArgumentException =>
835835
dictEditorException.getMessage.startsWith(
836-
"Compilation errors: IncompatibleParameterDefinitionModification(ParameterName(static),dictKeyWithLabel,List(SpelTemplateParameterEditor, SpelParameterEditor)"
836+
"Compilation errors: IncompatibleParameterDefinitionModification(static,dictKeyWithLabel,List(SpelTemplateParameterEditor, SpelParameterEditor)"
837837
) shouldBe true
838838
}
839839
}
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
package pl.touk.nussknacker.engine.compile
22

3+
import cats.Id
4+
import cats.data.{NonEmptySet, WriterT}
35
import cats.data.Validated.valid
4-
import cats.implicits.catsSyntaxValidatedId
6+
import cats.implicits.toTraverseOps
7+
import cats.instances.set
58
import com.typesafe.scalalogging.LazyLogging
69
import pl.touk.nussknacker.engine.api.{JobData, NodeId}
710
import pl.touk.nussknacker.engine.api.context.ProcessCompilationError.MissingParameters
8-
import pl.touk.nussknacker.engine.api.definition.Parameter
11+
import pl.touk.nussknacker.engine.api.definition.{Parameter => ParameterDefinition}
912
import pl.touk.nussknacker.engine.api.parameter.ParameterName
1013
import pl.touk.nussknacker.engine.graph.evaluatedparam.{Parameter => NodeParameter}
14+
import pl.touk.nussknacker.engine.util.Implicits.RichTupleList
1115

1216
object NodeParametersAdjuster extends LazyLogging {
1317

14-
def adjustNonBranchParameters(parameterDefinitions: List[Parameter], parameters: List[NodeParameter])(
18+
def adjustNonBranchParameters(parameterDefinitions: List[ParameterDefinition], parameters: List[NodeParameter])(
1519
implicit nodeId: NodeId,
1620
jobData: JobData
1721
): List[NodeParameter] = {
18-
val definedParamNamesSet = parameterDefinitions.filter(!_.branchParam).map(_.name).toSet
19-
val usedParamNamesSet = parameters.map(_.name).toSet
20-
21-
checkRedundancyAndWarnIfNeeded(definedParamNamesSet, usedParamNamesSet)
22-
validateMissingness(definedParamNamesSet, usedParamNamesSet)
23-
// FIXME abr
24-
parameters
22+
val nonBranchParametersDefinition = parameterDefinitions.filter(!_.branchParam)
23+
checkRedundancyAndWarnIfNeeded(nonBranchParametersDefinition, parameters)
24+
addMissingNodeParameters(nonBranchParametersDefinition, parameters)
2525
}
2626

2727
private def checkRedundancyAndWarnIfNeeded(
28-
definedParamNamesSet: Set[ParameterName],
29-
usedParamNamesSet: Set[ParameterName]
28+
parameterDefinitions: List[ParameterDefinition],
29+
parameters: List[NodeParameter]
3030
)(
3131
implicit nodeId: NodeId,
3232
jobData: JobData
3333
): Unit = {
34-
val redundantParams = usedParamNamesSet.diff(definedParamNamesSet)
34+
val redundantParams = parameters.map(_.name).toSet.diff(parameterDefinitions.map(_.name).toSet)
3535
if (redundantParams.nonEmpty) {
3636
logger.warn(
3737
s"Scenario [${jobData.metaData.name}] node [$nodeId] compilation warning. " +
@@ -40,11 +40,37 @@ object NodeParametersAdjuster extends LazyLogging {
4040
}
4141
}
4242

43-
private def validateMissingness(definedParamNamesSet: Set[ParameterName], usedParamNamesSet: Set[ParameterName])(
44-
implicit nodeId: NodeId
43+
private def addMissingNodeParameters(
44+
parameterDefinitions: List[ParameterDefinition],
45+
parameters: List[NodeParameter]
46+
)(
47+
implicit nodeId: NodeId,
48+
jobData: JobData
4549
) = {
46-
val notUsedParams = definedParamNamesSet.diff(usedParamNamesSet)
47-
if (notUsedParams.nonEmpty) MissingParameters(notUsedParams).invalidNel[Unit] else valid(())
50+
val parameterByName = parameters.map(p => p.name -> p).toMapCheckingDuplicates
51+
val (missingParameterNames, adjustedParameters) = parameterDefinitions
52+
.map { parameterDefinition =>
53+
parameterByName
54+
.get(parameterDefinition.name)
55+
.map(parameter => WriterT.value[Id, Set[ParameterName], NodeParameter](parameter))
56+
.getOrElse {
57+
WriterT
58+
.value[Id, Set[ParameterName], NodeParameter](
59+
NodeParameter(parameterDefinition.name, parameterDefinition.finalDefaultValue)
60+
)
61+
.tell(Set(parameterDefinition.name))
62+
}
63+
}
64+
.sequence
65+
.run
66+
if (missingParameterNames.nonEmpty) {
67+
logger.warn(
68+
s"Scenario [${jobData.metaData.name}] node [$nodeId] compilation warning. " +
69+
s"Found missing parameters: ${missingParameterNames.toList.map(_.value).sorted.mkString(", ")}. " +
70+
s"They will be recovered based on the default value from parameters definitions."
71+
)
72+
}
73+
adjustedParameters
4874
}
4975

5076
}

scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/InterpreterSpec.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ class InterpreterSpec extends AnyFunSuite with Matchers {
965965

966966
intercept[IllegalArgumentException] {
967967
interpretProcess(process, Transaction())
968-
}.getMessage shouldBe "Compilation errors: EmptyMandatoryParameter(This field is mandatory and can not be empty,Please fill field for this parameter,ParameterName(expression),customNode)"
968+
}.getMessage shouldBe "Compilation errors: EmptyMandatoryParameter(This field is mandatory and can not be empty,Please fill field for this parameter,expression,customNode)"
969969
}
970970

971971
test("not accept blank expression for not blank parameter") {
@@ -978,7 +978,7 @@ class InterpreterSpec extends AnyFunSuite with Matchers {
978978

979979
intercept[IllegalArgumentException] {
980980
interpretProcess(process, Transaction())
981-
}.getMessage shouldBe "Compilation errors: BlankParameter(This field value is required and can not be blank,Please fill field value for this parameter,ParameterName(expression),customNode)"
981+
}.getMessage shouldBe "Compilation errors: BlankParameter(This field value is required and can not be blank,Please fill field value for this parameter,expression,customNode)"
982982
}
983983

984984
test("use eager service") {

scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/ProcessValidatorSpec.scala

-13
Original file line numberDiff line numberDiff line change
@@ -956,19 +956,6 @@ class ProcessValidatorSpec extends AnyFunSuite with Matchers with Inside with Op
956956
}
957957
}
958958

959-
test("validate service params") {
960-
val process = ScenarioBuilder
961-
.streaming("process1")
962-
.source("id1", "typed-source")
963-
.enricher("enricher1", "out", "withParamsService")
964-
.emptySink("id2", "sink")
965-
966-
inside(validate(process, definitionWithTypedSource).result) {
967-
case Invalid(NonEmptyList(MissingParameters(missingParam, "enricher1"), _)) =>
968-
missingParam shouldBe Set(ParameterName("par1"))
969-
}
970-
}
971-
972959
test("find usage of fields that does not exist in option object") {
973960
val process = ScenarioBuilder
974961
.streaming("process1")

0 commit comments

Comments
 (0)