use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.
the class DataSourceTransactionManagerTests method transactionWithTimeout.
@ParameterizedTest(name = "transaction with {0} second timeout")
@ValueSource(ints = { 1, 10 })
@EnabledForTestGroups(LONG_RUNNING)
public void transactionWithTimeout(int timeout) throws Exception {
PreparedStatement ps = mock(PreparedStatement.class);
given(con.getAutoCommit()).willReturn(true);
given(con.prepareStatement("some SQL statement")).willReturn(ps);
TransactionTemplate tt = new TransactionTemplate(tm);
tt.setTimeout(timeout);
boolean condition1 = !TransactionSynchronizationManager.hasResource(ds);
assertThat(condition1).as("Hasn't thread connection").isTrue();
try {
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
Thread.sleep(1500);
} catch (InterruptedException ex) {
}
try {
Connection con = DataSourceUtils.getConnection(ds);
PreparedStatement ps = con.prepareStatement("some SQL statement");
DataSourceUtils.applyTransactionTimeout(ps, ds);
} catch (SQLException ex) {
throw new DataAccessResourceFailureException("", ex);
}
}
});
if (timeout <= 1) {
fail("Should have thrown TransactionTimedOutException");
}
} catch (TransactionTimedOutException ex) {
if (timeout <= 1) {
// expected
} else {
throw ex;
}
}
boolean condition = !TransactionSynchronizationManager.hasResource(ds);
assertThat(condition).as("Hasn't thread connection").isTrue();
if (timeout > 1) {
verify(ps).setQueryTimeout(timeout - 1);
verify(con).commit();
} else {
verify(con).rollback();
}
InOrder ordered = inOrder(con);
ordered.verify(con).setAutoCommit(false);
ordered.verify(con).setAutoCommit(true);
verify(con).close();
}
use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.
the class JdbcTransactionManagerTests method transactionWithTimeout.
@ParameterizedTest(name = "transaction with {0} second timeout")
@ValueSource(ints = { 1, 10 })
@EnabledForTestGroups(LONG_RUNNING)
public void transactionWithTimeout(int timeout) throws Exception {
PreparedStatement ps = mock(PreparedStatement.class);
given(con.getAutoCommit()).willReturn(true);
given(con.prepareStatement("some SQL statement")).willReturn(ps);
TransactionTemplate tt = new TransactionTemplate(tm);
tt.setTimeout(timeout);
boolean condition1 = !TransactionSynchronizationManager.hasResource(ds);
assertThat(condition1).as("Hasn't thread connection").isTrue();
try {
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
Thread.sleep(1500);
} catch (InterruptedException ex) {
}
try {
Connection con = DataSourceUtils.getConnection(ds);
PreparedStatement ps = con.prepareStatement("some SQL statement");
DataSourceUtils.applyTransactionTimeout(ps, ds);
} catch (SQLException ex) {
throw new DataAccessResourceFailureException("", ex);
}
}
});
if (timeout <= 1) {
fail("Should have thrown TransactionTimedOutException");
}
} catch (TransactionTimedOutException ex) {
if (timeout <= 1) {
// expected
} else {
throw ex;
}
}
boolean condition = !TransactionSynchronizationManager.hasResource(ds);
assertThat(condition).as("Hasn't thread connection").isTrue();
if (timeout > 1) {
verify(ps).setQueryTimeout(timeout - 1);
verify(con).commit();
} else {
verify(con).rollback();
}
InOrder ordered = inOrder(con);
ordered.verify(con).setAutoCommit(false);
ordered.verify(con).setAutoCommit(true);
verify(con).close();
}
use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.
the class QuartzSupportTests method schedulerAccessorBean.
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerAccessorBean() throws Exception {
try (ClassPathXmlApplicationContext ctx = context("schedulerAccessorBean.xml")) {
QuartzTestBean exportService = (QuartzTestBean) ctx.getBean("exportService");
QuartzTestBean importService = (QuartzTestBean) ctx.getBean("importService");
Thread.sleep(400);
assertThat(exportService.getImportCount()).as("doImport called exportService").isEqualTo(0);
assertThat(exportService.getExportCount()).as("doExport not called on exportService").isEqualTo(2);
assertThat(importService.getImportCount()).as("doImport not called on importService").isEqualTo(2);
assertThat(importService.getExportCount()).as("doExport called on importService").isEqualTo(0);
}
}
use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.
the class QuartzSupportTests method schedulerWithSpringBeanJobFactoryAndQuartzJobBean.
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception {
DummyJobBean.param = 0;
DummyJobBean.count = 0;
JobDetailImpl jobDetail = new JobDetailImpl();
jobDetail.setDurability(true);
jobDetail.setJobClass(DummyJobBean.class);
jobDetail.setName("myJob");
jobDetail.getJobDataMap().put("param", "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(DummyJobBean.param).isEqualTo(10);
assertThat(DummyJobBean.count > 0).isTrue();
bean.destroy();
}
use of org.springframework.core.testfixture.EnabledForTestGroups in project spring-framework by spring-projects.
the class QuartzSupportTests method schedulerWithQuartzJobBean.
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithQuartzJobBean() throws Exception {
DummyJob.param = 0;
DummyJob.count = 0;
JobDetailImpl jobDetail = new JobDetailImpl();
jobDetail.setDurability(true);
jobDetail.setJobClass(DummyJobBean.class);
jobDetail.setName("myJob");
jobDetail.getJobDataMap().put("param", "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.setTriggers(trigger.getObject());
bean.setJobDetails(jobDetail);
bean.afterPropertiesSet();
bean.start();
Thread.sleep(500);
assertThat(DummyJobBean.param).isEqualTo(10);
assertThat(DummyJobBean.count > 0).isTrue();
bean.destroy();
}
Aggregations