use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.
the class ScheduledExecutorFactoryBeanTests method oneTimeExecutionIsSetUpAndFiresCorrectly.
@Test
@EnabledForTestGroups(LONG_RUNNING)
void oneTimeExecutionIsSetUpAndFiresCorrectly() throws Exception {
Runnable runnable = mock(Runnable.class);
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
factory.setScheduledExecutorTasks(new ScheduledExecutorTask(runnable));
factory.afterPropertiesSet();
pauseToLetTaskStart(1);
factory.destroy();
verify(runnable).run();
}
use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.
the class ScheduledExecutorFactoryBeanTests method withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException.
@Test
@EnabledForTestGroups(LONG_RUNNING)
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception {
Runnable runnable = mock(Runnable.class);
willThrow(new IllegalStateException()).given(runnable).run();
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
task.setPeriod(500);
// nice long wait...
task.setDelay(3000);
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
factory.setScheduledExecutorTasks(task);
factory.setContinueScheduledExecutionAfterException(true);
factory.afterPropertiesSet();
pauseToLetTaskStart(1);
// invoke destroy before tasks have even been scheduled...
factory.destroy();
// Mock must never have been called
verify(runnable, never()).run();
}
use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.
the class ScheduledExecutorFactoryBeanTests method fixedRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException.
@Test
@EnabledForTestGroups(LONG_RUNNING)
void fixedRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception {
Runnable runnable = mock(Runnable.class);
willThrow(new IllegalStateException()).given(runnable).run();
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
task.setPeriod(500);
task.setFixedRate(true);
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
factory.setScheduledExecutorTasks(task);
factory.setContinueScheduledExecutionAfterException(true);
factory.afterPropertiesSet();
pauseToLetTaskStart(2);
factory.destroy();
verify(runnable, atLeast(2)).run();
}
use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.
the class EnableSchedulingTests method withExplicitScheduler.
@Test
@EnabledForTestGroups(LONG_RUNNING)
public void withExplicitScheduler() throws InterruptedException {
ctx = new AnnotationConfigApplicationContext(ExplicitSchedulerConfig.class);
assertThat(ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size()).isEqualTo(1);
Thread.sleep(100);
assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThanOrEqualTo(10);
assertThat(ctx.getBean(ExplicitSchedulerConfig.class).threadName).startsWith("explicitScheduler-");
assertThat(Arrays.asList(ctx.getDefaultListableBeanFactory().getDependentBeans("myTaskScheduler")).contains(TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
}
use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.
the class EnableSchedulingTests method withFixedRateTask.
@Test
@EnabledForTestGroups(LONG_RUNNING)
public void withFixedRateTask() throws InterruptedException {
ctx = new AnnotationConfigApplicationContext(FixedRateTaskConfig.class);
assertThat(ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size()).isEqualTo(2);
Thread.sleep(100);
assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThanOrEqualTo(10);
}
Aggregations