Added checkstyle

This commit is contained in:
Marcin Grzejszczak
2019-02-03 19:27:07 +01:00
parent 4d0acf120c
commit 60f1e21d03
249 changed files with 7450 additions and 5857 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring;
import java.util.ArrayList;
@@ -58,41 +59,40 @@ import org.springframework.core.io.Resource;
@Configuration
public class JobConfiguration {
private static final int GRID_SIZE = 4;
// @checkstyle:off
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Autowired
public DataSource dataSource;
@Autowired
public JobRepository jobRepository;
// @checkstyle:on
@Autowired
private ConfigurableApplicationContext context;
@Autowired
private DelegatingResourceLoader resourceLoader;
@Autowired
private Environment environment;
private static final int GRID_SIZE = 4;
@Bean
public PartitionHandler partitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer) throws Exception {
Resource resource = resourceLoader.getResource("maven://io.spring.cloud:partitioned-batch-job:1.1.0.RELEASE");
Resource resource = this.resourceLoader
.getResource("maven://io.spring.cloud:partitioned-batch-job:1.1.0.RELEASE");
DeployerPartitionHandler partitionHandler = new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, "workerStep");
DeployerPartitionHandler partitionHandler =
new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, "workerStep");
List<String> commandLineArgs = new ArrayList<>(3);
commandLineArgs.add("--spring.profiles.active=worker");
commandLineArgs.add("--spring.cloud.task.initialize.enable=false");
commandLineArgs.add("--spring.batch.initializer.enabled=false");
partitionHandler.setCommandLineArgsProvider(new PassThroughCommandLineArgsProvider(commandLineArgs));
partitionHandler.setEnvironmentVariablesProvider(new SimpleEnvironmentVariablesProvider(this.environment));
partitionHandler
.setCommandLineArgsProvider(new PassThroughCommandLineArgsProvider(commandLineArgs));
partitionHandler
.setEnvironmentVariablesProvider(new SimpleEnvironmentVariablesProvider(this.environment));
partitionHandler.setMaxWorkers(1);
partitionHandler.setApplicationName("PartitionedBatchJobTask");
@@ -107,7 +107,7 @@ public class JobConfiguration {
Map<String, ExecutionContext> partitions = new HashMap<>(gridSize);
for(int i = 0; i < GRID_SIZE; i++) {
for (int i = 0; i < GRID_SIZE; i++) {
ExecutionContext context1 = new ExecutionContext();
context1.put("partitionNumber", i);
@@ -128,7 +128,7 @@ public class JobConfiguration {
@Bean
@StepScope
public Tasklet workerTasklet(
final @Value("#{stepExecutionContext['partitionNumber']}")Integer partitionNumber) {
final @Value("#{stepExecutionContext['partitionNumber']}") Integer partitionNumber) {
return new Tasklet() {
@Override
@@ -142,26 +142,26 @@ public class JobConfiguration {
@Bean
public Step step1(PartitionHandler partitionHandler) throws Exception {
return stepBuilderFactory.get("step1")
.partitioner(workerStep().getName(), partitioner())
.step(workerStep())
.partitionHandler(partitionHandler)
.build();
return this.stepBuilderFactory.get("step1")
.partitioner(workerStep().getName(), partitioner())
.step(workerStep())
.partitionHandler(partitionHandler)
.build();
}
@Bean
public Step workerStep() {
return stepBuilderFactory.get("workerStep")
.tasklet(workerTasklet(null))
.build();
return this.stepBuilderFactory.get("workerStep")
.tasklet(workerTasklet(null))
.build();
}
@Bean
@Profile("!worker")
public Job partitionedJob(PartitionHandler partitionHandler) throws Exception {
Random random = new Random();
return jobBuilderFactory.get("partitionedJob"+random.nextInt())
.start(step1(partitionHandler))
.build();
return this.jobBuilderFactory.get("partitionedJob" + random.nextInt())
.start(step1(partitionHandler))
.build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.springframework.cloud.task.partitioner;
import java.sql.SQLException;
import javax.sql.DataSource;
import io.spring.PartitionedBatchJobApplication;
@@ -41,33 +42,31 @@ import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.SocketUtils;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {TaskPartitionerTests.TaskLauncherConfiguration.class})
public class TaskPartitionerTests {
private static String DATASOURCE_URL;
private final static String DATASOURCE_USER_NAME = "SA";
private final static String DATASOURCE_USER_PASSWORD = "";
private final static String DATASOURCE_DRIVER_CLASS_NAME = "org.h2.Driver";
private TaskExplorer taskExplorer;
@Autowired
private DataSource dataSource;
@Autowired
public void setDataSource(DataSource dataSource) {
taskExplorer = new SimpleTaskExplorer(new TaskExecutionDaoFactoryBean(dataSource));
}
private static String DATASOURCE_URL;
private static int randomPort;
static {
randomPort = SocketUtils.findAvailableTcpPort();
DATASOURCE_URL = "jdbc:h2:tcp://localhost:" + randomPort + "/mem:dataflow;DB_CLOSE_DELAY=-1;"
+ "DB_CLOSE_ON_EXIT=FALSE";
+ "DB_CLOSE_ON_EXIT=FALSE";
}
private TaskExplorer taskExplorer;
@Autowired
private DataSource dataSource;
@Autowired
public void setDataSource(DataSource dataSource) {
this.taskExplorer = new SimpleTaskExplorer(new TaskExecutionDaoFactoryBean(dataSource));
}
@Before
@@ -93,16 +92,23 @@ public class TaskPartitionerTests {
SpringApplication app = new SpringApplication(PartitionedBatchJobApplication.class);
app.setAdditionalProfiles("master");
app.run("--server.port=0", "--spring.datasource.url=" + DATASOURCE_URL,
"--spring.datasource.username=" + DATASOURCE_USER_NAME,
"--spring.datasource.driverClassName=" + DATASOURCE_DRIVER_CLASS_NAME,
"--spring.cloud.deployer.local.use-spring-application-json=false");
"--spring.datasource.username=" + DATASOURCE_USER_NAME,
"--spring.datasource.driverClassName=" + DATASOURCE_DRIVER_CLASS_NAME,
"--spring.cloud.deployer.local.use-spring-application-json=false");
Page<TaskExecution> taskExecutions = taskExplorer.findAll(PageRequest.of(0, 10));
assertEquals("Five rows are expected", 5, taskExecutions.getTotalElements());
assertEquals("Only One master is expected", 1, taskExplorer.getTaskExecutionCountByTaskName("Partitioned Batch Job Task:master:0"));
assertEquals("4 partitions is expected", 4, taskExplorer.getTaskExecutionCountByTaskName("Partitioned Batch Job Task:worker:0"));
Page<TaskExecution> taskExecutions = this.taskExplorer
.findAll(PageRequest.of(0, 10));
assertThat(taskExecutions.getTotalElements()).as("Five rows are expected")
.isEqualTo(5);
assertThat(this.taskExplorer
.getTaskExecutionCountByTaskName("Partitioned Batch Job Task:master:0"))
.as("Only One master is expected").isEqualTo(1);
assertThat(this.taskExplorer
.getTaskExecutionCountByTaskName("Partitioned Batch Job Task:worker:0"))
.as("4 partitions is expected").isEqualTo(4);
for (TaskExecution taskExecution : taskExecutions) {
assertEquals("return code should be 0", 0, taskExecution.getExitCode().intValue());
assertThat(taskExecution.getExitCode()
.intValue()).as("return code should be 0").isEqualTo(0);
}
}
@@ -114,7 +120,7 @@ public class TaskPartitionerTests {
Server server;
try {
server = Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort",
String.valueOf(randomPort)).start();
String.valueOf(randomPort)).start();
}
catch (SQLException e) {
throw new IllegalStateException(e);