Skip to content

Commit dc8322c

Browse files
wynnteoWynn Teo
andauthored
Bael 9303 (#18650)
* BAEL-9303 * Fix integration test --------- Co-authored-by: Wynn Teo <[email protected]>
1 parent 4650115 commit dc8322c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

spring-batch-2/src/test/java/com/baeldung/multiprocessorandwriter/BatchJobIntegrationTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import java.nio.file.Path;
1111
import java.nio.file.Paths;
1212
import java.sql.Connection;
13+
import java.sql.DatabaseMetaData;
14+
import java.sql.ResultSet;
1315
import java.sql.SQLException;
1416
import java.util.List;
1517

@@ -83,7 +85,14 @@ public JobLauncherTestUtils jobLauncherTestUtils() {
8385
@BeforeEach
8486
public void setup() throws IOException {
8587
try (Connection connection = dataSource.getConnection()) {
86-
ScriptUtils.executeSqlScript(connection, new ClassPathResource("org/springframework/batch/core/schema-h2.sql"));
88+
DatabaseMetaData metaData = connection.getMetaData();
89+
try (ResultSet rs = metaData.getTables(null, null, "BATCH_JOB_INSTANCE", null)) {
90+
if (!rs.next()) {
91+
ScriptUtils.executeSqlScript(connection, new ClassPathResource("org/springframework/batch/core/schema-h2.sql"));
92+
} else {
93+
System.out.println("Spring Batch tables already exist. Skipping schema creation.");
94+
}
95+
}
8796
} catch (SQLException e) {
8897
throw new RuntimeException(e);
8998
}

0 commit comments

Comments
 (0)