0

我在当前的 spring 项目中实现了一个带锁的调度程序,如下所示:

  @Scheduled(cron = "0 0/1 * * * *")
  @SchedulerLock(name = "syncData",
      lockAtMostFor = "${shedlock.myScheduler.lockAtMostFor}",
      lockAtLeastFor = "${shedlock.myScheduler.lockAtLeastFor}")
  public void syncSAData() {
    //To assert that the lock is held
    LockAssert.assertLocked();
    ...
  }

现在我想为这个函数编写单元测试。这里我面临的问题是:我无法模拟第一条语句:LockAssert.assertLocked()

4

1 回答 1

1

这应该可以解决问题LockAssert.TestHelper.makeAllAssertsPass(true);

只需在测试方法的开头添加它即可。

文档:https ://github.com/lukas-krecan/ShedLock#lock-assert

于 2020-08-20T15:31:56.003 回答