Skip to content

Commit

Permalink
DRTII-1675 Clear agg db h2 data on data resety
Browse files Browse the repository at this point in the history
  • Loading branch information
richbirch committed Nov 21, 2024
1 parent 96b9a61 commit 3da6fa3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions server/src/main/scala/actors/TestDrtSystemInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import drt.server.feeds.FeedPoller.Enable
import org.slf4j.{Logger, LoggerFactory}
import play.api.Configuration
import uk.gov.homeoffice.drt.crunchsystem.{ActorsServiceLike, PersistentStateActors}
import uk.gov.homeoffice.drt.db.AggregateDb
import uk.gov.homeoffice.drt.service.{ApplicationService, FeedService}
import uk.gov.homeoffice.drt.testsystem.RestartActor
import uk.gov.homeoffice.drt.testsystem.db.AggregateDbH2
import uk.gov.homeoffice.drt.time.{MilliDate => _}

import scala.collection.SortedSet
import scala.concurrent.ExecutionContext

trait TestDrtSystemActorsLike {
val restartActor: ActorRef
Expand All @@ -21,9 +24,12 @@ case class TestDrtSystemActors(applicationService: ApplicationService,
actorService: ActorsServiceLike,
persistentActors: PersistentStateActors,
config: Configuration)
(implicit system: ActorSystem) extends TestDrtSystemActorsLike {
(implicit system: ActorSystem, ec: ExecutionContext) extends TestDrtSystemActorsLike {
val log: Logger = LoggerFactory.getLogger(getClass)
override val restartActor: ActorRef = system.actorOf(Props(new RestartActor(startSystem)), name = "TestActor-ResetData")

val clearAggDb = () => AggregateDbH2.dropAndCreateH2Tables()

override val restartActor: ActorRef = system.actorOf(Props(new RestartActor(startSystem, clearAggDb)), name = "TestActor-ResetData")

restartActor ! RestartActor.AddResetActors(Seq(
feedService.forecastBaseFeedArrivalsActor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object RestartActor {
case class AddResetActors(actors: Iterable[ActorRef])
}

class RestartActor(startSystem: () => List[KillSwitch]) extends Actor with ActorLogging {
class RestartActor(startSystem: () => List[KillSwitch], clearAggregatedDb: () => Unit) extends Actor with ActorLogging {

private lazy val persistenceTestKit: PersistenceTestKit = PersistenceTestKit(context.system)

Expand All @@ -41,6 +41,7 @@ class RestartActor(startSystem: () => List[KillSwitch]) extends Actor with Actor
}

resetInMemoryData()
clearAggregatedDb()

val resetFutures = actorsToReset
.map(_.ask(ResetData)(new Timeout(3.second)).recover {
Expand Down

0 comments on commit 3da6fa3

Please sign in to comment.