Skip to content

Commit

Permalink
Correctly handle the MetaData in the ExecuteSingleInteraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Linschoten committed Aug 30, 2023
1 parent ff0e91a commit 4b92b2c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import com.ing.baker.runtime.akka.actor.recipe_manager.RecipeManagerProtocol
import com.ing.baker.runtime.akka.actor.recipe_manager.RecipeManagerProtocol.RecipeFound
import com.ing.baker.runtime.akka.internal.CachingInteractionManager
import com.ing.baker.runtime.common.BakerException._
import com.ing.baker.runtime.common.RecipeInstanceState.RecipeInstanceMetaDataName
import com.ing.baker.runtime.common.{InteractionExecutionFailureReason, RecipeRecord, SensoryEventStatus}
import com.ing.baker.runtime.model.recipeinstance.RecipeInstanceState.getMetaDataFromIngredients
import com.ing.baker.runtime.recipe_manager.{ActorBasedRecipeManager, DefaultRecipeManager, RecipeManager}
import com.ing.baker.runtime.scaladsl._
import com.ing.baker.runtime.{javadsl, scaladsl}
Expand Down Expand Up @@ -181,7 +183,10 @@ class AkkaBaker private[runtime](config: AkkaBakerConfig) extends scaladsl.Baker
case None => cats.effect.IO.pure(InteractionExecutionResult(Left(InteractionExecutionResult.Failure(
InteractionExecutionFailureReason.INTERACTION_NOT_FOUND, None, None))))
case Some(interactionInstance) =>
interactionInstance.execute(ingredients, Map())
interactionInstance.execute(
ingredients.filter(ingredientInstance => ingredientInstance.name != RecipeInstanceMetaDataName),
getMetaDataFromIngredients(ingredients)
.getOrElse(Map.empty))
.map(executionSuccess => InteractionExecutionResult(Right(InteractionExecutionResult.Success(executionSuccess))))
.recover {
case e => InteractionExecutionResult(Left(InteractionExecutionResult.Failure(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.ing.baker.petrinet.api.{Marking, MultiSet}
import com.ing.baker.runtime.scaladsl.{EventInstance, EventMoment}
import com.ing.baker.il.petrinet._
import com.ing.baker.petrinet.api._
import com.ing.baker.runtime.common.IngredientInstance
import com.ing.baker.runtime.common.RecipeInstanceState.RecipeInstanceMetaDataName
import com.ing.baker.types.{CharArray, MapType, Value}

Expand All @@ -24,6 +25,9 @@ object RecipeInstanceState {
})
}

def getMetaDataFromIngredients(ingredients: Seq[IngredientInstance]): Option[Map[String, String]] =
getMetaDataFromIngredients(ingredients.map(i => i.name -> i.value).toMap)

def empty(recipeInstanceId: String, recipe: CompiledRecipe, createdOn: Long): RecipeInstanceState =
RecipeInstanceState(
recipeInstanceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class InMemoryMemoryCleanupSpec extends AnyFunSpec with Matchers {
recipeId <- baker.addRecipe(RecipeCompiler.compileRecipe(recipe), validate = false)
_ <- baker.bake(recipeId, recipeInstanceId)
_ = baker.fireEventAndResolveWhenCompleted(recipeInstanceId, EventInstance.unsafeFrom(InitialEvent("initialIngredient"))).unsafeRunAsyncAndForget()
_ <- IO.sleep(120.milliseconds)
_ <- IO.sleep(200.milliseconds)
result <- baker.getRecipeInstanceState(recipeInstanceId)
} yield (result)
assertThrows[NoSuchProcessException](result.unsafeRunSync())
Expand Down

0 comments on commit 4b92b2c

Please sign in to comment.