use of cn.taketoday.core.testfixture.EnabledForTestGroups in project today-infrastructure by TAKETODAY.
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 cn.taketoday.core.testfixture.EnabledForTestGroups in project today-infrastructure by TAKETODAY.
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();
}
use of cn.taketoday.core.testfixture.EnabledForTestGroups in project today-infrastructure by TAKETODAY.
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);
}
use of cn.taketoday.core.testfixture.EnabledForTestGroups in project today-infrastructure by TAKETODAY.
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);
}
use of cn.taketoday.core.testfixture.EnabledForTestGroups in project today-infrastructure by TAKETODAY.
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-");
}
Aggregations