Search in sources :

Example 16 with EnabledForTestGroups

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();
}
Also used : NoOpRunnable(org.springframework.core.task.NoOpRunnable) Test(org.junit.jupiter.api.Test) EnabledForTestGroups(org.springframework.core.testfixture.EnabledForTestGroups)

Example 17 with EnabledForTestGroups

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();
}
Also used : NoOpRunnable(org.springframework.core.task.NoOpRunnable) Test(org.junit.jupiter.api.Test) EnabledForTestGroups(org.springframework.core.testfixture.EnabledForTestGroups)

Example 18 with EnabledForTestGroups

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();
}
Also used : NoOpRunnable(org.springframework.core.task.NoOpRunnable) Test(org.junit.jupiter.api.Test) EnabledForTestGroups(org.springframework.core.testfixture.EnabledForTestGroups)

Example 19 with EnabledForTestGroups

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();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test) EnabledForTestGroups(org.springframework.core.testfixture.EnabledForTestGroups)

Example 20 with EnabledForTestGroups

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);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test) EnabledForTestGroups(org.springframework.core.testfixture.EnabledForTestGroups)

Aggregations

EnabledForTestGroups (org.springframework.core.testfixture.EnabledForTestGroups)25 Test (org.junit.jupiter.api.Test)23 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 JobDetailImpl (org.quartz.impl.JobDetailImpl)5 NoOpRunnable (org.springframework.core.task.NoOpRunnable)5 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 InOrder (org.mockito.InOrder)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)2 UncategorizedSQLException (org.springframework.jdbc.UncategorizedSQLException)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 TransactionTimedOutException (org.springframework.transaction.TransactionTimedOutException)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)2 HttpWebConnection (com.gargoylesoftware.htmlunit.HttpWebConnection)1