Search in sources :

Example 11 with EnabledForTestGroups

use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.

the class EnableSchedulingTests method withAmbiguousTaskSchedulers_andSingleTask_disambiguatedBySchedulerNameAttribute.

@Test
@EnabledForTestGroups(LONG_RUNNING)
public void withAmbiguousTaskSchedulers_andSingleTask_disambiguatedBySchedulerNameAttribute() throws InterruptedException {
    ctx = new AnnotationConfigApplicationContext(SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask_disambiguatedBySchedulerNameAttribute.class);
    Thread.sleep(100);
    assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread).startsWith("explicitScheduler2-");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.jupiter.api.Test) EnabledForTestGroups(org.springframework.core.testfixture.EnabledForTestGroups)

Example 12 with EnabledForTestGroups

use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.

the class EnableSchedulingTests method withInitiallyDelayedFixedRateTask.

@Test
@EnabledForTestGroups(LONG_RUNNING)
public void withInitiallyDelayedFixedRateTask() throws InterruptedException {
    ctx = new AnnotationConfigApplicationContext(FixedRateTaskConfig_withInitialDelay.class);
    Thread.sleep(1950);
    AtomicInteger counter = ctx.getBean(AtomicInteger.class);
    // The @Scheduled method should have been called at least once but
    // not more times than the delay allows.
    assertThat(counter.get()).isBetween(1, 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)

Example 13 with EnabledForTestGroups

use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.

the class EnableSchedulingTests method withSubclass.

@Test
@EnabledForTestGroups(LONG_RUNNING)
public void withSubclass() throws InterruptedException {
    ctx = new AnnotationConfigApplicationContext(FixedRateTaskConfigSubclass.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)

Example 14 with EnabledForTestGroups

use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.

the class ScheduledExecutorFactoryBeanTests method withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectly.

@Test
@EnabledForTestGroups(LONG_RUNNING)
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
    Runnable runnable = mock(Runnable.class);
    ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
    task.setPeriod(500);
    // nice long wait...
    task.setDelay(3000);
    ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
    factory.setScheduledExecutorTasks(task);
    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 15 with EnabledForTestGroups

use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.

the class ScheduledExecutorFactoryBeanTests method fixedRepeatedExecutionIsSetUpAndFiresCorrectly.

@Test
@EnabledForTestGroups(LONG_RUNNING)
void fixedRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
    Runnable runnable = mock(Runnable.class);
    ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
    task.setPeriod(500);
    task.setFixedRate(true);
    ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
    factory.setScheduledExecutorTasks(task);
    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)

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