Set Spring Cloud Task Date Strategy to match Batch

resolves #868
Signed-off-by: Glenn Renfro <grenfro@vmware.com>

Updated the timestamps for H2,oracle, db2, hsqldb to be 9 digits for improved accuracy
This commit is contained in:
Glenn Renfro
2022-10-18 08:17:38 -04:00
parent cf8056880b
commit a0fda4bf6e
30 changed files with 243 additions and 247 deletions

View File

@@ -19,9 +19,9 @@ package org.springframework.cloud.task.executionid;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@@ -189,10 +189,10 @@ public class TaskStartTests {
@Test
public void testWithGeneratedTaskExecutionWithExistingDate() throws Exception {
final String TASK_EXECUTION_NAME = "PRE-EXECUTION-TEST-NAME";
Date startDate = new Date();
LocalDateTime startDate = LocalDateTime.now();
Thread.sleep(500);
TaskExecution taskExecution = new TaskExecution(1, 0, TASK_EXECUTION_NAME, startDate, new Date(), "foo",
Collections.emptyList(), "foo", "bar", null);
TaskExecution taskExecution = new TaskExecution(1, 0, TASK_EXECUTION_NAME, startDate, LocalDateTime.now(),
"foo", Collections.emptyList(), "foo", "bar", null);
this.taskRepository.createTaskExecution(taskExecution);
assertThat(this.taskExplorer.getTaskExecutionCount()).as("Only one row is expected").isEqualTo(1);
@@ -203,7 +203,7 @@ public class TaskStartTests {
assertThat(taskExecutions.getTotalElements()).as("Only one row is expected").isEqualTo(1);
assertThat(taskExecutions.iterator().next().getExitCode().intValue()).as("return code should be 0")
.isEqualTo(0);
assertThat(this.taskExplorer.getTaskExecution(1).getStartTime().getTime()).isEqualTo(startDate.getTime());
assertThat(this.taskExplorer.getTaskExecution(1).getStartTime().isEqual(startDate)).isTrue();
}
@@ -218,7 +218,7 @@ public class TaskStartTests {
public void testCompletedTaskExecution() throws Exception {
this.taskRepository.createTaskExecution();
assertThat(this.taskExplorer.getTaskExecutionCount()).as("Only one row is expected").isEqualTo(1);
this.taskRepository.completeTaskExecution(1, 0, new Date(), "");
this.taskRepository.completeTaskExecution(1, 0, LocalDateTime.now(), "");
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> {
this.applicationContext = getTaskApplication(1).run(new String[0]);
});
@@ -248,7 +248,8 @@ public class TaskStartTests {
public void testDuplicateTaskExecutionWithSingleInstanceDisabled() throws Exception {
this.taskRepository.createTaskExecution();
TaskExecution execution = this.taskRepository.createTaskExecution();
this.taskRepository.startTaskExecution(execution.getExecutionId(), "bar", new Date(), new ArrayList<>(), "");
this.taskRepository.startTaskExecution(execution.getExecutionId(), "bar", LocalDateTime.now(),
new ArrayList<>(), "");
String[] params = { "--spring.cloud.task.name=bar" };
enableLock("bar");
this.applicationContext = getTaskApplication(1).run(params);
@@ -293,7 +294,7 @@ public class TaskStartTests {
taskLockParams.put("LOCK_KEY", UUID.nameUUIDFromBytes(lockKey.getBytes()).toString());
taskLockParams.put("REGION", "DEFAULT");
taskLockParams.put("CLIENT_ID", "aClientID");
taskLockParams.put("CREATED_DATE", new Date());
taskLockParams.put("CREATED_DATE", LocalDateTime.now());
taskLockInsert.execute(taskLockParams);
}

View File

@@ -21,8 +21,10 @@ import java.util.List;
import java.util.UUID;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.WebApplicationType;
@@ -47,6 +49,11 @@ public class TaskEventTests {
private ConfigurableApplicationContext applicationContext;
@BeforeEach
public void setup() {
this.objectMapper.registerModule(new JavaTimeModule());
}
@AfterEach
public void tearDown() {
if (this.applicationContext != null && this.applicationContext.isActive()) {