From 301a5e4025550babce59343fd70182f2368a3f42 Mon Sep 17 00:00:00 2001 From: Rich Birch Date: Fri, 29 Nov 2024 08:57:29 +0000 Subject: [PATCH 1/2] DRTII-1693 Fix asyncness of db updates with live view data population. Tidying --- client/package-lock.json | 2 +- .../src/main/scala/actors/FlightLookups.scala | 6 +++--- .../src/main/scala/actors/MinuteLookups.scala | 4 ++-- .../actors/daily/TerminalDayFlightActor.scala | 15 +++++++------- .../actors/daily/TerminalDayLikeActor.scala | 5 ++++- .../actors/daily/TerminalDayQueuesActor.scala | 6 ++++-- .../api/v1/FlightsApiController.scala | 16 ++++++++------- .../api/v1/QueuesApiController.scala | 1 - .../scala/providers/FlightsProvider.scala | 5 ++--- .../drt/crunchsystem/DrtSystemInterface.scala | 11 ++++------ .../drt/testsystem/TestActors.scala | 4 ++-- .../drt/testsystem/TestDrtSystem.scala | 4 ++-- .../drt/testsystem/TestFlightLookups.scala | 2 +- .../drt/testsystem/TestMinuteLookups.scala | 2 +- .../routing/FlightsRouterActorSpec.scala | 8 ++++---- .../minutes/QueueMinutesRouterActorSpec.scala | 4 ++-- .../crunch/PortStateRequestsSpec.scala | 4 ++-- .../scala/services/crunch/TestDrtActor.scala | 20 ++++--------------- .../services/crunch/VoyageManifestsSpec.scala | 2 +- .../DynamicRunnablePassengerLoadsSpec.scala | 1 - .../services/exports/FlightExportSpec.scala | 2 +- .../services/exports/QueueExportSpec.scala | 2 +- .../graphstages/ArrivalsGraphStageSpec.scala | 2 -- .../staffing/StaffMinutesCheckerSpec.scala | 6 +----- .../workload/QueueProcessorTest.scala | 4 ---- 25 files changed, 59 insertions(+), 79 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index ccb8f38ba..a0bdc4f47 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -1,5 +1,5 @@ { - "name": "main", + "name": "test", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/server/src/main/scala/actors/FlightLookups.scala b/server/src/main/scala/actors/FlightLookups.scala index efdb9a1a4..3b651114a 100644 --- a/server/src/main/scala/actors/FlightLookups.scala +++ b/server/src/main/scala/actors/FlightLookups.scala @@ -16,7 +16,7 @@ import uk.gov.homeoffice.drt.ports.Queues.Queue import uk.gov.homeoffice.drt.ports.Terminals.Terminal import uk.gov.homeoffice.drt.time.{SDateLike, UtcDate} -import scala.concurrent.ExecutionContext +import scala.concurrent.{ExecutionContext, Future} import scala.concurrent.duration._ import scala.language.postfixOps @@ -31,7 +31,7 @@ trait FlightLookupsLike { val terminalSplits: Terminal => Option[Splits] def updateFlights(removalMessageCutOff: Option[FiniteDuration], - updateLiveView: (Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Unit, + updateLiveView: (Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Future[Unit], ) (requestHistoricSplitsActor: Option[ActorRef], requestHistoricPaxActor: Option[ActorRef], @@ -66,7 +66,7 @@ case class FlightLookups(system: ActorSystem, removalMessageCutOff: Option[FiniteDuration], paxFeedSourceOrder: List[FeedSource], terminalSplits: Terminal => Option[Splits], - updateLiveView: (Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Unit, + updateLiveView: (Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Future[Unit], ) extends FlightLookupsLike { override val requestAndTerminateActor: ActorRef = system.actorOf(Props(new RequestAndTerminateActor()), "flights-lookup-kill-actor") diff --git a/server/src/main/scala/actors/MinuteLookups.scala b/server/src/main/scala/actors/MinuteLookups.scala index 0eb745177..17b789033 100644 --- a/server/src/main/scala/actors/MinuteLookups.scala +++ b/server/src/main/scala/actors/MinuteLookups.scala @@ -37,7 +37,7 @@ trait MinuteLookupsLike { requestAndTerminateActor.ask(RequestAndTerminate(actor, container)).mapTo[Set[TerminalUpdateRequest]] } - def updateCrunchMinutes(updateLiveView: (UtcDate, Iterable[CrunchMinute]) => Unit): ((Terminal, UtcDate), MinutesContainer[CrunchMinute, TQM]) => Future[Set[TerminalUpdateRequest]] = + def updateCrunchMinutes(updateLiveView: (UtcDate, Iterable[CrunchMinute]) => Future[Unit]): ((Terminal, UtcDate), MinutesContainer[CrunchMinute, TQM]) => Future[Set[TerminalUpdateRequest]] = (terminalDate: (Terminal, UtcDate), container: MinutesContainer[CrunchMinute, TQM]) => { val (terminal, date) = terminalDate val actor = system.actorOf(TerminalDayQueuesActor.props(Option(updateLiveView))(terminal, date, now)) @@ -81,7 +81,7 @@ trait MinuteLookupsLike { case class MinuteLookups(now: () => SDateLike, expireAfterMillis: Int, queuesByTerminal: Map[Terminal, Seq[Queue]], - updateLiveView: (UtcDate, Iterable[CrunchMinute]) => Unit, + updateLiveView: (UtcDate, Iterable[CrunchMinute]) => Future[Unit], ) (implicit val ec: ExecutionContext, val system: ActorSystem) extends MinuteLookupsLike { override val requestAndTerminateActor: ActorRef = system.actorOf(Props(new RequestAndTerminateActor()), "minutes-lookup-kill-actor") diff --git a/server/src/main/scala/actors/daily/TerminalDayFlightActor.scala b/server/src/main/scala/actors/daily/TerminalDayFlightActor.scala index 89e98d13b..82948313e 100644 --- a/server/src/main/scala/actors/daily/TerminalDayFlightActor.scala +++ b/server/src/main/scala/actors/daily/TerminalDayFlightActor.scala @@ -21,6 +21,7 @@ import uk.gov.homeoffice.drt.protobuf.serialisation.FlightMessageConversion import uk.gov.homeoffice.drt.protobuf.serialisation.FlightMessageConversion._ import uk.gov.homeoffice.drt.time.{SDate, SDateLike, UtcDate} +import scala.concurrent.Future import scala.concurrent.duration.FiniteDuration object TerminalDayFlightActor { @@ -32,7 +33,7 @@ object TerminalDayFlightActor { terminalSplits: Option[Splits], requestHistoricSplitsActor: Option[ActorRef], requestHistoricPaxActor: Option[ActorRef], - maybeUpdateLiveView: Option[(Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Unit], + maybeUpdateLiveView: Option[(Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Future[Unit]], ): Props = Props(new TerminalDayFlightActor( year = date.year, @@ -84,7 +85,7 @@ class TerminalDayFlightActor(year: Int, terminalSplits: Option[Splits], maybeRequestHistoricSplitsActor: Option[ActorRef], maybeRequestHistoricPaxActor: Option[ActorRef], - maybeUpdateLiveView: Option[(Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Unit], + maybeUpdateLiveView: Option[(Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Future[Unit]], ) extends RecoveryActorLike { val loggerSuffix: String = maybePointInTime match { case None => "" @@ -200,8 +201,8 @@ class TerminalDayFlightActor(year: Int, acceptableExistingSources.isEmpty } - private def applyDiffAndPersist(applyDiff: (FlightsWithSplits, Long, List[FeedSource]) => (FlightsWithSplits, Set[Long], Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) - ): Set[TerminalUpdateRequest] = { + private def applyDiffAndRequestMissingData(applyDiff: (FlightsWithSplits, Long, List[FeedSource]) => (FlightsWithSplits, Set[Long], Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) + ): Set[TerminalUpdateRequest] = { val (updatedState, minutesToUpdate, updates, removals) = applyDiff(state, now().millisSinceEpoch, paxFeedSourceOrder) state = updatedState @@ -218,7 +219,7 @@ class TerminalDayFlightActor(year: Int, private def updateAndPersistDiffAndAck(diff: FlightsWithSplitsDiff): Unit = if (diff.nonEmpty) { - val updateRequests = applyDiffAndPersist(diff.applyTo) + val updateRequests = applyDiffAndRequestMissingData(diff.applyTo) val message = flightWithSplitsDiffToMessage(diff, now().millisSinceEpoch) persistAndMaybeSnapshotWithAck(message, List((sender(), updateRequests))) } @@ -226,7 +227,7 @@ class TerminalDayFlightActor(year: Int, private def updateAndPersistDiffAndAck(diff: ArrivalsDiff): Unit = if (diff.toUpdate.nonEmpty || diff.toRemove.nonEmpty) { - val updateRequests = applyDiffAndPersist(diff.applyTo) + val updateRequests = applyDiffAndRequestMissingData(diff.applyTo) val message = arrivalsDiffToMessage(diff, now().millisSinceEpoch) persistAndMaybeSnapshotWithAck(message, List((sender(), updateRequests))) } else sender() ! Set.empty @@ -234,7 +235,7 @@ class TerminalDayFlightActor(year: Int, private def updateAndPersistDiffAndAck(diff: SplitsForArrivals): Unit = if (diff.splits.nonEmpty) { val timestamp = now().millisSinceEpoch - val updateRequests = applyDiffAndPersist(diff.applyTo) + val updateRequests = applyDiffAndRequestMissingData(diff.applyTo) val message = splitsForArrivalsToMessage(diff, timestamp) persistAndMaybeSnapshotWithAck(message, List((sender(), updateRequests))) } else sender() ! Set.empty diff --git a/server/src/main/scala/actors/daily/TerminalDayLikeActor.scala b/server/src/main/scala/actors/daily/TerminalDayLikeActor.scala index cdb0838d4..7076cac80 100644 --- a/server/src/main/scala/actors/daily/TerminalDayLikeActor.scala +++ b/server/src/main/scala/actors/daily/TerminalDayLikeActor.scala @@ -14,6 +14,7 @@ import uk.gov.homeoffice.drt.time.TimeZoneHelper.utcTimeZone import uk.gov.homeoffice.drt.time.{SDate, SDateLike, UtcDate} import scala.collection.mutable +import scala.concurrent.Future abstract class TerminalDayLikeActor[VAL <: MinuteLike[VAL, INDEX], INDEX <: WithTimeAccessor, M <: GeneratedMessage](year: Int, @@ -23,6 +24,8 @@ abstract class TerminalDayLikeActor[VAL <: MinuteLike[VAL, INDEX], INDEX <: With now: () => SDateLike, override val maybePointInTime: Option[MillisSinceEpoch], ) extends RecoveryActorLike { + implicit val ec = context.dispatcher + val loggerSuffix: String = maybePointInTime match { case None => "" case Some(pit) => f"@${SDate(pit).toISOString}" @@ -33,7 +36,7 @@ abstract class TerminalDayLikeActor[VAL <: MinuteLike[VAL, INDEX], INDEX <: With val state: mutable.Map[INDEX, VAL] = mutable.Map[INDEX, VAL]() - val onUpdate: Option[(UtcDate, Iterable[VAL]) => Unit] = None + val onUpdate: Option[(UtcDate, Iterable[VAL]) => Future[Unit]] = None override def persistenceId: String = f"terminal-$persistenceIdType-${terminal.toString.toLowerCase}-$year-$month%02d-$day%02d" diff --git a/server/src/main/scala/actors/daily/TerminalDayQueuesActor.scala b/server/src/main/scala/actors/daily/TerminalDayQueuesActor.scala index 01c112f95..7fd6b89db 100644 --- a/server/src/main/scala/actors/daily/TerminalDayQueuesActor.scala +++ b/server/src/main/scala/actors/daily/TerminalDayQueuesActor.scala @@ -9,9 +9,11 @@ import uk.gov.homeoffice.drt.ports.Terminals.Terminal import uk.gov.homeoffice.drt.protobuf.messages.CrunchState.{CrunchMinuteMessage, CrunchMinutesMessage} import uk.gov.homeoffice.drt.time.{SDateLike, UtcDate} +import scala.concurrent.Future + object TerminalDayQueuesActor { - def props(maybeUpdateLiveView: Option[(UtcDate, Iterable[CrunchMinute]) => Unit]) + def props(maybeUpdateLiveView: Option[(UtcDate, Iterable[CrunchMinute]) => Future[Unit]]) (terminal: Terminal, date: UtcDate, now: () => SDateLike, @@ -28,7 +30,7 @@ class TerminalDayQueuesActor(year: Int, terminal: Terminal, val now: () => SDateLike, maybePointInTime: Option[MillisSinceEpoch], - override val onUpdate: Option[(UtcDate, Iterable[CrunchMinute]) => Unit], + override val onUpdate: Option[(UtcDate, Iterable[CrunchMinute]) => Future[Unit]], ) extends TerminalDayLikeActor[CrunchMinute, TQM, CrunchMinuteMessage](year, month, day, terminal, now, maybePointInTime) { override val persistenceIdType: String = "queues" diff --git a/server/src/main/scala/controllers/application/api/v1/FlightsApiController.scala b/server/src/main/scala/controllers/application/api/v1/FlightsApiController.scala index 69caf36dd..0a623dee6 100644 --- a/server/src/main/scala/controllers/application/api/v1/FlightsApiController.scala +++ b/server/src/main/scala/controllers/application/api/v1/FlightsApiController.scala @@ -10,8 +10,8 @@ import play.api.mvc._ import services.api.v1.FlightExport import services.api.v1.serialisation.FlightApiJsonProtocol import spray.json.enrichAny -import uk.gov.homeoffice.drt.arrivals.{Arrival, FlightsWithSplits} -import uk.gov.homeoffice.drt.auth.Roles.{ApiFlightAccess, ApiQueueAccess, SuperAdmin} +import uk.gov.homeoffice.drt.arrivals.{ApiFlightWithSplits, Arrival, FlightsWithSplits} +import uk.gov.homeoffice.drt.auth.Roles.{ApiFlightAccess, SuperAdmin} import uk.gov.homeoffice.drt.crunchsystem.DrtSystemInterface import uk.gov.homeoffice.drt.ports.FeedSource import uk.gov.homeoffice.drt.ports.Terminals.Terminal @@ -72,17 +72,19 @@ class FlightsApiController @Inject()(cc: ControllerComponents, ctrl: DrtSystemIn } Source(DateRange(startDate, endDate)) .mapAsync(1) { date => - ctrl.applicationService.flightsProvider.allTerminalsScheduledOn(date).runForeach { flights => - ctrl.updateFlightsLiveView(flights, Seq.empty) - log.info(s"Updated flights for $date") - } + log.info(s"Populating flights for $date") + ctrl.applicationService.flightsProvider.allTerminalsScheduledOn(date) + .runWith(Sink.fold(Seq.empty[ApiFlightWithSplits])(_ ++ _)) + .flatMap { flights => + ctrl.updateFlightsLiveView(flights, Seq.empty) + .map(_ => log.info(s"Updated flights for $date")) + } } .runWith(Sink.ignore) Ok("Flights populating") } } - private def parseOptionalEndDate(maybeString: Option[String], default: SDateLike): SDateLike = maybeString match { case None => default diff --git a/server/src/main/scala/controllers/application/api/v1/QueuesApiController.scala b/server/src/main/scala/controllers/application/api/v1/QueuesApiController.scala index 60adaeaa8..5a6102faa 100644 --- a/server/src/main/scala/controllers/application/api/v1/QueuesApiController.scala +++ b/server/src/main/scala/controllers/application/api/v1/QueuesApiController.scala @@ -8,7 +8,6 @@ import controllers.application.AuthController import drt.shared.CrunchApi import drt.shared.CrunchApi.MinutesContainer import play.api.mvc._ -import providers.MinutesProvider import services.api.v1.QueueExport import services.api.v1.serialisation.QueueApiJsonProtocol import spray.json.enrichAny diff --git a/server/src/main/scala/providers/FlightsProvider.scala b/server/src/main/scala/providers/FlightsProvider.scala index aebb6ceb3..f8f835001 100644 --- a/server/src/main/scala/providers/FlightsProvider.scala +++ b/server/src/main/scala/providers/FlightsProvider.scala @@ -51,9 +51,8 @@ case class FlightsProvider(flightsRouterActor: ActorRef) val start = SDate(date) val end = start.addDays(1).addMinutes(-1) val request = PartitionedPortStateActor.GetFlights(start.millisSinceEpoch, end.millisSinceEpoch) - flightsByUtcDate(request).map { case (_, flights) => - flights.filter(f => SDate(f.apiFlight.Scheduled).toUtcDate == date) - } + flightsByUtcDate(request) + .map { case (_, flights) => flights.filter(f => SDate(f.apiFlight.Scheduled).toUtcDate == date) } } def allTerminalsDateRangeScheduledOrPcp: (UtcDate, UtcDate) => Source[(UtcDate, Seq[ApiFlightWithSplits]), NotUsed] = diff --git a/server/src/main/scala/uk/gov/homeoffice/drt/crunchsystem/DrtSystemInterface.scala b/server/src/main/scala/uk/gov/homeoffice/drt/crunchsystem/DrtSystemInterface.scala index 93934a930..c92f3f17b 100644 --- a/server/src/main/scala/uk/gov/homeoffice/drt/crunchsystem/DrtSystemInterface.scala +++ b/server/src/main/scala/uk/gov/homeoffice/drt/crunchsystem/DrtSystemInterface.scala @@ -28,7 +28,7 @@ import uk.gov.homeoffice.drt.routes.UserRoleProviderLike import uk.gov.homeoffice.drt.service.{ApplicationService, FeedService} import uk.gov.homeoffice.drt.time._ -import scala.concurrent.ExecutionContext +import scala.concurrent.{ExecutionContext, Future} trait DrtSystemInterface extends UserRoleProviderLike with FeatureGuideProviderLike @@ -72,19 +72,16 @@ trait DrtSystemInterface extends UserRoleProviderLike lazy val flightsForPcpDateRange: (LocalDate, LocalDate, Seq[Terminal]) => Source[(UtcDate, Seq[ApiFlightWithSplits]), NotUsed] = flightDao.flightsForPcpDateRange(airportConfig.portCode, paxFeedSourceOrder, aggregatedDb.run) - lazy val updateFlightsLiveView: (Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Unit = { + lazy val updateFlightsLiveView: (Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Future[Unit] = { val doUpdate = FlightsLiveView.updateFlightsLiveView(flightDao, aggregatedDb, airportConfig.portCode) (updates, removals) => doUpdate(updates, removals) } - lazy val update15MinuteQueueSlotsLiveView: (UtcDate, Iterable[CrunchMinute]) => Unit = { + lazy val update15MinuteQueueSlotsLiveView: (UtcDate, Iterable[CrunchMinute]) => Future[Unit] = { val doUpdate = QueuesLiveView.updateQueuesLiveView(queueSlotDao, aggregatedDb, airportConfig.portCode) (date, updates) => - doUpdate(date, updates) - .recover { case e: Throwable => - log.error(s"Error updating FlightsLiveView: ${e.getMessage}") - } + doUpdate(date, updates).map(_ => ()) } def getRoles(config: Configuration, headers: Headers, session: Session): Set[Role] = { diff --git a/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestActors.scala b/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestActors.scala index 2e867438e..cf364310d 100644 --- a/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestActors.scala +++ b/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestActors.scala @@ -383,7 +383,7 @@ object TestActors { day: Int, terminal: Terminal, now: () => SDateLike, - onUpdate: Option[(UtcDate, Iterable[CrunchMinute]) => Unit], + onUpdate: Option[(UtcDate, Iterable[CrunchMinute]) => Future[Unit]], ) extends TerminalDayQueuesActor(year, month, day, terminal, now, None, onUpdate) with Resettable { override def resetState(): Unit = state.clear() @@ -409,7 +409,7 @@ object TestActors { paxFeedSourceOrder: List[FeedSource], requestHistoricSplitsActor: Option[ActorRef], requestHistoricPaxActor: Option[ActorRef], - maybeUpdateLiveView: Option[(Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Unit], + maybeUpdateLiveView: Option[(Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Future[Unit]], ) extends TerminalDayFlightActor( year, diff --git a/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestDrtSystem.scala b/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestDrtSystem.scala index 14dc1f7a1..8f6b214d0 100644 --- a/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestDrtSystem.scala +++ b/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestDrtSystem.scala @@ -12,8 +12,8 @@ import play.api.mvc.{Headers, Session} import slickdb._ import uk.gov.homeoffice.drt.auth.Roles.Role import uk.gov.homeoffice.drt.crunchsystem.{ActorsServiceLike, DrtSystemInterface} -import uk.gov.homeoffice.drt.db.dao.{FlightDao, IABFeatureDao, IUserFeedbackDao} -import uk.gov.homeoffice.drt.ports.{AirportConfig, PortCode} +import uk.gov.homeoffice.drt.db.dao.{IABFeatureDao, IUserFeedbackDao} +import uk.gov.homeoffice.drt.ports.AirportConfig import uk.gov.homeoffice.drt.service.FeedService import uk.gov.homeoffice.drt.testsystem.RestartActor.StartTestSystem import uk.gov.homeoffice.drt.testsystem.crunchsystem.TestPersistentStateActors diff --git a/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestFlightLookups.scala b/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestFlightLookups.scala index 3d93578ab..fde7b1f00 100644 --- a/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestFlightLookups.scala +++ b/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestFlightLookups.scala @@ -18,7 +18,7 @@ case class TestFlightLookups(system: ActorSystem, queuesByTerminal: Map[Terminal, Seq[Queue]], paxFeedSourceOrder: List[FeedSource], terminalSplits: Terminal => Option[Splits], - updateLiveView: (Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Unit, + updateLiveView: (Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Future[Unit], ) extends FlightLookupsLike { override val requestAndTerminateActor: ActorRef = system.actorOf(Props(new RequestAndTerminateActor()), "test-flights-lookup-kill-actor") diff --git a/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestMinuteLookups.scala b/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestMinuteLookups.scala index de054ef8e..6cfa4c1da 100644 --- a/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestMinuteLookups.scala +++ b/server/src/main/scala/uk/gov/homeoffice/drt/testsystem/TestMinuteLookups.scala @@ -17,7 +17,7 @@ case class TestMinuteLookups(system: ActorSystem, now: () => SDateLike, expireAfterMillis: Int, queuesByTerminal: Map[Terminal, Seq[Queue]], - updateLiveView: (UtcDate, Iterable[CrunchMinute]) => Unit, + updateLiveView: (UtcDate, Iterable[CrunchMinute]) => Future[Unit], ) (implicit val ec: ExecutionContext) extends MinuteLookupsLike { override val requestAndTerminateActor: ActorRef = system.actorOf(Props(new RequestAndTerminateActor()), "test-minutes-lookup-kill-actor") diff --git a/server/src/test/scala/actors/routing/FlightsRouterActorSpec.scala b/server/src/test/scala/actors/routing/FlightsRouterActorSpec.scala index 81a590c50..97d415d39 100644 --- a/server/src/test/scala/actors/routing/FlightsRouterActorSpec.scala +++ b/server/src/test/scala/actors/routing/FlightsRouterActorSpec.scala @@ -269,7 +269,7 @@ class FlightsRouterActorSpec extends CrunchTestLike { "Concerning persistence of flights" >> { "Given a router, I should see updates sent to it are persisted" >> { - val lookups = FlightLookups(system, myNow, queuesByTerminal = Map(T1 -> Seq(EeaDesk, NonEeaDesk, EGate)), None, paxFeedSourceOrder, _ => None, (_, _) => ()) + val lookups = FlightLookups(system, myNow, queuesByTerminal = Map(T1 -> Seq(EeaDesk, NonEeaDesk, EGate)), None, paxFeedSourceOrder, _ => None, (_, _) => Future.successful(())) val router = lookups.flightsRouterActor val scheduled = "2021-06-01T00:00" @@ -315,7 +315,7 @@ class FlightsRouterActorSpec extends CrunchTestLike { "Add red list pax to an existing arrival" in { val redListNow = SDate("2021-06-24T12:10:00") - val lookups = FlightLookups(system, () => redListNow, Map(T1 -> Seq(), T2 -> Seq()), None, paxFeedSourceOrder, _ => None, (_, _) => ()) + val lookups = FlightLookups(system, () => redListNow, Map(T1 -> Seq(), T2 -> Seq()), None, paxFeedSourceOrder, _ => None, (_, _) => Future.successful(())) val redListPassengers = RedListPassengers("BA0001", PortCode("LHR"), SDate(scheduled), redListPax) val neboArrivalActor: ActorRef = system.actorOf(NeboArrivalActor.props(redListPassengers, () => redListNow)) val arrival = ArrivalGenerator.live(iata = "BA0001", terminal = T1, schDt = scheduled).toArrival(LiveFeedSource) @@ -335,7 +335,7 @@ class FlightsRouterActorSpec extends CrunchTestLike { "Add red list pax counts to the appropriate arrivals" in { val redListNow = SDate("2021-06-24T12:10:00") - val lookups = FlightLookups(system, () => redListNow, Map(T1 -> Seq(), T2 -> Seq()), None, paxFeedSourceOrder, _ => None, (_, _) => ()) + val lookups = FlightLookups(system, () => redListNow, Map(T1 -> Seq(), T2 -> Seq()), None, paxFeedSourceOrder, _ => None, (_, _) => Future.successful(())) val flightsRouter = lookups.flightsRouterActor val scheduled2 = "2021-06-24T15:05" val arrivalT1 = ArrivalGenerator.live(iata = "BA0001", terminal = T1, schDt = scheduled).toArrival(LiveFeedSource) @@ -365,7 +365,7 @@ class FlightsRouterActorSpec extends CrunchTestLike { "Retain red list pax counts after updating an arrival" in { val redListNow = SDate("2021-06-24T12:10:00") - val lookups = FlightLookups(system, () => redListNow, Map(T1 -> Seq(), T2 -> Seq()), None, paxFeedSourceOrder, _ => None, (_, _) => ()) + val lookups = FlightLookups(system, () => redListNow, Map(T1 -> Seq(), T2 -> Seq()), None, paxFeedSourceOrder, _ => None, (_, _) => Future.successful(())) val flightsRouter = lookups.flightsRouterActor val arrivalT1 = ArrivalGenerator.live(iata = "BA0001", terminal = T1, schDt = scheduled).toArrival(LiveFeedSource) val redListPax = util.RandomString.getNRandomString(10, 10) diff --git a/server/src/test/scala/actors/routing/minutes/QueueMinutesRouterActorSpec.scala b/server/src/test/scala/actors/routing/minutes/QueueMinutesRouterActorSpec.scala index 536cbee00..4bb72b8d8 100644 --- a/server/src/test/scala/actors/routing/minutes/QueueMinutesRouterActorSpec.scala +++ b/server/src/test/scala/actors/routing/minutes/QueueMinutesRouterActorSpec.scala @@ -33,7 +33,7 @@ class QueueMinutesRouterActorSpec extends CrunchTestLike { "When I send some PassengerMinutes to a QueueMinutesActor and query it" >> { "I should see the passenger minutes originally sent" >> { - val lookups = MinuteLookups(myNow, MilliTimes.oneDayMillis, Map(terminal -> Seq(queue)), (_, _) => ()) + val lookups = MinuteLookups(myNow, MilliTimes.oneDayMillis, Map(terminal -> Seq(queue)), (_, _) => Future.successful(())) val passengers1 = PassengersMinute(terminal, queue, date.millisSinceEpoch, Seq(1, 2, 3), None) val passengers2 = PassengersMinute(terminal, queue, date.addMinutes(1).millisSinceEpoch, Seq(4, 4, 4), None) val result = lookups.queueLoadsMinutesActor @@ -50,7 +50,7 @@ class QueueMinutesRouterActorSpec extends CrunchTestLike { "When I send two sets of PassengerMinutes to a QueueMinutesActor and query it" >> { "I should see the combined set of minutes" >> { - val lookups = MinuteLookups(myNow, MilliTimes.oneDayMillis, Map(terminal -> Seq(queue)), (_, _) => ()) + val lookups = MinuteLookups(myNow, MilliTimes.oneDayMillis, Map(terminal -> Seq(queue)), (_, _) => Future.successful(())) val passengers1 = PassengersMinute(terminal, queue, date.millisSinceEpoch, Seq(1, 2, 3), None) val passengers2 = PassengersMinute(terminal, queue, date.addMinutes(1).millisSinceEpoch, Seq(4, 4, 4), None) val newPassengers2 = PassengersMinute(terminal, queue, date.addMinutes(1).millisSinceEpoch, Seq(2, 2), None) diff --git a/server/src/test/scala/services/crunch/PortStateRequestsSpec.scala b/server/src/test/scala/services/crunch/PortStateRequestsSpec.scala index 3d693dc45..5a870308e 100644 --- a/server/src/test/scala/services/crunch/PortStateRequestsSpec.scala +++ b/server/src/test/scala/services/crunch/PortStateRequestsSpec.scala @@ -31,11 +31,11 @@ class PortStateRequestsSpec extends CrunchTestLike { val forecastMaxDays = 10 val forecastMaxMillis: () => MillisSinceEpoch = () => myNow().addDays(forecastMaxDays).millisSinceEpoch - val lookups: MinuteLookups = MinuteLookups(myNow, MilliTimes.oneDayMillis, airportConfig.queuesByTerminal, (_, _) => ()) + val lookups: MinuteLookups = MinuteLookups(myNow, MilliTimes.oneDayMillis, airportConfig.queuesByTerminal, (_, _) => Future.successful(())) val dummyLegacy1ActorProps: (SDateLike, Int) => Props = (_: SDateLike, _: Int) => Props() - val flightLookups: FlightLookups = FlightLookups(system, myNow, airportConfig.queuesByTerminal, None, paxFeedSourceOrder, _ => None, (_, _) => ()) + val flightLookups: FlightLookups = FlightLookups(system, myNow, airportConfig.queuesByTerminal, None, paxFeedSourceOrder, _ => None, (_, _) => Future.successful(())) val legacyDataCutOff: SDateLike = SDate("2020-01-01") val maxReplyMessages = 1000 diff --git a/server/src/test/scala/services/crunch/TestDrtActor.scala b/server/src/test/scala/services/crunch/TestDrtActor.scala index f6e6b1b04..6e8da481e 100644 --- a/server/src/test/scala/services/crunch/TestDrtActor.scala +++ b/server/src/test/scala/services/crunch/TestDrtActor.scala @@ -37,7 +37,6 @@ import uk.gov.homeoffice.drt.actor.TerminalDayFeedArrivalActor import uk.gov.homeoffice.drt.actor.commands.Commands.AddUpdatesSubscriber import uk.gov.homeoffice.drt.actor.commands.TerminalUpdateRequest import uk.gov.homeoffice.drt.arrivals.{ApiFlightWithSplits, Arrival, UniqueArrival, VoyageNumber} -import uk.gov.homeoffice.drt.crunchsystem.PersistentStateActors import uk.gov.homeoffice.drt.db.dao.{FlightDao, QueueSlotDao} import uk.gov.homeoffice.drt.egates.{EgateBank, EgateBanksUpdate, EgateBanksUpdates, PortEgateBanksUpdates} import uk.gov.homeoffice.drt.model.CrunchMinute @@ -47,7 +46,6 @@ import uk.gov.homeoffice.drt.ports._ import uk.gov.homeoffice.drt.redlist.RedListUpdates import uk.gov.homeoffice.drt.service.ProdFeedService.{getFeedArrivalsLookup, partitionUpdates, partitionUpdatesBase, updateFeedArrivals} import uk.gov.homeoffice.drt.service.{ManifestPersistence, ProdFeedService} -import uk.gov.homeoffice.drt.testsystem.TestActors.MockAggregatedArrivalsActor import uk.gov.homeoffice.drt.time._ import scala.collection.SortedSet @@ -195,36 +193,26 @@ class TestDrtActor extends Actor { val manifestsRouterActor: ActorRef = system.actorOf(Props(new ManifestRouterActor(manifestLookups.manifestsByDayLookup, manifestLookups.updateManifests))) - val actors = new PersistentStateActors() { - override val manifestsRouterActor: ActorRef = manifestsRouterActor - - override val mergeArrivalsQueueActor: ActorRef = TestProbe("merge-arrivals-queue-actor").ref - override val crunchQueueActor: ActorRef = TestProbe("crunch-queue-actor").ref - override val deskRecsQueueActor: ActorRef = TestProbe("desk-recs-queue-actor").ref - override val deploymentQueueActor: ActorRef = TestProbe("deployments-queue-actor").ref - override val staffingQueueActor: ActorRef = TestProbe("staffing-queue-actor").ref - } - val (updateFlightsLiveView, update15MinuteQueueSlotsLiveView) = tc.maybeAggregatedDbTables match { case Some(dbTables) => val flightDao = FlightDao() val queueSlotDao = QueueSlotDao() - val updateFlightsLiveView: (Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Unit = { + val updateFlightsLiveView: (Iterable[ApiFlightWithSplits], Iterable[UniqueArrival]) => Future[Unit] = { val doUpdate = FlightsLiveView.updateFlightsLiveView(flightDao, dbTables, airportConfig.portCode) (updates, removals) => doUpdate(updates, removals) } - val update15MinuteQueueSlotsLiveView: (UtcDate, Iterable[CrunchMinute]) => Unit = { + val update15MinuteQueueSlotsLiveView: (UtcDate, Iterable[CrunchMinute]) => Future[Unit] = { val doUpdate = QueuesLiveView.updateQueuesLiveView(queueSlotDao, dbTables, airportConfig.portCode) (date, updates) => { - doUpdate(date, updates) + doUpdate(date, updates).map(_ => ()) } } (updateFlightsLiveView, update15MinuteQueueSlotsLiveView) case None => - ((_: Iterable[ApiFlightWithSplits], _: Iterable[UniqueArrival]) => (), (_: UtcDate, _: Iterable[CrunchMinute]) => ()) + ((_: Iterable[ApiFlightWithSplits], _: Iterable[UniqueArrival]) => Future.successful(()), (_: UtcDate, _: Iterable[CrunchMinute]) => Future.successful(())) } val flightLookups: FlightLookups = FlightLookups(system, tc.now, tc.airportConfig.queuesByTerminal, None, paxFeedSourceOrder, _ => None, updateFlightsLiveView) diff --git a/server/src/test/scala/services/crunch/VoyageManifestsSpec.scala b/server/src/test/scala/services/crunch/VoyageManifestsSpec.scala index 14ee69dbc..c0df2a1b3 100644 --- a/server/src/test/scala/services/crunch/VoyageManifestsSpec.scala +++ b/server/src/test/scala/services/crunch/VoyageManifestsSpec.scala @@ -285,7 +285,7 @@ class VoyageManifestsSpec extends CrunchTestLike { waitForFlightsInPortState(crunch.portStateTestProbe) offerAndWait(crunch.manifestsLiveInput, inputManifests) - val expected = Map(Queues.EeaDesk -> 1, Queues.EGate -> 1, Queues.NonEeaDesk -> 2.0) + val expected = Map(Queues.EeaDesk -> 1d, Queues.EGate -> 1d, Queues.NonEeaDesk -> 2d) crunch.portStateTestProbe.fishForMessage(2.seconds) { case ps: PortState => diff --git a/server/src/test/scala/services/crunch/deskrecs/DynamicRunnablePassengerLoadsSpec.scala b/server/src/test/scala/services/crunch/deskrecs/DynamicRunnablePassengerLoadsSpec.scala index 474ea4972..0c8b61131 100644 --- a/server/src/test/scala/services/crunch/deskrecs/DynamicRunnablePassengerLoadsSpec.scala +++ b/server/src/test/scala/services/crunch/deskrecs/DynamicRunnablePassengerLoadsSpec.scala @@ -7,7 +7,6 @@ import akka.pattern.StatusReply import akka.testkit.TestProbe import controllers.ArrivalGenerator import drt.shared.CrunchApi.{MinutesContainer, PassengersMinute} -import drt.shared._ import manifests.queues.SplitsCalculator import queueus._ import services.TryCrunchWholePax diff --git a/server/src/test/scala/services/exports/FlightExportSpec.scala b/server/src/test/scala/services/exports/FlightExportSpec.scala index c155661a0..eabedd664 100644 --- a/server/src/test/scala/services/exports/FlightExportSpec.scala +++ b/server/src/test/scala/services/exports/FlightExportSpec.scala @@ -37,7 +37,7 @@ class FlightExportSpec extends AnyWordSpec with Matchers { ArrivalGenerator.arrival(iata = "BA0004", schDt = "2024-10-15T15:00", totalPax = Option(200), transPax = Option(10), feedSource = LiveFeedSource), )) } - val export = FlightExport(source, Seq(T1), PortCode("LHR")) + val `export` = FlightExport(source, Seq(T1), PortCode("LHR")) Await.result(export(startMinute, endMinute), 1.second) shouldEqual PortFlightsJson( PortCode("LHR"), diff --git a/server/src/test/scala/services/exports/QueueExportSpec.scala b/server/src/test/scala/services/exports/QueueExportSpec.scala index 466c1a68c..2cc991ff7 100644 --- a/server/src/test/scala/services/exports/QueueExportSpec.scala +++ b/server/src/test/scala/services/exports/QueueExportSpec.scala @@ -50,7 +50,7 @@ class QueueExportSpec extends AnyWordSpec with Matchers { ), )) } - val export = QueueExport(source, Seq(T1), PortCode("LHR")) + val `export` = QueueExport(source, Seq(T1), PortCode("LHR")) Await.result(export(start, end, 15), 1.second) shouldEqual PortQueuesJson( PortCode("LHR"), diff --git a/server/src/test/scala/services/graphstages/ArrivalsGraphStageSpec.scala b/server/src/test/scala/services/graphstages/ArrivalsGraphStageSpec.scala index b7978486d..8b99e6e5c 100644 --- a/server/src/test/scala/services/graphstages/ArrivalsGraphStageSpec.scala +++ b/server/src/test/scala/services/graphstages/ArrivalsGraphStageSpec.scala @@ -4,12 +4,10 @@ import controllers.ArrivalGenerator import controllers.ArrivalGenerator.{forecast, live} import drt.server.feeds.{ArrivalsFeedSuccess, DqManifests, ManifestsFeedResponse, ManifestsFeedSuccess} import drt.shared._ -import passengersplits.core.PassengerTypeCalculatorValues.DocumentType import passengersplits.parsing.VoyageManifestParser._ import services.PcpArrival.pcpFrom import services.crunch.VoyageManifestGenerator.{euIdCard, xOfPaxType} import services.crunch.{CrunchGraphInputsAndProbes, CrunchTestLike, TestConfig} -import uk.gov.homeoffice.drt.Nationality import uk.gov.homeoffice.drt.arrivals.SplitStyle.Percentage import uk.gov.homeoffice.drt.arrivals._ import uk.gov.homeoffice.drt.ports.PaxTypes.EeaMachineReadable diff --git a/server/src/test/scala/services/staffing/StaffMinutesCheckerSpec.scala b/server/src/test/scala/services/staffing/StaffMinutesCheckerSpec.scala index 4d7cc108b..7875da775 100644 --- a/server/src/test/scala/services/staffing/StaffMinutesCheckerSpec.scala +++ b/server/src/test/scala/services/staffing/StaffMinutesCheckerSpec.scala @@ -1,23 +1,19 @@ package services.staffing -import akka.Done import akka.actor.ActorSystem import akka.testkit.TestProbe -import akka.util.Timeout import org.specs2.mutable.Specification import uk.gov.homeoffice.drt.actor.commands.TerminalUpdateRequest import uk.gov.homeoffice.drt.ports.config.Lhr import uk.gov.homeoffice.drt.time.{LocalDate, SDate} -import scala.concurrent.duration.DurationInt -import scala.concurrent.{ExecutionContext, ExecutionContextExecutor, Future} +import scala.concurrent.{ExecutionContext, ExecutionContextExecutor} class StaffMinutesCheckerSpec extends Specification { "Given a StaffMinutesChecker with LHR's config and max-forecast-days of 2" >> { "I should see TerminalUpdateRequests for every terminal for the last 2 days of the max forecast period" >> { implicit val system: ActorSystem = ActorSystem("test") implicit val ec: ExecutionContextExecutor = ExecutionContext.global - implicit val timeout: Timeout = new Timeout(1.second) val testProbe = TestProbe("staffing-update-requests-queue") val today = SDate("2023-01-08T10:00") diff --git a/server/src/test/scala/services/workload/QueueProcessorTest.scala b/server/src/test/scala/services/workload/QueueProcessorTest.scala index 3cd064933..2572d8e01 100644 --- a/server/src/test/scala/services/workload/QueueProcessorTest.scala +++ b/server/src/test/scala/services/workload/QueueProcessorTest.scala @@ -3,10 +3,6 @@ package services.workload import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec import services.workload.QueueProcessor.processQueue -import services.{OptimiserConfig, OptimiserWithFlexibleProcessors, OptimizerCrunchResult, TryRenjin, WorkloadProcessorsProvider} -import uk.gov.homeoffice.drt.egates.Desk - -import scala.util.Try class QueueProcessorTest extends AnyWordSpec with Matchers { "applyCapacity" should { From 2d5df6b685e777878241b5e8f4f8b11655d62bc2 Mon Sep 17 00:00:00 2001 From: Rich Birch Date: Fri, 29 Nov 2024 09:02:07 +0000 Subject: [PATCH 2/2] DRTII-1693 Tidying --- client/package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/package-lock.json b/client/package-lock.json index a0bdc4f47..ccb8f38ba 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -1,5 +1,5 @@ { - "name": "test", + "name": "main", "lockfileVersion": 3, "requires": true, "packages": {