Search in sources :

Example 6 with EnabledForTestGroups

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

the class QuartzSupportTests method schedulerWithSpringBeanJobFactory.

@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithSpringBeanJobFactory() throws Exception {
    DummyJob.param = 0;
    DummyJob.count = 0;
    JobDetailImpl jobDetail = new JobDetailImpl();
    jobDetail.setDurability(true);
    jobDetail.setJobClass(DummyJob.class);
    jobDetail.setName("myJob");
    jobDetail.getJobDataMap().put("param", "10");
    jobDetail.getJobDataMap().put("ignoredParam", "10");
    SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
    trigger.setName("myTrigger");
    trigger.setJobDetail(jobDetail);
    trigger.setStartDelay(1);
    trigger.setRepeatInterval(500);
    trigger.setRepeatCount(1);
    trigger.afterPropertiesSet();
    SchedulerFactoryBean bean = new SchedulerFactoryBean();
    bean.setJobFactory(new SpringBeanJobFactory());
    bean.setTriggers(trigger.getObject());
    bean.setJobDetails(jobDetail);
    bean.afterPropertiesSet();
    bean.start();
    Thread.sleep(500);
    assertThat(DummyJob.param).isEqualTo(10);
    assertThat(DummyJob.count > 0).as("DummyJob should have been executed at least once.").isTrue();
    bean.destroy();
}
Also used : JobDetailImpl(org.quartz.impl.JobDetailImpl) Test(org.junit.jupiter.api.Test) EnabledForTestGroups(org.springframework.core.testfixture.EnabledForTestGroups)

Example 7 with EnabledForTestGroups

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

the class QuartzSupportTests method schedulerWithTaskExecutor.

@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithTaskExecutor() throws Exception {
    CountingTaskExecutor taskExecutor = new CountingTaskExecutor();
    DummyJob.count = 0;
    JobDetailImpl jobDetail = new JobDetailImpl();
    jobDetail.setDurability(true);
    jobDetail.setJobClass(DummyJob.class);
    jobDetail.setName("myJob");
    SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
    trigger.setName("myTrigger");
    trigger.setJobDetail(jobDetail);
    trigger.setStartDelay(1);
    trigger.setRepeatInterval(500);
    trigger.setRepeatCount(1);
    trigger.afterPropertiesSet();
    SchedulerFactoryBean bean = new SchedulerFactoryBean();
    bean.setTaskExecutor(taskExecutor);
    bean.setTriggers(trigger.getObject());
    bean.setJobDetails(jobDetail);
    bean.afterPropertiesSet();
    bean.start();
    Thread.sleep(500);
    assertThat(DummyJob.count > 0).as("DummyJob should have been executed at least once.").isTrue();
    assertThat(taskExecutor.count).isEqualTo(DummyJob.count);
    bean.destroy();
}
Also used : JobDetailImpl(org.quartz.impl.JobDetailImpl) Test(org.junit.jupiter.api.Test) EnabledForTestGroups(org.springframework.core.testfixture.EnabledForTestGroups)

Example 8 with EnabledForTestGroups

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

the class EnableSchedulingTests method withExplicitScheduledTaskRegistrar.

@Test
@EnabledForTestGroups(LONG_RUNNING)
public void withExplicitScheduledTaskRegistrar() throws InterruptedException {
    ctx = new AnnotationConfigApplicationContext(ExplicitScheduledTaskRegistrarConfig.class);
    assertThat(ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size()).isEqualTo(1);
    Thread.sleep(100);
    assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThanOrEqualTo(10);
    assertThat(ctx.getBean(ExplicitScheduledTaskRegistrarConfig.class).threadName).startsWith("explicitScheduler1");
}
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 9 with EnabledForTestGroups

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

the class EnableSchedulingTests method withAmbiguousTaskSchedulers_andSingleTask_disambiguatedByScheduledTaskRegistrarBean.

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

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

the class EnableSchedulingTests method withTaskAddedVia_configureTasks.

@Test
@EnabledForTestGroups(LONG_RUNNING)
public void withTaskAddedVia_configureTasks() throws InterruptedException {
    ctx = new AnnotationConfigApplicationContext(SchedulingEnabled_withTaskAddedVia_configureTasks.class);
    Thread.sleep(100);
    assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread).startsWith("taskScheduler-");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) 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