From 26f3a4cf1054eb3d713200bd8812f17a34c30e94 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Wed, 10 Dec 2025 11:35:03 +0800 Subject: [PATCH] Introduce schema-drop-mongodb.jsonl Signed-off-by: Yanming Zhou --- .../batch/core/schema-drop-mongodb.jsonl | 4 ++++ .../AbstractMongoDBDaoIntegrationTests.java | 21 +++++++------------ .../MongoDBJobExplorerIntegrationTests.java | 11 +++++++--- .../MongoDBJobRepositoryIntegrationTests.java | 11 +++++++--- .../MongoDBJobRestartIntegrationTests.java | 17 ++++++++------- 5 files changed, 37 insertions(+), 27 deletions(-) create mode 100644 spring-batch-core/src/main/resources/org/springframework/batch/core/schema-drop-mongodb.jsonl diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-drop-mongodb.jsonl b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-drop-mongodb.jsonl new file mode 100644 index 0000000000..0a3ea01de1 --- /dev/null +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-drop-mongodb.jsonl @@ -0,0 +1,4 @@ +{drop:'BATCH_JOB_INSTANCE'} +{drop:'BATCH_JOB_EXECUTION'} +{drop:'BATCH_STEP_EXECUTION'} +{drop:'BATCH_SEQUENCES'} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/AbstractMongoDBDaoIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/AbstractMongoDBDaoIntegrationTests.java index 25375257e7..ee1d23a649 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/AbstractMongoDBDaoIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/AbstractMongoDBDaoIntegrationTests.java @@ -49,19 +49,14 @@ abstract class AbstractMongoDBDaoIntegrationTests { @BeforeEach void setUp(@Autowired MongoTemplate mongoTemplate) throws IOException { - mongoTemplate.dropCollection("BATCH_JOB_INSTANCE"); - mongoTemplate.dropCollection("BATCH_JOB_EXECUTION"); - mongoTemplate.dropCollection("BATCH_STEP_EXECUTION"); - mongoTemplate.createCollection("BATCH_JOB_INSTANCE"); - mongoTemplate.createCollection("BATCH_JOB_EXECUTION"); - mongoTemplate.createCollection("BATCH_STEP_EXECUTION"); - // sequences - mongoTemplate.dropCollection("BATCH_SEQUENCES"); - Resource resource = new FileSystemResource( - "src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl"); - try (Stream lines = Files.lines(resource.getFilePath())) { - lines.forEach(mongoTemplate::executeCommand); - } + Files + .lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-drop-mongodb.jsonl") + .getFilePath()) + .forEach(mongoTemplate::executeCommand); + Files + .lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl") + .getFilePath()) + .forEach(mongoTemplate::executeCommand); } protected void assertTemporalEquals(LocalDateTime lhs, LocalDateTime rhs) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobExplorerIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobExplorerIntegrationTests.java index eef1c328f1..177c6905b6 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobExplorerIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobExplorerIntegrationTests.java @@ -54,9 +54,14 @@ public class MongoDBJobExplorerIntegrationTests { @BeforeAll static void setUp(@Autowired MongoTemplate mongoTemplate) throws IOException { - Resource resource = new FileSystemResource( - "src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl"); - Files.lines(resource.getFilePath()).forEach(line -> mongoTemplate.executeCommand(line)); + Files + .lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-drop-mongodb.jsonl") + .getFilePath()) + .forEach(mongoTemplate::executeCommand); + Files + .lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl") + .getFilePath()) + .forEach(mongoTemplate::executeCommand); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRepositoryIntegrationTests.java index 5d3fe053da..895cc916c2 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRepositoryIntegrationTests.java @@ -53,9 +53,14 @@ public class MongoDBJobRepositoryIntegrationTests { @BeforeEach public void setUp() throws IOException { - Resource resource = new FileSystemResource( - "src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl"); - Files.lines(resource.getFilePath()).forEach(line -> mongoTemplate.executeCommand(line)); + Files + .lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-drop-mongodb.jsonl") + .getFilePath()) + .forEach(mongoTemplate::executeCommand); + Files + .lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl") + .getFilePath()) + .forEach(mongoTemplate::executeCommand); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRestartIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRestartIntegrationTests.java index b7351951c7..776c888c87 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRestartIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRestartIntegrationTests.java @@ -52,6 +52,7 @@ /** * @author Mahmoud Ben Hassine + * @author Yanming Zhou */ @Testcontainers(disabledWithoutDocker = true) @SpringJUnitConfig(MongoDBIntegrationTestConfiguration.class) @@ -62,14 +63,14 @@ public class MongoDBJobRestartIntegrationTests { @BeforeEach public void setUp() throws IOException { - // TODO put drop statements in schema-drop-mongodb.jsonl - mongoTemplate.dropCollection("BATCH_JOB_INSTANCE"); - mongoTemplate.dropCollection("BATCH_JOB_EXECUTION"); - mongoTemplate.dropCollection("BATCH_STEP_EXECUTION"); - mongoTemplate.dropCollection("BATCH_SEQUENCES"); - Resource resource = new FileSystemResource( - "src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl"); - Files.lines(resource.getFilePath()).forEach(line -> mongoTemplate.executeCommand(line)); + Files + .lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-drop-mongodb.jsonl") + .getFilePath()) + .forEach(mongoTemplate::executeCommand); + Files + .lines(new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl") + .getFilePath()) + .forEach(mongoTemplate::executeCommand); } @Test