Updated tests to remove SQL Bad Grammar warnings

Also replacing the last of the SpringJunit4ClassRunner with SpringRunner
Other cleanup

resolves #482
This commit is contained in:
Glenn Renfro
2018-11-15 09:13:40 -05:00
committed by Michael Minella
parent ab58cdd9df
commit fa3e4e55c6
10 changed files with 23 additions and 98 deletions

View File

@@ -43,13 +43,6 @@ public class TaskBatchProperties {
*/
private int commandLineRunnerOrder = 0;
/**
* Maximum wait time in milliseconds that Spring Cloud Task will wait for tasks to complete
* when spring.cloud.task.batch.failOnJobFailure is set to true. Defaults
* to 0. 0 indicates no wait time is enforced.
*/
private long failOnJobFailurewaitTime = 0;
/**
* Fixed delay in milliseconds that Spring Cloud Task will wait when checking if
* {@link org.springframework.batch.core.JobExecution}s have completed,
@@ -74,14 +67,6 @@ public class TaskBatchProperties {
this.commandLineRunnerOrder = commandLineRunnerOrder;
}
public long getFailOnJobFailurewaitTime() {
return failOnJobFailurewaitTime;
}
public void setFailOnJobFailurewaitTime(long failOnJobFailurewaitTime) {
this.failOnJobFailurewaitTime = failOnJobFailurewaitTime;
}
public long getFailOnJobFailurePollInterval() {
return failOnJobFailurePollInterval;
}

View File

@@ -183,12 +183,6 @@ public class TaskJobLauncherCommandLineRunner extends JobLauncherCommandLineRunn
if (repeatStatus.equals(RepeatStatus.FINISHED) && failedJobExecutions.size() > 0) {
throwJobFailedException(failedJobExecutions);
}
if (repeatStatus.isContinuable() && taskBatchProperties.getFailOnJobFailurewaitTime() != 0
&& (new Date()).getTime() - startDate.getTime() > taskBatchProperties.getFailOnJobFailurewaitTime()) {
throw new IllegalStateException("Not all jobs were completed " +
"within the time specified by spring.cloud.task.batch." +
"failOnJobFailurewaitTime.");
}
return repeatStatus;
});
}

View File

@@ -45,8 +45,8 @@ import org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.cloud.task.batch.configuration.TaskBatchAutoConfiguration;
import org.springframework.cloud.task.batch.configuration.TaskJobLauncherAutoConfiguration;
import org.springframework.cloud.task.batch.configuration.TaskBatchTest;
import org.springframework.cloud.task.batch.configuration.TaskJobLauncherAutoConfiguration;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
@@ -74,7 +74,7 @@ public class TaskJobLauncherCommandLineRunnerTests {
@After
public void tearDown() {
if (this.applicationContext != null) {
if (this.applicationContext != null && this.applicationContext.isActive()) {
this.applicationContext.close();
}
}
@@ -108,19 +108,6 @@ public class TaskJobLauncherCommandLineRunnerTests {
enabledArgs);
}
@Test
public void testTaskJobLauncherCLRSuccessWithLongWaitTaskExecutor() {
String[] enabledArgs = new String[] {
"--spring.cloud.task.batch.failOnJobFailure=true",
"--spring.cloud.task.batch.failOnJobFailurePollInterval=500",
"--spring.cloud.task.batch.failOnJobFailurewaitTime=1000"
};
validateForFail("Not all jobs were completed within the time specified by spring.cloud.task.batch.failOnJobFailurewaitTime.",
TaskJobLauncherCommandLineRunnerTests.JobWithFailureTaskExecutorLongWaitConfiguration.class,
enabledArgs);
}
@Test
public void testTaskJobLauncherPickOneJob() {
String[] enabledArgs = new String[] {
@@ -259,60 +246,6 @@ public class TaskJobLauncherCommandLineRunnerTests {
}
}
@EnableBatchProcessing
@ImportAutoConfiguration({
PropertyPlaceholderAutoConfiguration.class,
BatchAutoConfiguration.class,
TaskBatchAutoConfiguration.class,
TaskJobLauncherAutoConfiguration.class,
SingleTaskConfiguration.class,
SimpleTaskAutoConfiguration.class })
@Import(EmbeddedDataSourceConfiguration.class)
public static class JobWithFailureTaskExecutorLongWaitConfiguration {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Bean
public BatchConfigurer batchConfigurer(DataSource dataSource) {
return new TestBatchConfigurer(dataSource);
}
@Bean
public Job jobShortRunner() {
return jobBuilderFactory.get("jobSucceedShort")
.start(stepBuilderFactory.get("step1SucceedSort").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext)
throws Exception {
System.out.println("Executed Short Runner");
return RepeatStatus.FINISHED;
}
}).build())
.build();
}
@Bean
public Job jobLongRunner() {
return jobBuilderFactory.get("jobSucceedLong")
.start(stepBuilderFactory.get("step1SucceedLong").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext)
throws Exception {
System.out.println("Executed Long Runner");
Thread.sleep(5000);
return RepeatStatus.FINISHED;
}
}).build())
.build();
}
}
private static class TestBatchConfigurer extends DefaultBatchConfigurer{
public TestBatchConfigurer(DataSource dataSource) {
super(dataSource);

View File

@@ -48,7 +48,7 @@ public class PrefixTests {
@After
public void tearDown() {
if (this.applicationContext != null) {
if (this.applicationContext != null && this.applicationContext.isActive()) {
this.applicationContext.close();
}
}

View File

@@ -74,7 +74,7 @@ public class TaskBatchExecutionListenerTests {
@After
public void tearDown() {
if(this.applicationContext != null) {
if(this.applicationContext != null && this.applicationContext.isActive()) {
this.applicationContext.close();
}
}

View File

@@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfigurati
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
import org.springframework.cloud.task.configuration.TaskConfigurer;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -44,6 +45,7 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {SimpleTaskAutoConfiguration.class,
EmbeddedDataSourceConfiguration.class})
@DirtiesContext
public class TaskRepositoryInitializerDefaultTaskConfigurerTests {
@Autowired

View File

@@ -32,6 +32,7 @@ import org.springframework.cloud.task.repository.TaskExecution;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -46,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = { TaskListenerExecutorObjectFactoryTests.TaskExecutionListenerConfiguration.class })
@DirtiesContext
public class TaskListenerExecutorObjectFactoryTests {
public static final String BEFORE_LISTENER = "BEFORE LISTENER";

View File

@@ -27,6 +27,7 @@ import javax.sql.DataSource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
@@ -41,7 +42,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
@@ -51,7 +52,7 @@ import static org.junit.Assert.assertEquals;
* @author Glenn Renfro
* @author Gunnar Hillert
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {TestConfiguration.class,
EmbeddedDataSourceConfiguration.class,
PropertyPlaceholderAutoConfiguration.class})

View File

@@ -19,6 +19,7 @@ package org.springframework.cloud.task.repository.support;
import java.util.Collections;
import java.util.Date;
import java.util.UUID;
import javax.sql.DataSource;
import org.junit.Test;
@@ -35,7 +36,7 @@ import org.springframework.cloud.task.util.TestDBUtils;
import org.springframework.cloud.task.util.TestVerifierUtils;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
@@ -46,10 +47,11 @@ import static org.junit.Assert.assertEquals;
* @author Michael Minella
* @author Ilayaperumal Gopinathan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {EmbeddedDataSourceConfiguration.class,
SimpleTaskAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class})
@DirtiesContext
public class SimpleTaskRepositoryJdbcTests {
@Autowired

View File

@@ -29,14 +29,15 @@ import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.util.SocketUtils;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
/**
* Verifies that a JPA Application can write its data to a repository.
@@ -55,6 +56,8 @@ public class JpaApplicationTests {
private static int randomPort;
private ConfigurableApplicationContext context;
static {
randomPort = SocketUtils.findAvailableTcpPort();
DATASOURCE_URL = "jdbc:h2:tcp://localhost:" + randomPort + "/mem:dataflow;DB_CLOSE_DELAY=-1;"
@@ -84,6 +87,9 @@ public class JpaApplicationTests {
@After
public void tearDown() {
if(this.context != null && this.context.isActive()) {
this.context.close();
}
this.server.stop();
}
@@ -93,7 +99,7 @@ public class JpaApplicationTests {
@Test
public void testBatchJobApp() {
final String INSERT_MESSAGE = "Hibernate: insert into task_run_output (";
SpringApplication.run(JpaApplication.class, "--spring.datasource.url=" + DATASOURCE_URL,
this.context = SpringApplication.run(JpaApplication.class, "--spring.datasource.url=" + DATASOURCE_URL,
"--spring.datasource.username=" + DATASOURCE_USER_NAME,
"--spring.datasource.driverClassName=" + DATASOURCE_DRIVER_CLASS_NAME,
"--spring.jpa.database-platform=org.hibernate.dialect.H2Dialect");