Skip to content

Commit dcfd42e

Browse files
authored
Introduce schema-drop-mongodb.jsonl (#5155)
Signed-off-by: Yanming Zhou <[email protected]>
1 parent 088487b commit dcfd42e

File tree

5 files changed

+37
-27
lines changed

5 files changed

+37
-27
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{drop:'BATCH_JOB_INSTANCE'}
2+
{drop:'BATCH_JOB_EXECUTION'}
3+
{drop:'BATCH_STEP_EXECUTION'}
4+
{drop:'BATCH_SEQUENCES'}

spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/AbstractMongoDBDaoIntegrationTests.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,14 @@ abstract class AbstractMongoDBDaoIntegrationTests {
4949

5050
@BeforeEach
5151
void setUp(@Autowired MongoTemplate mongoTemplate) throws IOException {
52-
mongoTemplate.dropCollection("BATCH_JOB_INSTANCE");
53-
mongoTemplate.dropCollection("BATCH_JOB_EXECUTION");
54-
mongoTemplate.dropCollection("BATCH_STEP_EXECUTION");
55-
mongoTemplate.createCollection("BATCH_JOB_INSTANCE");
56-
mongoTemplate.createCollection("BATCH_JOB_EXECUTION");
57-
mongoTemplate.createCollection("BATCH_STEP_EXECUTION");
58-
// sequences
59-
mongoTemplate.dropCollection("BATCH_SEQUENCES");
60-
Resource resource = new FileSystemResource(
61-
"src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl");
62-
try (Stream<String> lines = Files.lines(resource.getFilePath())) {
63-
lines.forEach(mongoTemplate::executeCommand);
64-
}
52+
Files
53+
.lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-drop-mongodb.jsonl")
54+
.getFilePath())
55+
.forEach(mongoTemplate::executeCommand);
56+
Files
57+
.lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl")
58+
.getFilePath())
59+
.forEach(mongoTemplate::executeCommand);
6560
}
6661

6762
protected void assertTemporalEquals(LocalDateTime lhs, LocalDateTime rhs) {

spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobExplorerIntegrationTests.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,14 @@ public class MongoDBJobExplorerIntegrationTests {
5454

5555
@BeforeAll
5656
static void setUp(@Autowired MongoTemplate mongoTemplate) throws IOException {
57-
Resource resource = new FileSystemResource(
58-
"src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl");
59-
Files.lines(resource.getFilePath()).forEach(line -> mongoTemplate.executeCommand(line));
57+
Files
58+
.lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-drop-mongodb.jsonl")
59+
.getFilePath())
60+
.forEach(mongoTemplate::executeCommand);
61+
Files
62+
.lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl")
63+
.getFilePath())
64+
.forEach(mongoTemplate::executeCommand);
6065
}
6166

6267
@Test

spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRepositoryIntegrationTests.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ public class MongoDBJobRepositoryIntegrationTests {
5353

5454
@BeforeEach
5555
public void setUp() throws IOException {
56-
Resource resource = new FileSystemResource(
57-
"src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl");
58-
Files.lines(resource.getFilePath()).forEach(line -> mongoTemplate.executeCommand(line));
56+
Files
57+
.lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-drop-mongodb.jsonl")
58+
.getFilePath())
59+
.forEach(mongoTemplate::executeCommand);
60+
Files
61+
.lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl")
62+
.getFilePath())
63+
.forEach(mongoTemplate::executeCommand);
5964
}
6065

6166
@Test

spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRestartIntegrationTests.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
/**
5454
* @author Mahmoud Ben Hassine
55+
* @author Yanming Zhou
5556
*/
5657
@Testcontainers(disabledWithoutDocker = true)
5758
@SpringJUnitConfig(MongoDBIntegrationTestConfiguration.class)
@@ -62,14 +63,14 @@ public class MongoDBJobRestartIntegrationTests {
6263

6364
@BeforeEach
6465
public void setUp() throws IOException {
65-
// TODO put drop statements in schema-drop-mongodb.jsonl
66-
mongoTemplate.dropCollection("BATCH_JOB_INSTANCE");
67-
mongoTemplate.dropCollection("BATCH_JOB_EXECUTION");
68-
mongoTemplate.dropCollection("BATCH_STEP_EXECUTION");
69-
mongoTemplate.dropCollection("BATCH_SEQUENCES");
70-
Resource resource = new FileSystemResource(
71-
"src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl");
72-
Files.lines(resource.getFilePath()).forEach(line -> mongoTemplate.executeCommand(line));
66+
Files
67+
.lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-drop-mongodb.jsonl")
68+
.getFilePath())
69+
.forEach(mongoTemplate::executeCommand);
70+
Files
71+
.lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl")
72+
.getFilePath())
73+
.forEach(mongoTemplate::executeCommand);
7374
}
7475

7576
@Test

0 commit comments

Comments
 (0)