Skip to content

Commit 4adddc8

Browse files
committed
Polish
1 parent 414cfc3 commit 4adddc8

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

spring-cloud-task-samples/single-step-batch-job/README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= Timestamp Task
1+
= Single Step Batch JOb
22

33
This is a Spring Cloud Task application that autoconfigures a single step Spring Batch job based on the profiles that are active.
44

spring-cloud-task-samples/single-step-batch-job/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
<dependency>
4747
<groupId>org.springframework.boot</groupId>
4848
<artifactId>spring-boot-configuration-processor</artifactId>
49-
<optional>true</optional>
5049
</dependency>
5150
<dependency>
5251
<groupId>org.springframework.boot</groupId>

spring-cloud-task-samples/single-step-batch-job/src/test/java/io/spring/BatchJobApplicationTests.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Map;
2626

2727
import javax.sql.DataSource;
28+
2829
import org.h2.tools.Server;
2930
import org.junit.jupiter.api.AfterEach;
3031
import org.junit.jupiter.api.BeforeEach;
@@ -40,7 +41,6 @@
4041
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
4142
import org.springframework.util.SocketUtils;
4243

43-
4444
import static org.assertj.core.api.Assertions.assertThat;
4545

4646
/**
@@ -71,8 +71,8 @@ public class BatchJobApplicationTests {
7171
private File outputFile;
7272

7373
@BeforeEach
74-
public void setup() {
75-
outputFile = new File("./result.txt");
74+
public void setup() throws Exception {
75+
outputFile = new File("result.txt");
7676
initH2TCPServer();
7777
}
7878

@@ -130,29 +130,26 @@ public void testFileReaderFileWriter() throws Exception {
130130
validateFileResult();
131131
}
132132

133-
public Server initH2TCPServer() {
134-
Server server = null;
135-
try {
136-
if (defaultServer == null) {
137-
server = Server.createTcpServer("-ifNotExists", "-tcp",
138-
"-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort))
139-
.start();
140-
defaultServer = server;
141-
DriverManagerDataSource dataSource = new DriverManagerDataSource();
142-
dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME);
143-
dataSource.setUrl(DATASOURCE_URL);
144-
dataSource.setUsername(DATASOURCE_USER_NAME);
145-
dataSource.setPassword(DATASOURCE_USER_PASSWORD);
146-
ClassPathResource setupResource = new ClassPathResource(
147-
"schema-h2.sql");
148-
ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator(
149-
setupResource);
150-
resourceDatabasePopulator.execute(dataSource);
151-
}
152-
}
153-
catch (SQLException e) {
154-
throw new IllegalStateException(e);
133+
public Server initH2TCPServer() throws SQLException {
134+
Server server;
135+
136+
if (defaultServer == null) {
137+
server = Server.createTcpServer("-ifNotExists", "-tcp",
138+
"-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort))
139+
.start();
140+
defaultServer = server;
141+
DriverManagerDataSource dataSource = new DriverManagerDataSource();
142+
dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME);
143+
dataSource.setUrl(DATASOURCE_URL);
144+
dataSource.setUsername(DATASOURCE_USER_NAME);
145+
dataSource.setPassword(DATASOURCE_USER_PASSWORD);
146+
ClassPathResource setupResource = new ClassPathResource(
147+
"schema-h2.sql");
148+
ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator(
149+
setupResource);
150+
resourceDatabasePopulator.execute(dataSource);
155151
}
152+
156153
return defaultServer;
157154
}
158155

0 commit comments

Comments
 (0)