cgrim
cgrim

Reputation: 5031

Disable periodic task execution in Micronaut during unit test

Now I'm disabling periodic tasks by setting of initialDelay for each periodic task with value 10h in an application configuration which is used during unit tests.

Then the annotation for task method is like this:

@Scheduled(fixedDelay = '10s', initialDelay = '${some-domain.periodic-task.initial-delay}')
void periodicTask() {
    // periodic task implementation
}

And in application.yaml configuration used in unit test is:

someDomain:
  periodicTask:
    initialDelay: 10h

The question is: Is there a better way how to disable periodic task execution in Micronaut during unit test?

Because I feel that my solution is not nice - it's workaround. But I did not find any global setting for that or any specific annotation which can be used in unit test to achieve that etc.

Thank you

Upvotes: 4

Views: 1295

Answers (1)

Jeff Scott Brown
Jeff Scott Brown

Reputation: 27245

Is there a better way how to disable periodic task execution in Micronaut during unit test?

It really depends on the particulars but one option is to mark the beans which contain the periodic tasks with @Requires(notEnv="test").

Upvotes: 4

Related Questions