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,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.spring.cloud</groupId>
@@ -14,7 +16,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>
@@ -72,7 +74,7 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

View File

@@ -1,17 +1,17 @@
/*
* 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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.cloud;
@@ -61,42 +61,42 @@ public class BatchEventsApplication {
@Bean
public Step step1() {
return this.stepBuilderFactory.get("step1")
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
System.out.println("Tasklet has run");
return RepeatStatus.FINISHED;
}
}).build();
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
System.out.println("Tasklet has run");
return RepeatStatus.FINISHED;
}
}).build();
}
@Bean
public Step step2() {
return this.stepBuilderFactory.get("step2")
.<String, String>chunk(DEFAULT_CHUNK_COUNT)
.reader(new ListItemReader<>(Arrays.asList("1", "2", "3", "4", "5", "6")))
.processor(new ItemProcessor<String, String>() {
@Override
public String process(String item) throws Exception {
return String.valueOf(Integer.parseInt(item) * -1);
.<String, String>chunk(DEFAULT_CHUNK_COUNT)
.reader(new ListItemReader<>(Arrays.asList("1", "2", "3", "4", "5", "6")))
.processor(new ItemProcessor<String, String>() {
@Override
public String process(String item) throws Exception {
return String.valueOf(Integer.parseInt(item) * -1);
}
})
.writer(new ItemWriter<String>() {
@Override
public void write(List<? extends String> items) throws Exception {
for (String item : items) {
System.out.println(">> " + item);
}
})
.writer(new ItemWriter<String>() {
@Override
public void write(List<? extends String> items) throws Exception {
for (String item : items) {
System.out.println(">> " + item);
}
}
}).build();
}
}).build();
}
@Bean
public Job job() {
return this.jobBuilderFactory.get("job")
.start(step1())
.next(step2())
.build();
.start(step1())
.next(step2())
.build();
}
}
}

View File

@@ -1,17 +1,17 @@
/*
* 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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.cloud;
@@ -19,7 +19,7 @@ package io.spring.cloud;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.assertj.core.api.BDDAssertions;
import org.junit.ClassRule;
import org.junit.Test;
@@ -32,6 +32,8 @@ import org.springframework.cloud.task.batch.listener.support.JobExecutionEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import static org.assertj.core.api.Assertions.assertThat;
public class BatchEventsApplicationTests {
@ClassRule
@@ -42,13 +44,14 @@ public class BatchEventsApplicationTests {
@Test
public void testExecution() throws Exception {
SpringApplication.run(JobExecutionListenerBinding.class, "--spring.main.web-environment=false");
SpringApplication
.run(JobExecutionListenerBinding.class, "--spring.main.web-environment=false");
SpringApplication.run(BatchEventsApplication.class, "--server.port=0",
"--spring.cloud.stream.bindings.output.producer.requiredGroups=testgroup",
"--spring.jmx.default-domain=fakedomain",
"--spring.main.webEnvironment=false");
Assert.assertTrue("The latch did not count down to zero before timeout",
jobExecutionLatch.await(60, TimeUnit.SECONDS));
"--spring.cloud.stream.bindings.output.producer.requiredGroups=testgroup",
"--spring.jmx.default-domain=fakedomain",
"--spring.main.webEnvironment=false");
assertThat(jobExecutionLatch.await(60, TimeUnit.SECONDS))
.as("The latch did not count down to zero before timeout").isTrue();
}
@EnableBinding(Sink.class)
@@ -58,7 +61,8 @@ public class BatchEventsApplicationTests {
@StreamListener(Sink.INPUT)
public void receive(JobExecutionEvent execution) {
Assert.assertEquals("Job name should be job", "job", execution.getJobInstance().getJobName());
BDDAssertions.then(execution.getJobInstance().getJobName())
.isEqualTo("job").as("Job name should be job");
jobExecutionLatch.countDown();
}
}

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.
@@ -13,6 +13,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
spring.cloud.stream.bindings.input.destination=job-execution-events
spring.cloud.stream.bindings.input.group=testgroup

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.spring.cloud</groupId>
@@ -14,7 +16,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>

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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.configuration;
import org.apache.commons.logging.Log;
@@ -45,31 +46,31 @@ public class JobConfiguration {
@Bean
public Job job1() {
return jobBuilderFactory.get("job1")
.start(stepBuilderFactory.get("job1step1")
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
logger.info("Job1 was run");
return RepeatStatus.FINISHED;
}
})
.build())
.build();
return this.jobBuilderFactory.get("job1")
.start(this.stepBuilderFactory.get("job1step1")
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
logger.info("Job1 was run");
return RepeatStatus.FINISHED;
}
})
.build())
.build();
}
@Bean
public Job job2() {
return jobBuilderFactory.get("job2")
.start(stepBuilderFactory.get("job2step1")
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
logger.info("Job2 was run");
return RepeatStatus.FINISHED;
}
})
.build())
.build();
return this.jobBuilderFactory.get("job2")
.start(this.stepBuilderFactory.get("job2step1")
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
logger.info("Job2 was run");
return RepeatStatus.FINISHED;
}
})
.build())
.build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 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.
@@ -50,23 +50,23 @@ public class BatchJobApplicationTests {
String output = this.outputCapture.toString();
assertTrue("Unable to find the timestamp: " + output,
output.contains(JOB_RUN_MESSAGE));
output.contains(JOB_RUN_MESSAGE));
assertTrue("Test results do not show create task message: " + output,
output.contains(CREATE_TASK_MESSAGE));
output.contains(CREATE_TASK_MESSAGE));
assertTrue("Test results do not show success message: " + output,
output.contains(UPDATE_TASK_MESSAGE));
output.contains(UPDATE_TASK_MESSAGE));
assertTrue("Test results do not show success message: " + output,
output.contains(EXIT_CODE_MESSAGE));
output.contains(EXIT_CODE_MESSAGE));
int i = output.indexOf(JOB_ASSOCIATION_MESSAGE);
assertTrue("Test results do not show the listener message: " + output,
i > 0);
i > 0);
int j = output.indexOf(JOB_ASSOCIATION_MESSAGE, i + 1);
assertTrue("Test results do not show the listener message: " + output,
j > i);
j > i);
String taskTitle = "Demo Batch Job Task";

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.
@@ -13,6 +13,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
logging.level.root=DEBUG
spring.application.name=Demo Batch Job Task

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017 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,7 +13,10 @@
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.spring.cloud</groupId>
@@ -28,7 +31,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2017-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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring;

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2017 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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.configuration;
@@ -29,7 +29,7 @@ import org.springframework.stereotype.Component;
/**
* Records an entry in the TASK_RUN_OUTPUT table on the BeforeTask event.
*
*
* @author Glenn Renfro
* @author Pas Apicella
*/
@@ -44,7 +44,7 @@ public class TaskRunComponent {
@BeforeTask
public void init(TaskExecution taskExecution) {
String execDate = new SimpleDateFormat().format(new Date());
taskRunRepository.save(new TaskRunOutput("Executed at " + execDate));
this.taskRunRepository.save(new TaskRunOutput("Executed at " + execDate));
logger.info("Executed at : " + execDate);
}
}

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2017 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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.configuration;
@@ -24,7 +24,7 @@ import javax.persistence.Table;
/**
* Entity for the id and output to be written to the data store.
*
*
* @author Pas Apicella
* @author Glenn Renfro
*/
@@ -45,7 +45,7 @@ public class TaskRunOutput {
}
public Long getId() {
return id;
return this.id;
}
public void setId(Long id) {
@@ -53,7 +53,7 @@ public class TaskRunOutput {
}
public String getOutput() {
return output;
return this.output;
}
public void setOutput(String output) {
@@ -62,6 +62,6 @@ public class TaskRunOutput {
@Override
public String toString() {
return "TaskRunOutput{" + "id=" + id + ", output='" + output + '\'' + '}';
return "TaskRunOutput{" + "id=" + this.id + ", output='" + this.output + '\'' + '}';
}
}

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2017 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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.configuration;

View File

@@ -7,7 +7,7 @@ spring:
name: Spring Cloud Task JPA Sample Application
logging:
level:
org:
springframework:
cloud:
task: debug
org:
springframework:
cloud:
task: debug

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2017-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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring;
@@ -34,10 +34,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.util.SocketUtils;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Verifies that a JPA Application can write its data to a repository.
@@ -56,16 +53,16 @@ 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;"
+ "DB_CLOSE_ON_EXIT=FALSE";
+ "DB_CLOSE_ON_EXIT=FALSE";
}
@Rule
public OutputCapture outputCapture = new OutputCapture();
private ConfigurableApplicationContext context;
private DataSource dataSource;
private Server server;
@Before
@@ -77,8 +74,10 @@ public class JpaApplicationTests {
dataSource.setPassword(DATASOURCE_USER_PASSWORD);
this.dataSource = dataSource;
try {
this.server = Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort))
.start();
this.server = Server
.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", String
.valueOf(randomPort))
.start();
}
catch (SQLException e) {
throw new IllegalStateException(e);
@@ -87,28 +86,29 @@ public class JpaApplicationTests {
@After
public void tearDown() {
if(this.context != null && this.context.isActive()) {
if (this.context != null && this.context.isActive()) {
this.context.close();
}
this.server.stop();
}
@Rule
public OutputCapture outputCapture = new OutputCapture();
@Test
public void testBatchJobApp() {
final String INSERT_MESSAGE = "Hibernate: insert into task_run_output (";
this.context = 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");
String output = this.outputCapture.toString();
assertTrue("Unable to find the insert message: " + output, output.contains(INSERT_MESSAGE));
assertThat(output
.contains(INSERT_MESSAGE)).as("Unable to find the insert message: " + output)
.isTrue();
JdbcTemplate template = new JdbcTemplate(this.dataSource);
Map<String, Object> result = template.queryForMap("Select * from TASK_RUN_OUTPUT");
assertThat(result.get("ID"), is(1L));
assertThat(((String) result.get("OUTPUT")), containsString("Executed at"));
Map<String, Object> result = template
.queryForMap("Select * from TASK_RUN_OUTPUT");
assertThat(result.get("ID")).isEqualTo(1L);
assertThat(((String) result.get("OUTPUT"))).contains("Executed at");
}
}

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.
@@ -13,6 +13,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
logging.level.root=DEBUG
spring.application.name=Spring Cloud Task JPA Sample Application

View File

@@ -1,12 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.spring.cloud</groupId>
<artifactId>multiple-datasources</artifactId>
<packaging>jar</packaging>
<version>2.1.0.BUILD-SNAPSHOT</version>
<description>To show users how to enable a task with a multiple DataSources.</description>
<description>To show users how to enable a task with a multiple DataSources.
</description>
<name>Spring Cloud Task Multiple DataSources Application</name>
@@ -14,7 +17,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>

View File

@@ -1,17 +1,17 @@
/*
* 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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring;

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.configuration;
import javax.sql.DataSource;

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.configuration;
import javax.sql.DataSource;
@@ -31,14 +32,14 @@ public class DataSourceConfiguration {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.HSQL)
.build();
.setType(EmbeddedDatabaseType.HSQL)
.build();
}
@Bean
public DataSource secondDataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.build();
.setType(EmbeddedDatabaseType.H2)
.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,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.task;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
@@ -37,7 +39,7 @@ public class SampleCommandLineRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("There are " + dataSources.size() +
" DataSources within this application");
System.out.println("There are " + this.dataSources.size() +
" DataSources within this application");
}
}

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.junit.Rule;
@@ -21,7 +22,7 @@ import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.rule.OutputCapture;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Michael Minella
@@ -38,11 +39,11 @@ public class MultiDataSourcesApplicationTests {
String output = this.outputCapture.toString();
assertTrue("Unable to find CommandLineRunner output: " + output,
output.contains("There are 2 DataSources within this application"));
assertTrue("Unable to find start task message: " + output,
output.contains("Creating: TaskExecution{"));
assertTrue("Unable to find update task message: " + output,
output.contains("Updating: TaskExecution"));
assertThat(output.contains("There are 2 DataSources within this application"))
.as("Unable to find CommandLineRunner output: " + output).isTrue();
assertThat(output.contains("Creating: TaskExecution{"))
.as("Unable to find start task message: " + output).isTrue();
assertThat(output.contains("Updating: TaskExecution"))
.as("Unable to find update task message: " + output).isTrue();
}
}

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.
@@ -13,6 +13,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
spring.application.name=Demo Multiple DataSources Task
logging.level.org.springframework.cloud.task=DEBUG

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.spring.cloud</groupId>
@@ -13,7 +15,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>
@@ -159,7 +161,7 @@
</build>
</profile>
</profiles>
<repositories>
<repository>
<id>spring-snapshots</id>

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);

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.spring.cloud</groupId>
@@ -14,7 +16,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>
@@ -52,7 +54,7 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

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 org.springframework.boot.CommandLineRunner;

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.spring.cloud</groupId>
@@ -8,13 +10,14 @@
<packaging>jar</packaging>
<name>Task Processor Sample Application</name>
<description>Task processor converts inbound message to a TaskLaunchRequest</description>
<description>Task processor converts inbound message to a TaskLaunchRequest
</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>

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.
@@ -43,26 +43,32 @@ public class TaskProcessor {
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public Object setupRequest(String message) {
Map<String, String> properties = new HashMap<String,String>();
if(StringUtils.hasText(processorProperties.getDataSourceUrl())){
properties.put("spring_datasource_url",processorProperties.getDataSourceUrl());
Map<String, String> properties = new HashMap<>();
if (StringUtils.hasText(this.processorProperties.getDataSourceUrl())) {
properties
.put("spring_datasource_url", this.processorProperties
.getDataSourceUrl());
}
if(StringUtils.hasText(processorProperties.getDataSourceDriverClassName())){
properties.put("spring_datasource_driverClassName",processorProperties.getDataSourceDriverClassName());
if (StringUtils
.hasText(this.processorProperties.getDataSourceDriverClassName())) {
properties.put("spring_datasource_driverClassName", this.processorProperties
.getDataSourceDriverClassName());
}
if(StringUtils.hasText(processorProperties.getDataSourceUserName())){
properties.put("spring_datasource_username",processorProperties.getDataSourceUserName());
if (StringUtils.hasText(this.processorProperties.getDataSourceUserName())) {
properties.put("spring_datasource_username", this.processorProperties
.getDataSourceUserName());
}
if(StringUtils.hasText(processorProperties.getDataSourcePassword())){
properties.put("spring_datasource_password",processorProperties.getDataSourcePassword());
if (StringUtils.hasText(this.processorProperties.getDataSourcePassword())) {
properties.put("spring_datasource_password", this.processorProperties
.getDataSourcePassword());
}
properties.put("payload", message);
TaskLaunchRequest request = new TaskLaunchRequest(
processorProperties.getUri(), null, properties, null,
processorProperties.getApplicationName());
this.processorProperties.getUri(), null, properties, null,
this.processorProperties.getApplicationName());
return new GenericMessage<TaskLaunchRequest>(request);
return new GenericMessage<>(request);
}
}

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.

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.
@@ -25,7 +25,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class TaskProcessorProperties {
private static final String DEFAULT_URI = "maven://org.springframework.cloud.task.app:"
+ "timestamp-task:jar:1.0.1.RELEASE";
+ "timestamp-task:jar:1.0.1.RELEASE";
private String uri = DEFAULT_URI;
@@ -41,9 +41,8 @@ public class TaskProcessorProperties {
private String applicationName;
public String getDataSourceUrl() {
return dataSourceUrl;
return this.dataSourceUrl;
}
public void setDataSourceUrl(String dataSourceUrl) {
@@ -51,7 +50,7 @@ public class TaskProcessorProperties {
}
public String getDataSourceDriverClassName() {
return dataSourceDriverClassName;
return this.dataSourceDriverClassName;
}
public void setDataSourceDriverClassName(String dataSourceDriverClassName) {
@@ -59,7 +58,7 @@ public class TaskProcessorProperties {
}
public String getDataSourceUserName() {
return dataSourceUserName;
return this.dataSourceUserName;
}
public void setDataSourceUserName(String dataSourceUserName) {
@@ -67,7 +66,7 @@ public class TaskProcessorProperties {
}
public String getDataSourcePassword() {
return dataSourcePassword;
return this.dataSourcePassword;
}
public void setDataSourcePassword(String dataSourcePassword) {
@@ -75,7 +74,7 @@ public class TaskProcessorProperties {
}
public String getUri() {
return uri;
return this.uri;
}
public void setUri(String uri) {
@@ -83,7 +82,7 @@ public class TaskProcessorProperties {
}
public String getApplicationName() {
return applicationName;
return this.applicationName;
}
public void setApplicationName(String applicationName) {

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.
@@ -33,8 +33,7 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.junit4.SpringRunner;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Glenn Renfro
@@ -53,18 +52,21 @@ public class TaskProcessorApplicationTests {
private ObjectMapper mapper = new ObjectMapper();
@Test
public void test() throws InterruptedException, IOException {
channels.input().send(new GenericMessage<Object>(DEFAULT_PAYLOAD));
Map<String, String> properties = new HashMap();
properties.put("payload", DEFAULT_PAYLOAD);
TaskLaunchRequest expectedRequest = new TaskLaunchRequest(
"maven://org.springframework.cloud.task.app:"
+ "timestamp-task:jar:1.0.1.RELEASE", null, properties,
null, null);
Message<String> result = (Message<String>)collector.forChannel(channels.output()).take();
TaskLaunchRequest tlq = mapper.readValue(result.getPayload(),TaskLaunchRequest.class);
assertThat(tlq, is(expectedRequest));
}
@Test
public void test() throws InterruptedException, IOException {
this.channels.input().send(new GenericMessage<Object>(DEFAULT_PAYLOAD));
Map<String, String> properties = new HashMap();
properties.put("payload", DEFAULT_PAYLOAD);
TaskLaunchRequest expectedRequest = new TaskLaunchRequest(
"maven://org.springframework.cloud.task.app:"
+ "timestamp-task:jar:1.0.1.RELEASE", null, properties,
null, null);
Message<String> result = (Message<String>) this.collector
.forChannel(this.channels.output())
.take();
TaskLaunchRequest tlq = this.mapper
.readValue(result.getPayload(), TaskLaunchRequest.class);
assertThat(tlq).isEqualTo(expectedRequest);
}
}

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.spring.cloud</groupId>
@@ -8,13 +10,15 @@
<packaging>jar</packaging>
<name>Task Sink Sample Application</name>
<description>Launches tasks based on contents of TaskLaunchRequest for local deployer</description>
<description>Launches tasks based on contents of TaskLaunchRequest for local
deployer
</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>

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.

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.
@@ -34,9 +34,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
/**
@@ -54,29 +52,32 @@ public class TaskSinkApplicationTests {
@Test
public void testLaunch() throws IOException {
assertNotNull(this.sink.input());
assertThat(this.sink.input()).isNotNull();
TaskLauncher testTaskLauncher =
context.getBean(TaskLauncher.class);
this.context.getBean(TaskLauncher.class);
Map<String, String> properties = new HashMap();
properties.put("server.port", "0");
TaskLaunchRequest request = new TaskLaunchRequest(
"maven://org.springframework.cloud.task.app:"
"maven://org.springframework.cloud.task.app:"
+ "timestamp-task:jar:1.0.1.RELEASE", null, properties,
null, null);
GenericMessage<TaskLaunchRequest> message = new GenericMessage<TaskLaunchRequest>(request);
null, null);
GenericMessage<TaskLaunchRequest> message = new GenericMessage<>(request);
this.sink.input().send(message);
ArgumentCaptor<AppDeploymentRequest> deploymentRequest = ArgumentCaptor.forClass(AppDeploymentRequest.class);
ArgumentCaptor<AppDeploymentRequest> deploymentRequest = ArgumentCaptor
.forClass(AppDeploymentRequest.class);
verify(testTaskLauncher).launch(deploymentRequest.capture());
AppDeploymentRequest actualRequest = deploymentRequest.getValue();
assertTrue(actualRequest.getCommandlineArguments().isEmpty());
assertEquals("0", actualRequest.getDefinition().getProperties().get("server.port"));
assertTrue(actualRequest.getResource().toString()
.contains("maven://org.springframework.cloud.task.app:timestamp-task:jar:1.0.1.RELEASE"));
assertThat(actualRequest.getCommandlineArguments().isEmpty()).isTrue();
assertThat(actualRequest.getDefinition().getProperties()
.get("server.port")).isEqualTo("0");
assertThat(actualRequest.getResource().toString()
.contains("maven://org.springframework.cloud.task.app:timestamp-task:jar:1.0.1.RELEASE"))
.isTrue();
}
}

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.

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -14,11 +16,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath />
<relativePath/>
</parent>
<properties>
<start-class>org.springframework.cloud.task.timestamp.TaskApplication</start-class>
<start-class>org.springframework.cloud.task.timestamp.TaskApplication
</start-class>
<skipInstall>true</skipInstall>
</properties>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-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.
@@ -35,23 +35,22 @@ import org.springframework.context.annotation.Bean;
/**
* Spring Boot Application that has tasks enabled.
*/
@EnableTask
@SpringBootApplication
@EnableConfigurationProperties({ TimestampTaskProperties.class })
@EnableConfigurationProperties({TimestampTaskProperties.class})
public class TaskApplication {
private static final Log logger = LogFactory.getLog(TaskApplication.class);
public static void main(String[] args) {
SpringApplication.run(TaskApplication.class, args);
}
@Bean
public TimestampTask timeStampTask() {
return new TimestampTask();
}
public static void main(String[] args) {
SpringApplication.run(TaskApplication.class, args);
}
/**
* A commandline runner that prints a timestamp.
*/
@@ -62,7 +61,7 @@ public class TaskApplication {
@Override
public void run(String... strings) throws Exception {
DateFormat dateFormat = new SimpleDateFormat(config.getFormat());
DateFormat dateFormat = new SimpleDateFormat(this.config.getFormat());
logger.info(dateFormat.format(new Date()));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 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.
@@ -31,8 +31,8 @@ public class TimestampTaskProperties {
private String format = "yyyy-MM-dd HH:mm:ss.SSS";
public String getFormat() {
Assert.hasText(format, "format must not be empty nor null");
return format;
Assert.hasText(this.format, "format must not be empty nor null");
return this.format;
}
public void setFormat(String format) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 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.
@@ -25,8 +25,7 @@ import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.rule.OutputCapture;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Verifies that the Task Application outputs the correct task log entries.
@@ -44,19 +43,19 @@ public class TaskApplicationTests {
final String CREATE_TASK_MESSAGE = "Creating: TaskExecution{executionId=";
final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId=";
final String EXIT_CODE_MESSAGE = "with the following {exitCode=0";
String[] args = { "--format=yyyy" + TEST_DATE_DOTS };
String[] args = {"--format=yyyy" + TEST_DATE_DOTS};
SpringApplication.run(TaskApplication.class, args);
String output = this.outputCapture.toString();
assertTrue("Unable to find the timestamp: " + output,
output.contains(TEST_DATE_DOTS));
assertTrue("Test results do not show create task message: " + output,
output.contains(CREATE_TASK_MESSAGE));
assertTrue("Test results do not show success message: " + output,
output.contains(UPDATE_TASK_MESSAGE));
assertTrue("Test results have incorrect exit code: " + output,
output.contains(EXIT_CODE_MESSAGE));
assertThat(output.contains(TEST_DATE_DOTS))
.as("Unable to find the timestamp: " + output).isTrue();
assertThat(output.contains(CREATE_TASK_MESSAGE))
.as("Test results do not show create task message: " + output).isTrue();
assertThat(output.contains(UPDATE_TASK_MESSAGE))
.as("Test results do not show success message: " + output).isTrue();
assertThat(output.contains(EXIT_CODE_MESSAGE))
.as("Test results have incorrect exit code: " + output).isTrue();
String taskTitle = "Demo Timestamp Task";
Pattern pattern = Pattern.compile(taskTitle);
@@ -65,6 +64,7 @@ public class TaskApplicationTests {
while (matcher.find()) {
count++;
}
assertEquals("The number of task titles did not match expected: ", 1, count);
assertThat(count).as("The number of task titles did not match expected: ")
.isEqualTo(1);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 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.
@@ -16,14 +16,15 @@
package org.springframework.cloud.task.timestamp;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Glenn Renfro
*/
@@ -36,7 +37,8 @@ public class TimestampTaskPropertiesTests {
testPropertyValues.applyTo(context);
context.register(Conf.class);
context.refresh();
TimestampTaskProperties properties = context.getBean(TimestampTaskProperties.class);
TimestampTaskProperties properties = context
.getBean(TimestampTaskProperties.class);
properties.getFormat();
}
@@ -45,9 +47,10 @@ public class TimestampTaskPropertiesTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Conf.class);
context.refresh();
TimestampTaskProperties properties = context.getBean(TimestampTaskProperties.class);
assertEquals("result does not match default format.", "yyyy-MM-dd HH:mm:ss.SSS",
properties.getFormat());
TimestampTaskProperties properties = context
.getBean(TimestampTaskProperties.class);
assertThat(properties.getFormat()).as("result does not match default format.")
.isEqualTo("yyyy-MM-dd HH:mm:ss.SSS");
}
@Test
@@ -56,10 +59,11 @@ public class TimestampTaskPropertiesTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Conf.class);
context.refresh();
TimestampTaskProperties properties = context.getBean(TimestampTaskProperties.class);
TimestampTaskProperties properties = context
.getBean(TimestampTaskProperties.class);
properties.setFormat(FORMAT);
assertEquals("result does not match established format.", FORMAT,
properties.getFormat());
assertThat(properties.getFormat()).as("result does not match established format.")
.isEqualTo(FORMAT);
}
@Configuration

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.
@@ -13,6 +13,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
logging.level.org.springframework.cloud.task=DEBUG
spring.application.name=Demo Timestamp Task