11package app .softnetwork .scheduler .handlers
22
3- import akka .actor .testkit .typed .scaladsl .TestProbe
43import akka .actor .typed .ActorSystem
54import app .softnetwork .persistence ._
65import app .softnetwork .scheduler .message .SampleMessages .{AddSample , SampleAdded }
76import app .softnetwork .scheduler .scalatest .SchedulerWithSampleTestKit
87import org .scalatest .wordspec .AnyWordSpecLike
98import app .softnetwork .scheduler .message ._
10- import app .softnetwork .scheduler .persistence .query .SampleScheduleTriggered
119import app .softnetwork .scheduler .persistence .typed .SampleBehavior
1210import org .softnetwork .akka .model .{CronTab , Schedule }
1311
@@ -25,14 +23,14 @@ class SchedulerHandlerSpec
2523 implicit lazy val ec : ExecutionContextExecutor = system.executionContext
2624
2725 " Scheduler" must {
26+ val cronTab = CronTab (SampleBehavior .persistenceId, ALL_KEY , " cron" , " * * * * *" )
2827 " add Cron Tab" in {
2928 // add Sample[sample] entity
3029 SampleHandler ? (" sample" , AddSample ) assert {
3130 case SampleAdded => succeed
3231 case _ => fail()
3332 }
3433 // add cron tab for all Sample entity
35- val cronTab = CronTab (SampleBehavior .persistenceId, ALL_KEY , " cron" , " * * * * *" )
3634 this !? AddCronTab (cronTab) assert {
3735 case _ : CronTabAdded => succeed
3836 case other => fail(other.getClass)
@@ -55,11 +53,31 @@ class SchedulerHandlerSpec
5553 case Some (schedule) =>
5654 assert(schedule.repeatedly.getOrElse(false ))
5755 assert(schedule.getScheduledDate.equals(schedule.getLastTriggered))
56+ assert(schedule.getCronTab == cronTab.uuid)
5857 case _ => fail(" schedule not found" )
5958 }
6059 case _ => fail()
6160 }
6261 }
62+ " remove Cron Tab" in {
63+ this !? RemoveCronTab (cronTab.persistenceId, cronTab.entityId, cronTab.key) assert {
64+ case _ : CronTabRemoved => succeed
65+ case other => fail(other.getClass)
66+ }
67+ this !? LoadScheduler assert {
68+ case r : SchedulerLoaded =>
69+ val scheduler = r.scheduler
70+ logger.info(scheduler.toProtoString)
71+ assert(! scheduler.cronTabs.exists(ct => ct.uuid == cronTab.uuid))
72+ scheduler.schedules.find(s =>
73+ s.persistenceId == SampleBehavior .persistenceId && s.entityId == " sample" && s.key == cronTab.key
74+ ) match {
75+ case Some (_) => fail()
76+ case _ => succeed
77+ }
78+ case _ => fail()
79+ }
80+ }
6381 " remove schedule that is not repeatable and has already been triggered" in {
6482 val schedule = Schedule (" p" , " 0" , " add" , 1 , None , None , None )
6583 // add schedule which has to be triggered
0 commit comments