daml/triggers/simulations/scala/ACSGrowth.scala
Remy 96f16df3c0
remove script/trigger/cantonFixture deps on scala-bindings (#17954)
Basically we remove the dependency of different components on "//language-support/scala/bindings" by:

- replacing com.daml.ledger.api.refinements.ApiTypes.Party by com.daml.lf.data.Ref.Party
- replacing com.daml.ledger.api.refinements.ApiTypes.ApplicationId by Option[com.daml.lf.data.Ref.ApplicationId] (here we use option as ApiTypes.ApplicationId allows empty string while Ref.ApplicationId does not).
- adding rounding logic for timestamp in com.daml.lf.data.Time.Timestamp and use it instead of the one from com.daml.api.util.TimestampConversion

Note we did not clean daml-sript export as it have never pass the alpha stage and will be dropped with the 3.x fork.
2023-12-05 15:08:09 +00:00

60 lines
2.2 KiB
Scala

// Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package com.daml.lf.engine.trigger
import org.apache.pekko.actor.typed.Behavior
import org.apache.pekko.actor.typed.scaladsl.Behaviors
import com.daml.lf.data.Ref
import com.daml.lf.engine.trigger.simulation.TriggerMultiProcessSimulation
import com.daml.lf.engine.trigger.simulation.TriggerMultiProcessSimulation.TriggerSimulationConfig
import com.daml.lf.engine.trigger.simulation.process.wrapper.TriggerTimer
import java.nio.file.{Path, Paths}
import scala.concurrent.duration._
class GenericACSGrowth(triggerName: String) extends TriggerMultiProcessSimulation {
override protected lazy val darFile: Either[Path, Path] =
Right(
Paths.get(
Option(System.getenv("DAR")).getOrElse(
throw new RuntimeException(
"Trigger simulation needs a Dar file specified using the environment variable: DAR"
)
)
)
)
// For demonstration purposes, we only run the simulation for 30 seconds
override protected implicit lazy val simulationConfig: TriggerSimulationConfig =
TriggerSimulationConfig(simulationDuration = 30.seconds)
override protected val cantonFixtureDebugMode: Boolean = true
override protected def triggerMultiProcessSimulation: Behavior[Unit] = {
implicit val applicationId: Option[Ref.ApplicationId] = this.applicationId
withLedger { (client, ledger, actAs, controllerContext) =>
val triggerFactory = triggerProcessFactory(client, ledger, s"Cats:$triggerName", actAs)
val startState = unsafeSValueFromLf("Types:Tuple2 { _1 = False, _2 = 0 }")
val trigger =
controllerContext.spawn(triggerFactory.create(startState, Seq.empty), triggerName)
controllerContext.watch(trigger)
controllerContext.spawn(
TriggerTimer.messageWithFixedDelay(1.second, 1.second)(trigger),
s"timed-$triggerName",
)
Behaviors.empty
}
}
}
class SlowACSGrowth extends GenericACSGrowth("slowBreedingTrigger")
class MediumACSGrowth extends GenericACSGrowth("mediumBreedingTrigger")
class FastACSGrowth extends GenericACSGrowth("fastBreedingTrigger")