Skip to content

Commit

Permalink
test: avoid bean pollution (#4956)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo committed Feb 18, 2021
1 parent ad62b2a commit 29158f0
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class ScheduledFixedRateSpec extends Specification {
given:
ApplicationContext beanContext = ApplicationContext.run(
'some.configuration':'10ms',
'scheduled-test.task.enabled':true
'scheduled-test.task.enabled':true,
'spec.name': 'ScheduledFixedRateSpecMyTask',
)

PollingConditions conditions = new PollingConditions(timeout: 10)
Expand All @@ -59,12 +60,16 @@ class ScheduledFixedRateSpec extends Specification {
myTask.wasDelayedRun
beanContext.getBean(MyJavaTask).wasRun
}

cleanup:
beanContext.close()
}

void 'test scheduled annotation with retry'() {
given:
ApplicationContext beanContext = ApplicationContext.run(
'scheduled-test.task2.enabled': true
'scheduled-test.task2.enabled': true,
'spec.name': 'ScheduledFixedRateSpecTask2',
)

PollingConditions conditions = new PollingConditions(timeout: 10)
Expand All @@ -77,12 +82,16 @@ class ScheduledFixedRateSpec extends Specification {
myTask.initialDelayWasRun
myTask.attempts.get() == 2
}

cleanup:
beanContext.close()
}

void 'test multiple schedule annotations'() {
given:
ApplicationContext beanContext = ApplicationContext.run(
'scheduled-test.task.enabled': true
'scheduled-test.task.enabled': true,
'spec.name': 'ScheduledFixedRateSpecMyOtherTask',
)

PollingConditions conditions = new PollingConditions(timeout: 20)
Expand All @@ -94,9 +103,13 @@ class ScheduledFixedRateSpec extends Specification {
conditions.eventually {
myTask.cronEvents.get() == 2
}

cleanup:
beanContext.close()
}

@Singleton
@Requires(property = 'spec.name', value = 'ScheduledFixedRateSpecMyTask')
@Requires(property = 'scheduled-test.task.enabled', value = 'true')
static class MyTask {

Expand Down Expand Up @@ -140,6 +153,7 @@ class ScheduledFixedRateSpec extends Specification {

@Singleton
@Requires(property = 'scheduled-test.task2.enabled', value = 'true')
@Requires(property = 'spec.name', value = 'ScheduledFixedRateSpecTask2')
static class MyTask2 {

boolean initialDelayWasRun = false
Expand All @@ -159,6 +173,7 @@ class ScheduledFixedRateSpec extends Specification {
}

@Singleton
@Requires(property = 'spec.name', value = 'ScheduledFixedRateSpecMyOtherTask')
@Requires(property = 'scheduled-test.task.enabled', value = 'true')
static class MyOtherTask {

Expand Down

0 comments on commit 29158f0

Please sign in to comment.