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,7 +19,6 @@ package org.springframework.cloud.task.batch.handler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -156,8 +155,6 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
private void monitorJobExecutions() { private void monitorJobExecutions() {
RepeatTemplate template = new RepeatTemplate(); RepeatTemplate template = new RepeatTemplate();
Date startDate = new Date();
template.iterate(context -> { template.iterate(context -> {
List<JobExecution> failedJobExecutions = new ArrayList<>(); List<JobExecution> failedJobExecutions = new ArrayList<>();

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.task.batch.partition; package org.springframework.cloud.task.batch.partition;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@@ -91,7 +92,7 @@ public class DeployerPartitionHandlerTests {
public void setUp() { public void setUp() {
MockitoAnnotations.openMocks(this); MockitoAnnotations.openMocks(this);
this.environment = new MockEnvironment(); this.environment = new MockEnvironment();
TaskExecution taskExecution = new TaskExecution(2, 0, "name", new Date(), new Date(), "", TaskExecution taskExecution = new TaskExecution(2, 0, "name", LocalDateTime.now(), LocalDateTime.now(), "",
Collections.emptyList(), null, null, null); Collections.emptyList(), null, null, null);
Mockito.lenient().when(taskRepository.createTaskExecution()).thenReturn(taskExecution); Mockito.lenient().when(taskRepository.createTaskExecution()).thenReturn(taskExecution);
} }

View File

@@ -19,11 +19,11 @@ package org.springframework.cloud.task.listener;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.List; import java.util.List;
import io.micrometer.observation.ObservationConvention; import io.micrometer.observation.ObservationConvention;
@@ -191,7 +191,7 @@ public class TaskLifecycleListener
private void doTaskEnd() { private void doTaskEnd() {
if ((this.listenerFailed || this.started) && !this.finished) { if ((this.listenerFailed || this.started) && !this.finished) {
this.taskExecution.setEndTime(new Date()); this.taskExecution.setEndTime(LocalDateTime.now());
if (this.applicationFailedException != null) { if (this.applicationFailedException != null) {
this.taskExecution.setErrorMessage(stackTraceToString(this.applicationFailedException)); this.taskExecution.setErrorMessage(stackTraceToString(this.applicationFailedException));
@@ -277,7 +277,8 @@ public class TaskLifecycleListener
Assert.isNull(taskExecution.getEndTime(), Assert.isNull(taskExecution.getEndTime(),
String.format("Invalid TaskExecution, ID %s task is already complete", String.format("Invalid TaskExecution, ID %s task is already complete",
this.taskProperties.getExecutionid())); this.taskProperties.getExecutionid()));
Date startDate = (taskExecution.getStartTime() == null) ? new Date() : taskExecution.getStartTime(); LocalDateTime startDate = (taskExecution.getStartTime() == null) ? LocalDateTime.now()
: taskExecution.getStartTime();
this.taskExecution = this.taskRepository.startTaskExecution(this.taskProperties.getExecutionid(), this.taskExecution = this.taskRepository.startTaskExecution(this.taskProperties.getExecutionid(),
this.taskNameResolver.getTaskName(), startDate, args, this.taskNameResolver.getTaskName(), startDate, args,
this.taskProperties.getExternalExecutionId(), this.taskProperties.getParentExecutionId()); this.taskProperties.getExternalExecutionId(), this.taskProperties.getParentExecutionId());
@@ -285,7 +286,7 @@ public class TaskLifecycleListener
else { else {
TaskExecution taskExecution = new TaskExecution(); TaskExecution taskExecution = new TaskExecution();
taskExecution.setTaskName(this.taskNameResolver.getTaskName()); taskExecution.setTaskName(this.taskNameResolver.getTaskName());
taskExecution.setStartTime(new Date()); taskExecution.setStartTime(LocalDateTime.now());
taskExecution.setArguments(args); taskExecution.setArguments(args);
taskExecution.setExternalExecutionId(this.taskProperties.getExternalExecutionId()); taskExecution.setExternalExecutionId(this.taskProperties.getExternalExecutionId());
taskExecution.setParentExecutionId(this.taskProperties.getParentExecutionId()); taskExecution.setParentExecutionId(this.taskProperties.getParentExecutionId());
@@ -384,8 +385,8 @@ public class TaskLifecycleListener
} }
private TaskExecution getTaskExecutionCopy(TaskExecution taskExecution) { private TaskExecution getTaskExecutionCopy(TaskExecution taskExecution) {
Date startTime = new Date(taskExecution.getStartTime().getTime()); LocalDateTime startTime = taskExecution.getStartTime();
Date endTime = (taskExecution.getEndTime() == null) ? null : new Date(taskExecution.getEndTime().getTime()); LocalDateTime endTime = taskExecution.getEndTime();
return new TaskExecution(taskExecution.getExecutionId(), taskExecution.getExitCode(), return new TaskExecution(taskExecution.getExecutionId(), taskExecution.getExitCode(),
taskExecution.getTaskName(), startTime, endTime, taskExecution.getExitMessage(), taskExecution.getTaskName(), startTime, endTime, taskExecution.getExitMessage(),

View File

@@ -16,8 +16,8 @@
package org.springframework.cloud.task.repository; package org.springframework.cloud.task.repository;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -55,12 +55,12 @@ public class TaskExecution {
/** /**
* Time of when the task was started. * Time of when the task was started.
*/ */
private Date startTime; private LocalDateTime startTime;
/** /**
* Timestamp of when the task was completed/terminated. * Timestamp of when the task was completed/terminated.
*/ */
private Date endTime; private LocalDateTime endTime;
/** /**
* Message returned from the task or stacktrace. * Message returned from the task or stacktrace.
@@ -90,9 +90,9 @@ public class TaskExecution {
this.arguments = new ArrayList<>(); this.arguments = new ArrayList<>();
} }
public TaskExecution(long executionId, Integer exitCode, String taskName, Date startTime, Date endTime, public TaskExecution(long executionId, Integer exitCode, String taskName, LocalDateTime startTime,
String exitMessage, List<String> arguments, String errorMessage, String externalExecutionId, LocalDateTime endTime, String exitMessage, List<String> arguments, String errorMessage,
Long parentExecutionId) { String externalExecutionId, Long parentExecutionId) {
Assert.notNull(arguments, "arguments must not be null"); Assert.notNull(arguments, "arguments must not be null");
this.executionId = executionId; this.executionId = executionId;
@@ -100,15 +100,16 @@ public class TaskExecution {
this.taskName = taskName; this.taskName = taskName;
this.exitMessage = exitMessage; this.exitMessage = exitMessage;
this.arguments = new ArrayList<>(arguments); this.arguments = new ArrayList<>(arguments);
this.startTime = (startTime != null) ? (Date) startTime.clone() : null; this.startTime = startTime;
this.endTime = (endTime != null) ? (Date) endTime.clone() : null; this.endTime = endTime;
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
this.externalExecutionId = externalExecutionId; this.externalExecutionId = externalExecutionId;
this.parentExecutionId = parentExecutionId; this.parentExecutionId = parentExecutionId;
} }
public TaskExecution(long executionId, Integer exitCode, String taskName, Date startTime, Date endTime, public TaskExecution(long executionId, Integer exitCode, String taskName, LocalDateTime startTime,
String exitMessage, List<String> arguments, String errorMessage, String externalExecutionId) { LocalDateTime endTime, String exitMessage, List<String> arguments, String errorMessage,
String externalExecutionId) {
this(executionId, exitCode, taskName, startTime, endTime, exitMessage, arguments, errorMessage, this(executionId, exitCode, taskName, startTime, endTime, exitMessage, arguments, errorMessage,
externalExecutionId, null); externalExecutionId, null);
@@ -134,20 +135,20 @@ public class TaskExecution {
this.taskName = taskName; this.taskName = taskName;
} }
public Date getStartTime() { public LocalDateTime getStartTime() {
return (this.startTime != null) ? (Date) this.startTime.clone() : null; return this.startTime;
} }
public void setStartTime(Date startTime) { public void setStartTime(LocalDateTime startTime) {
this.startTime = (startTime != null) ? (Date) startTime.clone() : null; this.startTime = startTime;
} }
public Date getEndTime() { public LocalDateTime getEndTime() {
return (this.endTime != null) ? (Date) this.endTime.clone() : null; return this.endTime;
} }
public void setEndTime(Date endTime) { public void setEndTime(LocalDateTime endTime) {
this.endTime = (endTime != null) ? (Date) endTime.clone() : null; this.endTime = endTime;
} }
public String getExitMessage() { public String getExitMessage() {

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.task.repository; package org.springframework.cloud.task.repository;
import java.util.Date; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -40,7 +40,7 @@ public interface TaskRepository {
* @return the updated {@link TaskExecution} * @return the updated {@link TaskExecution}
*/ */
@Transactional("${spring.cloud.task.transaction-manager:springCloudTaskTransactionManager}") @Transactional("${spring.cloud.task.transaction-manager:springCloudTaskTransactionManager}")
TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage); TaskExecution completeTaskExecution(long executionId, Integer exitCode, LocalDateTime endTime, String exitMessage);
/** /**
* Notifies the repository that a taskExecution has completed. * Notifies the repository that a taskExecution has completed.
@@ -53,7 +53,7 @@ public interface TaskRepository {
* @since 1.1.0 * @since 1.1.0
*/ */
@Transactional("${spring.cloud.task.transaction-manager:springCloudTaskTransactionManager}") @Transactional("${spring.cloud.task.transaction-manager:springCloudTaskTransactionManager}")
TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage, TaskExecution completeTaskExecution(long executionId, Integer exitCode, LocalDateTime endTime, String exitMessage,
String errorMessage); String errorMessage);
/** /**
@@ -99,7 +99,7 @@ public interface TaskRepository {
* @return TaskExecution created based on the parameters. * @return TaskExecution created based on the parameters.
*/ */
@Transactional("${spring.cloud.task.transaction-manager:springCloudTaskTransactionManager}") @Transactional("${spring.cloud.task.transaction-manager:springCloudTaskTransactionManager}")
TaskExecution startTaskExecution(long executionid, String taskName, Date startTime, List<String> arguments, TaskExecution startTaskExecution(long executionid, String taskName, LocalDateTime startTime, List<String> arguments,
String externalExecutionId); String externalExecutionId);
/** /**
@@ -122,7 +122,7 @@ public interface TaskRepository {
* a TaskExecution. * a TaskExecution.
*/ */
@Transactional("${spring.cloud.task.transaction-manager:springCloudTaskTransactionManager}") @Transactional("${spring.cloud.task.transaction-manager:springCloudTaskTransactionManager}")
TaskExecution startTaskExecution(long executionid, String taskName, Date startTime, List<String> arguments, TaskExecution startTaskExecution(long executionid, String taskName, LocalDateTime startTime, List<String> arguments,
String externalExecutionId, Long parentExecutionId); String externalExecutionId, Long parentExecutionId);
} }

View File

@@ -18,10 +18,11 @@ package org.springframework.cloud.task.repository.dao;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types; import java.sql.Types;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@@ -199,13 +200,13 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
} }
@Override @Override
public TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments, public TaskExecution createTaskExecution(String taskName, LocalDateTime startTime, List<String> arguments,
String externalExecutionId) { String externalExecutionId) {
return createTaskExecution(taskName, startTime, arguments, externalExecutionId, null); return createTaskExecution(taskName, startTime, arguments, externalExecutionId, null);
} }
@Override @Override
public TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments, public TaskExecution createTaskExecution(String taskName, LocalDateTime startTime, List<String> arguments,
String externalExecutionId, Long parentExecutionId) { String externalExecutionId, Long parentExecutionId) {
long nextExecutionId = getNextExecutionId(); long nextExecutionId = getNextExecutionId();
@@ -214,8 +215,9 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
final MapSqlParameterSource queryParameters = new MapSqlParameterSource() final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
.addValue("taskExecutionId", nextExecutionId, Types.BIGINT).addValue("exitCode", null, Types.INTEGER) .addValue("taskExecutionId", nextExecutionId, Types.BIGINT).addValue("exitCode", null, Types.INTEGER)
.addValue("startTime", startTime, Types.TIMESTAMP).addValue("taskName", taskName, Types.VARCHAR) .addValue("startTime", startTime == null ? null : Timestamp.valueOf(startTime), Types.TIMESTAMP)
.addValue("lastUpdated", new Date(), Types.TIMESTAMP) .addValue("taskName", taskName, Types.VARCHAR)
.addValue("lastUpdated", Timestamp.valueOf(LocalDateTime.now()), Types.TIMESTAMP)
.addValue("externalExecutionId", externalExecutionId, Types.VARCHAR) .addValue("externalExecutionId", externalExecutionId, Types.VARCHAR)
.addValue("parentExecutionId", parentExecutionId, Types.BIGINT); .addValue("parentExecutionId", parentExecutionId, Types.BIGINT);
@@ -225,20 +227,21 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
} }
@Override @Override
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments, public TaskExecution startTaskExecution(long executionId, String taskName, LocalDateTime startTime,
String externalExecutionId) { List<String> arguments, String externalExecutionId) {
return startTaskExecution(executionId, taskName, startTime, arguments, externalExecutionId, null); return startTaskExecution(executionId, taskName, startTime, arguments, externalExecutionId, null);
} }
@Override @Override
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments, public TaskExecution startTaskExecution(long executionId, String taskName, LocalDateTime startTime,
String externalExecutionId, Long parentExecutionId) { List<String> arguments, String externalExecutionId, Long parentExecutionId) {
TaskExecution taskExecution = new TaskExecution(executionId, null, taskName, startTime, null, null, arguments, TaskExecution taskExecution = new TaskExecution(executionId, null, taskName, startTime, null, null, arguments,
null, externalExecutionId, parentExecutionId); null, externalExecutionId, parentExecutionId);
final MapSqlParameterSource queryParameters = new MapSqlParameterSource() final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
.addValue("startTime", startTime, Types.TIMESTAMP).addValue("exitCode", null, Types.INTEGER) .addValue("startTime", startTime == null ? null : Timestamp.valueOf(startTime), Types.TIMESTAMP)
.addValue("taskName", taskName, Types.VARCHAR).addValue("lastUpdated", new Date(), Types.TIMESTAMP) .addValue("exitCode", null, Types.INTEGER).addValue("taskName", taskName, Types.VARCHAR)
.addValue("lastUpdated", Timestamp.valueOf(LocalDateTime.now()), Types.TIMESTAMP)
.addValue("parentExecutionId", parentExecutionId, Types.BIGINT) .addValue("parentExecutionId", parentExecutionId, Types.BIGINT)
.addValue("taskExecutionId", executionId, Types.BIGINT); .addValue("taskExecutionId", executionId, Types.BIGINT);
@@ -258,7 +261,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
} }
@Override @Override
public void completeTaskExecution(long taskExecutionId, Integer exitCode, Date endTime, String exitMessage, public void completeTaskExecution(long taskExecutionId, Integer exitCode, LocalDateTime endTime, String exitMessage,
String errorMessage) { String errorMessage) {
final MapSqlParameterSource queryParameters = new MapSqlParameterSource().addValue("taskExecutionId", final MapSqlParameterSource queryParameters = new MapSqlParameterSource().addValue("taskExecutionId",
taskExecutionId, Types.BIGINT); taskExecutionId, Types.BIGINT);
@@ -271,17 +274,18 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
} }
final MapSqlParameterSource parameters = new MapSqlParameterSource() final MapSqlParameterSource parameters = new MapSqlParameterSource()
.addValue("endTime", endTime, Types.TIMESTAMP).addValue("exitCode", exitCode, Types.INTEGER) .addValue("endTime", endTime == null ? null : Timestamp.valueOf(endTime), Types.TIMESTAMP)
.addValue("exitMessage", exitMessage, Types.VARCHAR) .addValue("exitCode", exitCode, Types.INTEGER).addValue("exitMessage", exitMessage, Types.VARCHAR)
.addValue("errorMessage", errorMessage, Types.VARCHAR) .addValue("errorMessage", errorMessage, Types.VARCHAR)
.addValue("lastUpdated", new Date(), Types.TIMESTAMP) .addValue("lastUpdated", Timestamp.valueOf(LocalDateTime.now()), Types.TIMESTAMP)
.addValue("taskExecutionId", taskExecutionId, Types.BIGINT); .addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
this.jdbcTemplate.update(getQuery(UPDATE_TASK_EXECUTION), parameters); this.jdbcTemplate.update(getQuery(UPDATE_TASK_EXECUTION), parameters);
} }
@Override @Override
public void completeTaskExecution(long taskExecutionId, Integer exitCode, Date endTime, String exitMessage) { public void completeTaskExecution(long taskExecutionId, Integer exitCode, LocalDateTime endTime,
String exitMessage) {
completeTaskExecution(taskExecutionId, exitCode, endTime, exitMessage, null); completeTaskExecution(taskExecutionId, exitCode, endTime, exitMessage, null);
} }
@@ -582,9 +586,9 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
parentExecutionId = null; parentExecutionId = null;
} }
return new TaskExecution(id, getNullableExitCode(rs), rs.getString("TASK_NAME"), return new TaskExecution(id, getNullableExitCode(rs), rs.getString("TASK_NAME"),
rs.getTimestamp("START_TIME"), rs.getTimestamp("END_TIME"), rs.getString("EXIT_MESSAGE"), rs.getObject("START_TIME", LocalDateTime.class), rs.getObject("END_TIME", LocalDateTime.class),
getTaskArguments(id), rs.getString("ERROR_MESSAGE"), rs.getString("EXTERNAL_EXECUTION_ID"), rs.getString("EXIT_MESSAGE"), getTaskArguments(id), rs.getString("ERROR_MESSAGE"),
parentExecutionId); rs.getString("EXTERNAL_EXECUTION_ID"), parentExecutionId);
} }
private Integer getNullableExitCode(ResultSet rs) throws SQLException { private Integer getNullableExitCode(ResultSet rs) throws SQLException {

View File

@@ -17,10 +17,10 @@
package org.springframework.cloud.task.repository.dao; package org.springframework.cloud.task.repository.dao;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -58,13 +58,13 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
} }
@Override @Override
public TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments, public TaskExecution createTaskExecution(String taskName, LocalDateTime startTime, List<String> arguments,
String externalExecutionId) { String externalExecutionId) {
return createTaskExecution(taskName, startTime, arguments, externalExecutionId, null); return createTaskExecution(taskName, startTime, arguments, externalExecutionId, null);
} }
@Override @Override
public TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments, public TaskExecution createTaskExecution(String taskName, LocalDateTime startTime, List<String> arguments,
String externalExecutionId, Long parentExecutionId) { String externalExecutionId, Long parentExecutionId) {
long taskExecutionId = getNextExecutionId(); long taskExecutionId = getNextExecutionId();
TaskExecution taskExecution = new TaskExecution(taskExecutionId, null, taskName, startTime, null, null, TaskExecution taskExecution = new TaskExecution(taskExecutionId, null, taskName, startTime, null, null,
@@ -74,14 +74,14 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
} }
@Override @Override
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments, public TaskExecution startTaskExecution(long executionId, String taskName, LocalDateTime startTime,
String externalExecutionid) { List<String> arguments, String externalExecutionid) {
return startTaskExecution(executionId, taskName, startTime, arguments, externalExecutionid, null); return startTaskExecution(executionId, taskName, startTime, arguments, externalExecutionid, null);
} }
@Override @Override
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments, public TaskExecution startTaskExecution(long executionId, String taskName, LocalDateTime startTime,
String externalExecutionid, Long parentExecutionId) { List<String> arguments, String externalExecutionid, Long parentExecutionId) {
TaskExecution taskExecution = this.taskExecutions.get(executionId); TaskExecution taskExecution = this.taskExecutions.get(executionId);
taskExecution.setTaskName(taskName); taskExecution.setTaskName(taskName);
taskExecution.setStartTime(startTime); taskExecution.setStartTime(startTime);
@@ -94,7 +94,7 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
} }
@Override @Override
public void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage, public void completeTaskExecution(long executionId, Integer exitCode, LocalDateTime endTime, String exitMessage,
String errorMessage) { String errorMessage) {
if (!this.taskExecutions.containsKey(executionId)) { if (!this.taskExecutions.containsKey(executionId)) {
throw new IllegalStateException("Invalid TaskExecution, ID " + executionId + " not found."); throw new IllegalStateException("Invalid TaskExecution, ID " + executionId + " not found.");
@@ -108,7 +108,7 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
} }
@Override @Override
public void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage) { public void completeTaskExecution(long executionId, Integer exitCode, LocalDateTime endTime, String exitMessage) {
completeTaskExecution(executionId, exitCode, endTime, exitMessage, null); completeTaskExecution(executionId, exitCode, endTime, exitMessage, null);
} }
@@ -287,7 +287,7 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
final TaskExecution tempTaskExecution = tempTaskExecutions final TaskExecution tempTaskExecution = tempTaskExecutions
.get(taskExecutionMapEntry.getValue().getTaskName()); .get(taskExecutionMapEntry.getValue().getTaskName());
if (tempTaskExecution == null if (tempTaskExecution == null
|| tempTaskExecution.getStartTime().before(taskExecutionMapEntry.getValue().getStartTime()) || tempTaskExecution.getStartTime().isBefore(taskExecutionMapEntry.getValue().getStartTime())
|| (tempTaskExecution.getStartTime().equals(taskExecutionMapEntry.getValue().getStartTime()) || (tempTaskExecution.getStartTime().equals(taskExecutionMapEntry.getValue().getStartTime())
&& tempTaskExecution.getExecutionId() < taskExecutionMapEntry.getValue() && tempTaskExecution.getExecutionId() < taskExecutionMapEntry.getValue()
.getExecutionId())) { .getExecutionId())) {

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.task.repository.dao; package org.springframework.cloud.task.repository.dao;
import java.util.Date; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -42,7 +42,7 @@ public interface TaskExecutionDao {
* @param externalExecutionId id assigned to the task by the platform * @param externalExecutionId id assigned to the task by the platform
* @return A fully qualified {@link TaskExecution} instance. * @return A fully qualified {@link TaskExecution} instance.
*/ */
TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments, TaskExecution createTaskExecution(String taskName, LocalDateTime startTime, List<String> arguments,
String externalExecutionId); String externalExecutionId);
/** /**
@@ -55,7 +55,7 @@ public interface TaskExecutionDao {
* @return A fully qualified {@link TaskExecution} instance. * @return A fully qualified {@link TaskExecution} instance.
* @since 1.2.0 * @since 1.2.0
*/ */
TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments, TaskExecution createTaskExecution(String taskName, LocalDateTime startTime, List<String> arguments,
String externalExecutionId, Long parentExecutionId); String externalExecutionId, Long parentExecutionId);
/** /**
@@ -69,7 +69,7 @@ public interface TaskExecutionDao {
* start. * start.
* @since 1.1.0 * @since 1.1.0
*/ */
TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments, TaskExecution startTaskExecution(long executionId, String taskName, LocalDateTime startTime, List<String> arguments,
String externalExecutionId); String externalExecutionId);
/** /**
@@ -84,7 +84,7 @@ public interface TaskExecutionDao {
* start. * start.
* @since 1.2.0 * @since 1.2.0
*/ */
TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments, TaskExecution startTaskExecution(long executionId, String taskName, LocalDateTime startTime, List<String> arguments,
String externalExecutionId, Long parentExecutionId); String externalExecutionId, Long parentExecutionId);
/** /**
@@ -96,7 +96,7 @@ public interface TaskExecutionDao {
* @param errorMessage error information available upon failure of a task. * @param errorMessage error information available upon failure of a task.
* @since 1.1.0 * @since 1.1.0
*/ */
void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage, void completeTaskExecution(long executionId, Integer exitCode, LocalDateTime endTime, String exitMessage,
String errorMessage); String errorMessage);
/** /**
@@ -106,7 +106,7 @@ public interface TaskExecutionDao {
* @param endTime the time the task completed. * @param endTime the time the task completed.
* @param exitMessage the message assigned to the task upon completion. * @param exitMessage the message assigned to the task upon completion.
*/ */
void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage); void completeTaskExecution(long executionId, Integer exitCode, LocalDateTime endTime, String exitMessage);
/** /**
* Retrieves a task execution from the task repository. * Retrieves a task execution from the task repository.

View File

@@ -16,8 +16,8 @@
package org.springframework.cloud.task.repository.support; package org.springframework.cloud.task.repository.support;
import java.time.LocalDateTime;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@@ -87,13 +87,14 @@ public class SimpleTaskRepository implements TaskRepository {
} }
@Override @Override
public TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage) { public TaskExecution completeTaskExecution(long executionId, Integer exitCode, LocalDateTime endTime,
String exitMessage) {
return completeTaskExecution(executionId, exitCode, endTime, exitMessage, null); return completeTaskExecution(executionId, exitCode, endTime, exitMessage, null);
} }
@Override @Override
public TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage, public TaskExecution completeTaskExecution(long executionId, Integer exitCode, LocalDateTime endTime,
String errorMessage) { String exitMessage, String errorMessage) {
initialize(); initialize();
validateCompletedTaskExitInformation(executionId, exitCode, endTime); validateCompletedTaskExitInformation(executionId, exitCode, endTime);
@@ -133,8 +134,8 @@ public class SimpleTaskRepository implements TaskRepository {
} }
@Override @Override
public TaskExecution startTaskExecution(long executionid, String taskName, Date startTime, List<String> arguments, public TaskExecution startTaskExecution(long executionid, String taskName, LocalDateTime startTime,
String externalExecutionId) { List<String> arguments, String externalExecutionId) {
return startTaskExecution(executionid, taskName, startTime, arguments, externalExecutionId, null); return startTaskExecution(executionid, taskName, startTime, arguments, externalExecutionId, null);
} }
@@ -145,8 +146,8 @@ public class SimpleTaskRepository implements TaskRepository {
} }
@Override @Override
public TaskExecution startTaskExecution(long executionid, String taskName, Date startTime, List<String> arguments, public TaskExecution startTaskExecution(long executionid, String taskName, LocalDateTime startTime,
String externalExecutionId, Long parentExecutionId) { List<String> arguments, String externalExecutionId, Long parentExecutionId) {
initialize(); initialize();
TaskExecution taskExecution = this.taskExecutionDao.startTaskExecution(executionid, taskName, startTime, TaskExecution taskExecution = this.taskExecutionDao.startTaskExecution(executionid, taskName, startTime,
arguments, externalExecutionId, parentExecutionId); arguments, externalExecutionId, parentExecutionId);
@@ -187,7 +188,7 @@ public class SimpleTaskRepository implements TaskRepository {
} }
} }
private void validateCompletedTaskExitInformation(long executionId, Integer exitCode, Date endTime) { private void validateCompletedTaskExitInformation(long executionId, Integer exitCode, LocalDateTime endTime) {
Assert.notNull(exitCode, "exitCode should not be null"); Assert.notNull(exitCode, "exitCode should not be null");
Assert.isTrue(exitCode >= 0, "exit code must be greater than or equal to zero"); Assert.isTrue(exitCode >= 0, "exit code must be greater than or equal to zero");
Assert.notNull(endTime, "TaskExecution endTime cannot be null."); Assert.notNull(endTime, "TaskExecution endTime cannot be null.");

View File

@@ -1,13 +1,13 @@
CREATE TABLE TASK_EXECUTION ( CREATE TABLE TASK_EXECUTION (
TASK_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY , TASK_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
START_TIME TIMESTAMP DEFAULT NULL , START_TIME TIMESTAMP(9) DEFAULT NULL ,
END_TIME TIMESTAMP DEFAULT NULL , END_TIME TIMESTAMP(9) DEFAULT NULL ,
TASK_NAME VARCHAR(100) , TASK_NAME VARCHAR(100) ,
EXIT_CODE INTEGER , EXIT_CODE INTEGER ,
EXIT_MESSAGE VARCHAR(2500) , EXIT_MESSAGE VARCHAR(2500) ,
ERROR_MESSAGE VARCHAR(2500) , ERROR_MESSAGE VARCHAR(2500) ,
LAST_UPDATED TIMESTAMP, LAST_UPDATED TIMESTAMP(9),
EXTERNAL_EXECUTION_ID VARCHAR(255), EXTERNAL_EXECUTION_ID VARCHAR(255),
PARENT_EXECUTION_ID BIGINT PARENT_EXECUTION_ID BIGINT
); );
@@ -32,6 +32,6 @@ CREATE TABLE TASK_LOCK (
LOCK_KEY CHAR(36) NOT NULL, LOCK_KEY CHAR(36) NOT NULL,
REGION VARCHAR(100) NOT NULL, REGION VARCHAR(100) NOT NULL,
CLIENT_ID CHAR(36), CLIENT_ID CHAR(36),
CREATED_DATE TIMESTAMP NOT NULL, CREATED_DATE TIMESTAMP(9) NOT NULL,
constraint LOCK_PK primary key (LOCK_KEY, REGION) constraint LOCK_PK primary key (LOCK_KEY, REGION)
); );

View File

@@ -1,13 +1,13 @@
CREATE TABLE TASK_EXECUTION ( CREATE TABLE TASK_EXECUTION (
TASK_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY , TASK_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
START_TIME TIMESTAMP DEFAULT NULL , START_TIME TIMESTAMP(9) DEFAULT NULL ,
END_TIME TIMESTAMP DEFAULT NULL , END_TIME TIMESTAMP(9) DEFAULT NULL ,
TASK_NAME VARCHAR(100) , TASK_NAME VARCHAR(100) ,
EXIT_CODE INTEGER , EXIT_CODE INTEGER ,
EXIT_MESSAGE VARCHAR(2500) , EXIT_MESSAGE VARCHAR(2500) ,
ERROR_MESSAGE VARCHAR(2500) , ERROR_MESSAGE VARCHAR(2500) ,
LAST_UPDATED TIMESTAMP, LAST_UPDATED TIMESTAMP(9),
EXTERNAL_EXECUTION_ID VARCHAR(255), EXTERNAL_EXECUTION_ID VARCHAR(255),
PARENT_EXECUTION_ID BIGINT PARENT_EXECUTION_ID BIGINT
); );
@@ -32,6 +32,6 @@ CREATE TABLE TASK_LOCK (
LOCK_KEY CHAR(36) NOT NULL, LOCK_KEY CHAR(36) NOT NULL,
REGION VARCHAR(100) NOT NULL, REGION VARCHAR(100) NOT NULL,
CLIENT_ID CHAR(36), CLIENT_ID CHAR(36),
CREATED_DATE TIMESTAMP NOT NULL, CREATED_DATE TIMESTAMP(9) NOT NULL,
constraint LOCK_PK primary key (LOCK_KEY, REGION) constraint LOCK_PK primary key (LOCK_KEY, REGION)
); );

View File

@@ -1,13 +1,13 @@
CREATE TABLE TASK_EXECUTION ( CREATE TABLE TASK_EXECUTION (
TASK_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY , TASK_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
START_TIME TIMESTAMP DEFAULT NULL , START_TIME TIMESTAMP(9) DEFAULT NULL ,
END_TIME TIMESTAMP DEFAULT NULL , END_TIME TIMESTAMP(9) DEFAULT NULL ,
TASK_NAME VARCHAR(100) , TASK_NAME VARCHAR(100) ,
EXIT_CODE INTEGER , EXIT_CODE INTEGER ,
EXIT_MESSAGE VARCHAR(2500) , EXIT_MESSAGE VARCHAR(2500) ,
ERROR_MESSAGE VARCHAR(2500) , ERROR_MESSAGE VARCHAR(2500) ,
LAST_UPDATED TIMESTAMP, LAST_UPDATED TIMESTAMP(9),
EXTERNAL_EXECUTION_ID VARCHAR(255), EXTERNAL_EXECUTION_ID VARCHAR(255),
PARENT_EXECUTION_ID BIGINT PARENT_EXECUTION_ID BIGINT
); );
@@ -34,6 +34,6 @@ CREATE TABLE TASK_LOCK (
LOCK_KEY CHAR(36) NOT NULL, LOCK_KEY CHAR(36) NOT NULL,
REGION VARCHAR(100) NOT NULL, REGION VARCHAR(100) NOT NULL,
CLIENT_ID CHAR(36), CLIENT_ID CHAR(36),
CREATED_DATE TIMESTAMP NOT NULL, CREATED_DATE TIMESTAMP(9) NOT NULL,
constraint LOCK_PK primary key (LOCK_KEY, REGION) constraint LOCK_PK primary key (LOCK_KEY, REGION)
); );

View File

@@ -1,13 +1,13 @@
CREATE TABLE TASK_EXECUTION ( CREATE TABLE TASK_EXECUTION (
TASK_EXECUTION_ID NUMBER NOT NULL PRIMARY KEY , TASK_EXECUTION_ID NUMBER NOT NULL PRIMARY KEY ,
START_TIME TIMESTAMP DEFAULT NULL , START_TIME TIMESTAMP(9) DEFAULT NULL ,
END_TIME TIMESTAMP DEFAULT NULL , END_TIME TIMESTAMP(9) DEFAULT NULL ,
TASK_NAME VARCHAR2(100) , TASK_NAME VARCHAR2(100) ,
EXIT_CODE INTEGER , EXIT_CODE INTEGER ,
EXIT_MESSAGE VARCHAR2(2500) , EXIT_MESSAGE VARCHAR2(2500) ,
ERROR_MESSAGE VARCHAR2(2500) , ERROR_MESSAGE VARCHAR2(2500) ,
LAST_UPDATED TIMESTAMP, LAST_UPDATED TIMESTAMP(9),
EXTERNAL_EXECUTION_ID VARCHAR2(255), EXTERNAL_EXECUTION_ID VARCHAR2(255),
PARENT_EXECUTION_ID NUMBER PARENT_EXECUTION_ID NUMBER
); );
@@ -32,6 +32,6 @@ CREATE TABLE TASK_LOCK (
LOCK_KEY VARCHAR2(36) NOT NULL, LOCK_KEY VARCHAR2(36) NOT NULL,
REGION VARCHAR2(100) NOT NULL, REGION VARCHAR2(100) NOT NULL,
CLIENT_ID VARCHAR2(36), CLIENT_ID VARCHAR2(36),
CREATED_DATE TIMESTAMP NOT NULL, CREATED_DATE TIMESTAMP(9) NOT NULL,
constraint LOCK_PK primary key (LOCK_KEY, REGION) constraint LOCK_PK primary key (LOCK_KEY, REGION)
); );

View File

@@ -16,8 +16,8 @@
package org.springframework.cloud.task.configuration; package org.springframework.cloud.task.configuration;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import javax.sql.DataSource; import javax.sql.DataSource;
@@ -93,7 +93,7 @@ public class RepositoryTransactionManagerConfigurationTests {
TaskExecution taskExecution = taskRepository.createTaskExecution("transactionManagerTask"); TaskExecution taskExecution = taskRepository.createTaskExecution("transactionManagerTask");
taskExecution = taskRepository.startTaskExecution(taskExecution.getExecutionId(), taskExecution = taskRepository.startTaskExecution(taskExecution.getExecutionId(),
taskExecution.getTaskName(), new Date(), new ArrayList<>(0), null); taskExecution.getTaskName(), LocalDateTime.now(), new ArrayList<>(0), null);
TaskLifecycleListener listener = context.getBean(TaskLifecycleListener.class); TaskLifecycleListener listener = context.getBean(TaskLifecycleListener.class);

View File

@@ -17,8 +17,8 @@
package org.springframework.cloud.task.listener; package org.springframework.cloud.task.listener;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@@ -81,8 +81,8 @@ public class TaskExecutionListenerTests {
setupContextForTaskExecutionListener(); setupContextForTaskExecutionListener();
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener = this.context DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener = this.context
.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class); .getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
TaskExecution taskExecution = new TaskExecution(0, null, "wombat", new Date(), new Date(), null, TaskExecution taskExecution = new TaskExecution(0, null, "wombat", LocalDateTime.now(), LocalDateTime.now(),
new ArrayList<>(), null, null); null, new ArrayList<>(), null, null);
verifyListenerResults(false, false, taskExecution, taskExecutionListener); verifyListenerResults(false, false, taskExecution, taskExecutionListener);
} }
@@ -155,8 +155,8 @@ public class TaskExecutionListenerTests {
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], this.context, this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], this.context,
Duration.ofSeconds(50))); Duration.ofSeconds(50)));
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat", new Date(), new Date(), null, new ArrayList<>(), TaskExecution taskExecution = new TaskExecution(0, 0, "wombat", LocalDateTime.now(), LocalDateTime.now(), null,
null, null); new ArrayList<>(), null, null);
verifyListenerResults(true, false, taskExecution, taskExecutionListener); verifyListenerResults(true, false, taskExecution, taskExecutionListener);
} }
@@ -175,8 +175,8 @@ public class TaskExecutionListenerTests {
this.context.publishEvent( this.context.publishEvent(
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50))); new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(), new Date(), null, new ArrayList<>(), TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", LocalDateTime.now(), LocalDateTime.now(), null,
null, null); new ArrayList<>(), null, null);
verifyListenerResults(true, true, taskExecution, taskExecutionListener); verifyListenerResults(true, true, taskExecution, taskExecutionListener);
} }
@@ -189,8 +189,8 @@ public class TaskExecutionListenerTests {
setupContextForAnnotatedListener(); setupContextForAnnotatedListener();
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener = this.context DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener = this.context
.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class); .getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
TaskExecution taskExecution = new TaskExecution(0, null, "wombat", new Date(), new Date(), null, TaskExecution taskExecution = new TaskExecution(0, null, "wombat", LocalDateTime.now(), LocalDateTime.now(),
new ArrayList<>(), null, null); null, new ArrayList<>(), null, null);
verifyListenerResults(false, false, taskExecution, annotatedListener); verifyListenerResults(false, false, taskExecution, annotatedListener);
} }
@@ -206,8 +206,8 @@ public class TaskExecutionListenerTests {
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], this.context, this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], this.context,
Duration.ofSeconds(50))); Duration.ofSeconds(50)));
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat", new Date(), new Date(), null, new ArrayList<>(), TaskExecution taskExecution = new TaskExecution(0, 0, "wombat", LocalDateTime.now(), LocalDateTime.now(), null,
null, null); new ArrayList<>(), null, null);
verifyListenerResults(true, false, taskExecution, annotatedListener); verifyListenerResults(true, false, taskExecution, annotatedListener);
} }
@@ -226,8 +226,8 @@ public class TaskExecutionListenerTests {
this.context.publishEvent( this.context.publishEvent(
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50))); new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(), new Date(), null, new ArrayList<>(), TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", LocalDateTime.now(), LocalDateTime.now(), null,
null, null); new ArrayList<>(), null, null);
verifyListenerResults(true, true, taskExecution, annotatedListener); verifyListenerResults(true, true, taskExecution, annotatedListener);
} }

View File

@@ -255,7 +255,8 @@ public class TaskLifecycleListenerTests {
} }
if (update) { if (update) {
assertThat(taskExecution.getEndTime().getTime() >= taskExecution.getStartTime().getTime()).isTrue(); assertThat(taskExecution.getEndTime().isAfter(taskExecution.getStartTime())
|| taskExecution.getEndTime().isEqual(taskExecution.getStartTime())).isTrue();
assertThat(taskExecution.getExitCode()).isNotNull(); assertThat(taskExecution.getExitCode()).isNotNull();
} }
else { else {

View File

@@ -16,8 +16,8 @@
package org.springframework.cloud.task.micrometer; package org.springframework.cloud.task.micrometer;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import io.micrometer.core.instrument.LongTaskTimer; import io.micrometer.core.instrument.LongTaskTimer;
import io.micrometer.core.instrument.Tags; import io.micrometer.core.instrument.Tags;
@@ -99,8 +99,8 @@ public class TaskObservationsTests {
@Test @Test
public void defaultTaskTest() { public void defaultTaskTest() {
TaskExecution taskExecution = new TaskExecution(123L, 0, null, new Date(), new Date(), null, new ArrayList<>(), TaskExecution taskExecution = new TaskExecution(123L, 0, null, LocalDateTime.now(), LocalDateTime.now(), null,
null, null, null); new ArrayList<>(), null, null, null);
// Start Task // Start Task
taskObservations.onTaskStartup(taskExecution); taskObservations.onTaskStartup(taskExecution);
@@ -274,8 +274,8 @@ public class TaskObservationsTests {
} }
private TaskExecution startupObservationForBasicTests(String taskName, long taskExecutionId) { private TaskExecution startupObservationForBasicTests(String taskName, long taskExecutionId) {
TaskExecution taskExecution = new TaskExecution(taskExecutionId, 0, taskName, new Date(), new Date(), null, TaskExecution taskExecution = new TaskExecution(taskExecutionId, 0, taskName, LocalDateTime.now(),
new ArrayList<>(), null, "-1", -1L); LocalDateTime.now(), null, new ArrayList<>(), null, "-1", -1L);
// Start Task // Start Task
taskObservations.onTaskStartup(taskExecution); taskObservations.onTaskStartup(taskExecution);

View File

@@ -16,10 +16,8 @@
package org.springframework.cloud.task.repository.dao; package org.springframework.cloud.task.repository.dao;
import java.util.Calendar; import java.time.LocalDateTime;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.TimeZone;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@@ -90,15 +88,12 @@ public abstract class BaseTaskExecutionDaoTestCases {
final TaskExecution lastTaskExecution = latestTaskExecutions.get(0); final TaskExecution lastTaskExecution = latestTaskExecutions.get(0);
assertThat(lastTaskExecution.getTaskName()).isEqualTo("FOO1"); assertThat(lastTaskExecution.getTaskName()).isEqualTo("FOO1");
final Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")); assertThat(lastTaskExecution.getStartTime().getYear()).isEqualTo(2015);
dateTime.setTime(lastTaskExecution.getStartTime()); assertThat(lastTaskExecution.getStartTime().getMonthValue()).isEqualTo(2);
assertThat(lastTaskExecution.getStartTime().getDayOfMonth()).isEqualTo(22);
assertThat(dateTime.get(Calendar.YEAR)).isEqualTo(2015); assertThat(lastTaskExecution.getStartTime().getHour()).isEqualTo(23);
assertThat(dateTime.get(Calendar.MONTH) + 1).isEqualTo(2); assertThat(lastTaskExecution.getStartTime().getMinute()).isEqualTo(59);
assertThat(dateTime.get(Calendar.DAY_OF_MONTH)).isEqualTo(22); assertThat(lastTaskExecution.getStartTime().getSecond()).isEqualTo(0);
assertThat(dateTime.get(Calendar.HOUR_OF_DAY)).isEqualTo(23);
assertThat(dateTime.get(Calendar.MINUTE)).isEqualTo(59);
assertThat(dateTime.get(Calendar.SECOND)).isEqualTo(0);
} }
@Test @Test
@@ -110,35 +105,31 @@ public abstract class BaseTaskExecutionDaoTestCases {
assertThat(latestTaskExecutions.size() == 3) assertThat(latestTaskExecutions.size() == 3)
.as("Expected 3 taskExecutions but got " + latestTaskExecutions.size()).isTrue(); .as("Expected 3 taskExecutions but got " + latestTaskExecutions.size()).isTrue();
final Calendar dateTimeFoo3 = Calendar.getInstance(TimeZone.getTimeZone("UTC")); LocalDateTime startDateTime = latestTaskExecutions.get(0).getStartTime();
dateTimeFoo3.setTime(latestTaskExecutions.get(0).getStartTime()); assertThat(startDateTime.getYear()).isEqualTo(2016);
assertThat(startDateTime.getMonthValue()).isEqualTo(8);
assertThat(startDateTime.getDayOfMonth()).isEqualTo(20);
assertThat(startDateTime.getHour()).isEqualTo(14);
assertThat(startDateTime.getMinute()).isEqualTo(45);
assertThat(startDateTime.getSecond()).isEqualTo(0);
assertThat(dateTimeFoo3.get(Calendar.YEAR)).isEqualTo(2016); LocalDateTime startDateTimeOne = latestTaskExecutions.get(1).getStartTime();
assertThat(dateTimeFoo3.get(Calendar.MONTH) + 1).isEqualTo(8);
assertThat(dateTimeFoo3.get(Calendar.DAY_OF_MONTH)).isEqualTo(20);
assertThat(dateTimeFoo3.get(Calendar.HOUR_OF_DAY)).isEqualTo(14);
assertThat(dateTimeFoo3.get(Calendar.MINUTE)).isEqualTo(45);
assertThat(dateTimeFoo3.get(Calendar.SECOND)).isEqualTo(0);
final Calendar dateTimeFoo1 = Calendar.getInstance(TimeZone.getTimeZone("UTC")); assertThat(startDateTimeOne.getYear()).isEqualTo(2015);
dateTimeFoo1.setTime(latestTaskExecutions.get(1).getStartTime()); assertThat(startDateTimeOne.getMonthValue()).isEqualTo(2);
assertThat(startDateTimeOne.getDayOfMonth()).isEqualTo(22);
assertThat(startDateTimeOne.getHour()).isEqualTo(23);
assertThat(startDateTimeOne.getMinute()).isEqualTo(59);
assertThat(startDateTimeOne.getSecond()).isEqualTo(0);
assertThat(dateTimeFoo1.get(Calendar.YEAR)).isEqualTo(2015); LocalDateTime startDateTimeTwo = latestTaskExecutions.get(2).getStartTime();
assertThat(dateTimeFoo1.get(Calendar.MONTH) + 1).isEqualTo(2);
assertThat(dateTimeFoo1.get(Calendar.DAY_OF_MONTH)).isEqualTo(22);
assertThat(dateTimeFoo1.get(Calendar.HOUR_OF_DAY)).isEqualTo(23);
assertThat(dateTimeFoo1.get(Calendar.MINUTE)).isEqualTo(59);
assertThat(dateTimeFoo1.get(Calendar.SECOND)).isEqualTo(0);
final Calendar dateTimeFoo4 = Calendar.getInstance(TimeZone.getTimeZone("UTC")); assertThat(startDateTimeTwo.getYear()).isEqualTo(2015);
dateTimeFoo4.setTime(latestTaskExecutions.get(2).getStartTime()); assertThat(startDateTimeTwo.getMonthValue()).isEqualTo(2);
assertThat(startDateTimeTwo.getDayOfMonth()).isEqualTo(20);
assertThat(dateTimeFoo4.get(Calendar.YEAR)).isEqualTo(2015); assertThat(startDateTimeTwo.getHour()).isEqualTo(14);
assertThat(dateTimeFoo4.get(Calendar.MONTH) + 1).isEqualTo(2); assertThat(startDateTimeTwo.getMinute()).isEqualTo(45);
assertThat(dateTimeFoo4.get(Calendar.DAY_OF_MONTH)).isEqualTo(20); assertThat(startDateTimeTwo.getSecond()).isEqualTo(0);
assertThat(dateTimeFoo4.get(Calendar.HOUR_OF_DAY)).isEqualTo(14);
assertThat(dateTimeFoo4.get(Calendar.MINUTE)).isEqualTo(45);
assertThat(dateTimeFoo4.get(Calendar.SECOND)).isEqualTo(0);
} }
/** /**
@@ -154,15 +145,14 @@ public abstract class BaseTaskExecutionDaoTestCases {
assertThat(latestTaskExecutions.size() == 1) assertThat(latestTaskExecutions.size() == 1)
.as("Expected only 1 taskExecution but got " + latestTaskExecutions.size()).isTrue(); .as("Expected only 1 taskExecution but got " + latestTaskExecutions.size()).isTrue();
final Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")); LocalDateTime startDateTime = latestTaskExecutions.get(0).getStartTime();
dateTime.setTime(latestTaskExecutions.get(0).getStartTime());
assertThat(dateTime.get(Calendar.YEAR)).isEqualTo(2015); assertThat(startDateTime.getYear()).isEqualTo(2015);
assertThat(dateTime.get(Calendar.MONTH) + 1).isEqualTo(2); assertThat(startDateTime.getMonthValue()).isEqualTo(2);
assertThat(dateTime.get(Calendar.DAY_OF_MONTH)).isEqualTo(22); assertThat(startDateTime.getDayOfMonth()).isEqualTo(22);
assertThat(dateTime.get(Calendar.HOUR_OF_DAY)).isEqualTo(23); assertThat(startDateTime.getHour()).isEqualTo(23);
assertThat(dateTime.get(Calendar.MINUTE)).isEqualTo(59); assertThat(startDateTime.getMinute()).isEqualTo(59);
assertThat(dateTime.get(Calendar.SECOND)).isEqualTo(0); assertThat(startDateTime.getSecond()).isEqualTo(0);
assertThat(latestTaskExecutions.get(0).getExecutionId()).isEqualTo(9 + executionIdOffset); assertThat(latestTaskExecutions.get(0).getExecutionId()).isEqualTo(9 + executionIdOffset);
} }
@@ -208,15 +198,14 @@ public abstract class BaseTaskExecutionDaoTestCases {
final TaskExecution latestTaskExecution = this.dao.getLatestTaskExecutionForTaskName("FOO1"); final TaskExecution latestTaskExecution = this.dao.getLatestTaskExecutionForTaskName("FOO1");
assertThat(latestTaskExecution).as("Expected the latestTaskExecution not to be null").isNotNull(); assertThat(latestTaskExecution).as("Expected the latestTaskExecution not to be null").isNotNull();
final Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")); LocalDateTime startDateTime = latestTaskExecution.getStartTime();
dateTime.setTime(latestTaskExecution.getStartTime());
assertThat(dateTime.get(Calendar.YEAR)).isEqualTo(2015); assertThat(startDateTime.getYear()).isEqualTo(2015);
assertThat(dateTime.get(Calendar.MONTH) + 1).isEqualTo(2); assertThat(startDateTime.getMonthValue()).isEqualTo(2);
assertThat(dateTime.get(Calendar.DAY_OF_MONTH)).isEqualTo(22); assertThat(startDateTime.getDayOfMonth()).isEqualTo(22);
assertThat(dateTime.get(Calendar.HOUR_OF_DAY)).isEqualTo(23); assertThat(startDateTime.getHour()).isEqualTo(23);
assertThat(dateTime.get(Calendar.MINUTE)).isEqualTo(59); assertThat(startDateTime.getMinute()).isEqualTo(59);
assertThat(dateTime.get(Calendar.SECOND)).isEqualTo(0); assertThat(startDateTime.getSecond()).isEqualTo(0);
} }
/** /**
@@ -231,15 +220,14 @@ public abstract class BaseTaskExecutionDaoTestCases {
final TaskExecution latestTaskExecution = this.dao.getLatestTaskExecutionForTaskName("FOO5"); final TaskExecution latestTaskExecution = this.dao.getLatestTaskExecutionForTaskName("FOO5");
assertThat(latestTaskExecution).as("Expected the latestTaskExecution not to be null").isNotNull(); assertThat(latestTaskExecution).as("Expected the latestTaskExecution not to be null").isNotNull();
final Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")); LocalDateTime startDateTime = latestTaskExecution.getStartTime();
dateTime.setTime(latestTaskExecution.getStartTime());
assertThat(dateTime.get(Calendar.YEAR)).isEqualTo(2015); assertThat(startDateTime.getYear()).isEqualTo(2015);
assertThat(dateTime.get(Calendar.MONTH) + 1).isEqualTo(2); assertThat(startDateTime.getMonthValue()).isEqualTo(2);
assertThat(dateTime.get(Calendar.DAY_OF_MONTH)).isEqualTo(22); assertThat(startDateTime.getDayOfMonth()).isEqualTo(22);
assertThat(dateTime.get(Calendar.HOUR_OF_DAY)).isEqualTo(23); assertThat(startDateTime.getHour()).isEqualTo(23);
assertThat(dateTime.get(Calendar.MINUTE)).isEqualTo(59); assertThat(startDateTime.getMinute()).isEqualTo(59);
assertThat(dateTime.get(Calendar.SECOND)).isEqualTo(0); assertThat(startDateTime.getSecond()).isEqualTo(0);
assertThat(latestTaskExecution.getExecutionId()).isEqualTo(9 + executionIdOffset); assertThat(latestTaskExecution.getExecutionId()).isEqualTo(9 + executionIdOffset);
} }
@@ -248,7 +236,7 @@ public abstract class BaseTaskExecutionDaoTestCases {
public void getRunningTaskExecutions() { public void getRunningTaskExecutions() {
initializeRepositoryNotInOrderWithMultipleTaskExecutions(); initializeRepositoryNotInOrderWithMultipleTaskExecutions();
assertThat(this.dao.getRunningTaskExecutionCount()).isEqualTo(this.dao.getTaskExecutionCount()); assertThat(this.dao.getRunningTaskExecutionCount()).isEqualTo(this.dao.getTaskExecutionCount());
this.dao.completeTaskExecution(1, 0, new Date(), "c'est fini!"); this.dao.completeTaskExecution(1, 0, LocalDateTime.now(), "c'est fini!");
assertThat(this.dao.getRunningTaskExecutionCount()).isEqualTo(this.dao.getTaskExecutionCount() - 1); assertThat(this.dao.getRunningTaskExecutionCount()).isEqualTo(this.dao.getTaskExecutionCount() - 1);
} }
@@ -300,11 +288,9 @@ public abstract class BaseTaskExecutionDaoTestCases {
return executionIdOffset; return executionIdOffset;
} }
private Date getDate(int year, int month, int day, int hour, int minute) { private LocalDateTime getDate(int year, int month, int day, int hour, int minute) {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); return LocalDateTime.now().withYear(year).withMonth(month).withDayOfMonth(day).withHour(hour).withMinute(minute)
calendar.clear(); .withSecond(0);
calendar.set(year, month - 1, day, hour, minute);
return calendar.getTime();
} }
private long createTaskExecution(TaskExecution te) { private long createTaskExecution(TaskExecution te) {
@@ -316,7 +302,7 @@ public abstract class BaseTaskExecutionDaoTestCases {
TaskExecution taskExecution = new TaskExecution(); TaskExecution taskExecution = new TaskExecution();
taskExecution.setTaskName(taskName); taskExecution.setTaskName(taskName);
taskExecution.setExternalExecutionId(externalExecutionId); taskExecution.setExternalExecutionId(externalExecutionId);
taskExecution.setStartTime(new Date()); taskExecution.setStartTime(LocalDateTime.now());
return taskExecution; return taskExecution;
} }

View File

@@ -16,9 +16,9 @@
package org.springframework.cloud.task.repository.dao; package org.springframework.cloud.task.repository.dao;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
@@ -79,7 +79,7 @@ public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null, new ArrayList<>(0), null); TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null, new ArrayList<>(0), null);
expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString())); expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString()));
expectedTaskExecution.setStartTime(new Date()); expectedTaskExecution.setStartTime(LocalDateTime.now());
expectedTaskExecution.setTaskName(UUID.randomUUID().toString()); expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(), this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),

View File

@@ -16,9 +16,9 @@
package org.springframework.cloud.task.repository.dao; package org.springframework.cloud.task.repository.dao;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -55,7 +55,7 @@ public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null, new ArrayList<>(0), null); TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null, new ArrayList<>(0), null);
expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString())); expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString()));
expectedTaskExecution.setStartTime(new Date()); expectedTaskExecution.setStartTime(LocalDateTime.now());
expectedTaskExecution.setTaskName(UUID.randomUUID().toString()); expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(), this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),

View File

@@ -16,11 +16,11 @@
package org.springframework.cloud.task.repository.support; package org.springframework.cloud.task.repository.support;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@@ -418,7 +418,7 @@ public class SimpleTaskExplorerTests {
private TaskExecution getSimpleTaskExecution() { private TaskExecution getSimpleTaskExecution() {
TaskExecution taskExecution = new TaskExecution(); TaskExecution taskExecution = new TaskExecution();
taskExecution.setTaskName(TASK_NAME); taskExecution.setTaskName(TASK_NAME);
taskExecution.setStartTime(new Date()); taskExecution.setStartTime(LocalDateTime.now());
taskExecution.setExternalExecutionId(EXTERNAL_EXECUTION_ID); taskExecution.setExternalExecutionId(EXTERNAL_EXECUTION_ID);
return taskExecution; return taskExecution;
} }

View File

@@ -16,8 +16,8 @@
package org.springframework.cloud.task.repository.support; package org.springframework.cloud.task.repository.support;
import java.time.LocalDateTime;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.UUID; import java.util.UUID;
import javax.sql.DataSource; import javax.sql.DataSource;
@@ -97,7 +97,7 @@ public class SimpleTaskRepositoryJdbcTests {
.createAndStoreEmptyTaskExecution(this.taskRepository); .createAndStoreEmptyTaskExecution(this.taskRepository);
expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString())); expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString()));
expectedTaskExecution.setStartTime(new Date()); expectedTaskExecution.setStartTime(LocalDateTime.now());
expectedTaskExecution.setTaskName(UUID.randomUUID().toString()); expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution( TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
@@ -114,7 +114,7 @@ public class SimpleTaskRepositoryJdbcTests {
TaskExecution expectedTaskExecution = TaskExecutionCreator TaskExecution expectedTaskExecution = TaskExecutionCreator
.createAndStoreEmptyTaskExecution(this.taskRepository); .createAndStoreEmptyTaskExecution(this.taskRepository);
expectedTaskExecution.setStartTime(new Date()); expectedTaskExecution.setStartTime(LocalDateTime.now());
expectedTaskExecution.setTaskName(UUID.randomUUID().toString()); expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution( TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
@@ -163,7 +163,7 @@ public class SimpleTaskRepositoryJdbcTests {
TaskExecution expectedTaskExecution = TaskExecutionCreator TaskExecution expectedTaskExecution = TaskExecutionCreator
.createAndStoreEmptyTaskExecution(this.taskRepository); .createAndStoreEmptyTaskExecution(this.taskRepository);
expectedTaskExecution.setStartTime(new Date()); expectedTaskExecution.setStartTime(LocalDateTime.now());
expectedTaskExecution.setTaskName(UUID.randomUUID().toString()); expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
expectedTaskExecution.setParentExecutionId(12345L); expectedTaskExecution.setParentExecutionId(12345L);
@@ -180,7 +180,7 @@ public class SimpleTaskRepositoryJdbcTests {
public void testCompleteTaskExecution() { public void testCompleteTaskExecution() {
TaskExecution expectedTaskExecution = TaskExecutionCreator TaskExecution expectedTaskExecution = TaskExecutionCreator
.createAndStoreTaskExecutionNoParams(this.taskRepository); .createAndStoreTaskExecutionNoParams(this.taskRepository);
expectedTaskExecution.setEndTime(new Date()); expectedTaskExecution.setEndTime(LocalDateTime.now());
expectedTaskExecution.setExitCode(77); expectedTaskExecution.setExitCode(77);
expectedTaskExecution.setExitMessage(UUID.randomUUID().toString()); expectedTaskExecution.setExitMessage(UUID.randomUUID().toString());
@@ -195,7 +195,7 @@ public class SimpleTaskRepositoryJdbcTests {
TaskExecution expectedTaskExecution = TaskExecutionCreator TaskExecution expectedTaskExecution = TaskExecutionCreator
.createAndStoreTaskExecutionNoParams(this.taskRepository); .createAndStoreTaskExecutionNoParams(this.taskRepository);
expectedTaskExecution.setExitMessage(new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1])); expectedTaskExecution.setExitMessage(new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
expectedTaskExecution.setEndTime(new Date()); expectedTaskExecution.setEndTime(LocalDateTime.now());
expectedTaskExecution.setExitCode(0); expectedTaskExecution.setExitCode(0);
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, this.taskRepository); TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, this.taskRepository);
assertThat(actualTaskExecution.getExitMessage().length()).isEqualTo(SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE); assertThat(actualTaskExecution.getExitMessage().length()).isEqualTo(SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE);
@@ -210,7 +210,7 @@ public class SimpleTaskRepositoryJdbcTests {
TaskExecution expectedTaskExecution = TaskExecutionCreator TaskExecution expectedTaskExecution = TaskExecutionCreator
.createAndStoreTaskExecutionNoParams(simpleTaskRepository); .createAndStoreTaskExecutionNoParams(simpleTaskRepository);
expectedTaskExecution.setExitMessage(new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1])); expectedTaskExecution.setExitMessage(new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
expectedTaskExecution.setEndTime(new Date()); expectedTaskExecution.setEndTime(LocalDateTime.now());
expectedTaskExecution.setExitCode(0); expectedTaskExecution.setExitCode(0);
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, simpleTaskRepository); TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, simpleTaskRepository);
assertThat(actualTaskExecution.getExitMessage().length()).isEqualTo(5); assertThat(actualTaskExecution.getExitMessage().length()).isEqualTo(5);
@@ -222,7 +222,7 @@ public class SimpleTaskRepositoryJdbcTests {
TaskExecution expectedTaskExecution = TaskExecutionCreator TaskExecution expectedTaskExecution = TaskExecutionCreator
.createAndStoreTaskExecutionNoParams(this.taskRepository); .createAndStoreTaskExecutionNoParams(this.taskRepository);
expectedTaskExecution.setErrorMessage(new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1])); expectedTaskExecution.setErrorMessage(new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
expectedTaskExecution.setEndTime(new Date()); expectedTaskExecution.setEndTime(LocalDateTime.now());
expectedTaskExecution.setExitCode(0); expectedTaskExecution.setExitCode(0);
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, this.taskRepository); TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, this.taskRepository);
assertThat(actualTaskExecution.getErrorMessage().length()) assertThat(actualTaskExecution.getErrorMessage().length())
@@ -238,7 +238,7 @@ public class SimpleTaskRepositoryJdbcTests {
TaskExecution expectedTaskExecution = TaskExecutionCreator TaskExecution expectedTaskExecution = TaskExecutionCreator
.createAndStoreTaskExecutionNoParams(simpleTaskRepository); .createAndStoreTaskExecutionNoParams(simpleTaskRepository);
expectedTaskExecution.setErrorMessage(new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1])); expectedTaskExecution.setErrorMessage(new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
expectedTaskExecution.setEndTime(new Date()); expectedTaskExecution.setEndTime(LocalDateTime.now());
expectedTaskExecution.setExitCode(0); expectedTaskExecution.setExitCode(0);
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, simpleTaskRepository); TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, simpleTaskRepository);
assertThat(actualTaskExecution.getErrorMessage().length()).isEqualTo(5); assertThat(actualTaskExecution.getErrorMessage().length()).isEqualTo(5);
@@ -292,7 +292,7 @@ public class SimpleTaskRepositoryJdbcTests {
public void testCreateTaskExecutionNoParamMaxTaskName() { public void testCreateTaskExecutionNoParamMaxTaskName() {
TaskExecution taskExecution = new TaskExecution(); TaskExecution taskExecution = new TaskExecution();
taskExecution.setTaskName(new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1])); taskExecution.setTaskName(new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1]));
taskExecution.setStartTime(new Date()); taskExecution.setStartTime(LocalDateTime.now());
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
this.taskRepository.createTaskExecution(taskExecution); this.taskRepository.createTaskExecution(taskExecution);
}); });
@@ -303,7 +303,7 @@ public class SimpleTaskRepositoryJdbcTests {
public void testCreateTaskExecutionNegativeException() { public void testCreateTaskExecutionNegativeException() {
TaskExecution expectedTaskExecution = TaskExecutionCreator TaskExecution expectedTaskExecution = TaskExecutionCreator
.createAndStoreTaskExecutionNoParams(this.taskRepository); .createAndStoreTaskExecutionNoParams(this.taskRepository);
expectedTaskExecution.setEndTime(new Date()); expectedTaskExecution.setEndTime(LocalDateTime.now());
expectedTaskExecution.setExitCode(-1); expectedTaskExecution.setExitCode(-1);
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
@@ -326,7 +326,7 @@ public class SimpleTaskRepositoryJdbcTests {
private TaskExecution completeTaskExecution(TaskExecution expectedTaskExecution, TaskRepository taskRepository) { private TaskExecution completeTaskExecution(TaskExecution expectedTaskExecution, TaskRepository taskRepository) {
return taskRepository.completeTaskExecution(expectedTaskExecution.getExecutionId(), return taskRepository.completeTaskExecution(expectedTaskExecution.getExecutionId(),
expectedTaskExecution.getExitCode(), new Date(), expectedTaskExecution.getExitMessage(), expectedTaskExecution.getExitCode(), LocalDateTime.now(), expectedTaskExecution.getExitMessage(),
expectedTaskExecution.getErrorMessage()); expectedTaskExecution.getErrorMessage());
} }
@@ -335,7 +335,7 @@ public class SimpleTaskRepositoryJdbcTests {
TaskExecution expectedTaskExecution = TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository); TaskExecution expectedTaskExecution = TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
expectedTaskExecution.setErrorMessage(new String(new char[maxErrorMessage + 1])); expectedTaskExecution.setErrorMessage(new String(new char[maxErrorMessage + 1]));
expectedTaskExecution.setExitMessage(new String(new char[maxExitMessage + 1])); expectedTaskExecution.setExitMessage(new String(new char[maxExitMessage + 1]));
expectedTaskExecution.setEndTime(new Date()); expectedTaskExecution.setEndTime(LocalDateTime.now());
expectedTaskExecution.setExitCode(0); expectedTaskExecution.setExitCode(0);
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, taskRepository); TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, taskRepository);

View File

@@ -16,8 +16,8 @@
package org.springframework.cloud.task.repository.support; package org.springframework.cloud.task.repository.support;
import java.time.LocalDateTime;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@@ -110,7 +110,7 @@ public class SimpleTaskRepositoryMapTests {
.createAndStoreEmptyTaskExecution(this.taskRepository); .createAndStoreEmptyTaskExecution(this.taskRepository);
expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString())); expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString()));
expectedTaskExecution.setStartTime(new Date()); expectedTaskExecution.setStartTime(LocalDateTime.now());
expectedTaskExecution.setTaskName(UUID.randomUUID().toString()); expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution( TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
@@ -126,7 +126,7 @@ public class SimpleTaskRepositoryMapTests {
TaskExecution expectedTaskExecution = TaskExecutionCreator TaskExecution expectedTaskExecution = TaskExecutionCreator
.createAndStoreEmptyTaskExecution(this.taskRepository); .createAndStoreEmptyTaskExecution(this.taskRepository);
expectedTaskExecution.setStartTime(new Date()); expectedTaskExecution.setStartTime(LocalDateTime.now());
expectedTaskExecution.setTaskName(UUID.randomUUID().toString()); expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution( TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
@@ -142,7 +142,7 @@ public class SimpleTaskRepositoryMapTests {
TaskExecution expectedTaskExecution = TaskExecutionCreator TaskExecution expectedTaskExecution = TaskExecutionCreator
.createAndStoreEmptyTaskExecution(this.taskRepository); .createAndStoreEmptyTaskExecution(this.taskRepository);
expectedTaskExecution.setStartTime(new Date()); expectedTaskExecution.setStartTime(LocalDateTime.now());
expectedTaskExecution.setTaskName(UUID.randomUUID().toString()); expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
expectedTaskExecution.setParentExecutionId(12345L); expectedTaskExecution.setParentExecutionId(12345L);
@@ -158,7 +158,7 @@ public class SimpleTaskRepositoryMapTests {
public void testCompleteTaskExecution() { public void testCompleteTaskExecution() {
TaskExecution expectedTaskExecution = TaskExecutionCreator TaskExecution expectedTaskExecution = TaskExecutionCreator
.createAndStoreTaskExecutionNoParams(this.taskRepository); .createAndStoreTaskExecutionNoParams(this.taskRepository);
expectedTaskExecution.setEndTime(new Date()); expectedTaskExecution.setEndTime(LocalDateTime.now());
expectedTaskExecution.setExitCode(0); expectedTaskExecution.setExitCode(0);
TaskExecution actualTaskExecution = TaskExecutionCreator.completeExecution(this.taskRepository, TaskExecution actualTaskExecution = TaskExecutionCreator.completeExecution(this.taskRepository,
expectedTaskExecution); expectedTaskExecution);

View File

@@ -20,6 +20,7 @@ import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -73,9 +74,9 @@ public final class TestDBUtils {
TaskExecution taskExecution = new TaskExecution(rs.getLong("TASK_EXECUTION_ID"), TaskExecution taskExecution = new TaskExecution(rs.getLong("TASK_EXECUTION_ID"),
StringUtils.hasText(rs.getString("EXIT_CODE")) ? Integer.valueOf(rs.getString("EXIT_CODE")) StringUtils.hasText(rs.getString("EXIT_CODE")) ? Integer.valueOf(rs.getString("EXIT_CODE"))
: null, : null,
rs.getString("TASK_NAME"), rs.getTimestamp("START_TIME"), rs.getTimestamp("END_TIME"), rs.getString("TASK_NAME"), rs.getObject("START_TIME", LocalDateTime.class),
rs.getString("EXIT_MESSAGE"), new ArrayList<>(0), rs.getString("ERROR_MESSAGE"), rs.getObject("END_TIME", LocalDateTime.class), rs.getString("EXIT_MESSAGE"), new ArrayList<>(0),
rs.getString("EXTERNAL_EXECUTION_ID")); rs.getString("ERROR_MESSAGE"), rs.getString("EXTERNAL_EXECUTION_ID"));
return taskExecution; return taskExecution;
} }
}); });

View File

@@ -16,8 +16,8 @@
package org.springframework.cloud.task.util; package org.springframework.cloud.task.util;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@@ -86,11 +86,11 @@ public final class TestVerifierUtils {
*/ */
public static TaskExecution createSampleTaskExecutionNoArg() { public static TaskExecution createSampleTaskExecutionNoArg() {
Random randomGenerator = new Random(); Random randomGenerator = new Random();
Date startTime = new Date();
long executionId = randomGenerator.nextLong(); long executionId = randomGenerator.nextLong();
String taskName = UUID.randomUUID().toString(); String taskName = UUID.randomUUID().toString();
return new TaskExecution(executionId, null, taskName, startTime, null, null, new ArrayList<>(), null, null); return new TaskExecution(executionId, null, taskName, LocalDateTime.now(), null, null, new ArrayList<>(), null,
null);
} }
/** /**
@@ -100,14 +100,12 @@ public final class TestVerifierUtils {
public static TaskExecution endSampleTaskExecutionNoArg() { public static TaskExecution endSampleTaskExecutionNoArg() {
Random randomGenerator = new Random(); Random randomGenerator = new Random();
int exitCode = randomGenerator.nextInt(); int exitCode = randomGenerator.nextInt();
Date startTime = new Date();
Date endTime = new Date();
long executionId = randomGenerator.nextLong(); long executionId = randomGenerator.nextLong();
String taskName = UUID.randomUUID().toString(); String taskName = UUID.randomUUID().toString();
String exitMessage = UUID.randomUUID().toString(); String exitMessage = UUID.randomUUID().toString();
return new TaskExecution(executionId, exitCode, taskName, startTime, endTime, exitMessage, new ArrayList<>(), return new TaskExecution(executionId, exitCode, taskName, LocalDateTime.now(), LocalDateTime.now(), exitMessage,
null, null); new ArrayList<>(), null, null);
} }
/** /**
@@ -116,14 +114,14 @@ public final class TestVerifierUtils {
* @return instance of the TaskExecution. * @return instance of the TaskExecution.
*/ */
public static TaskExecution createSampleTaskExecution(long executionId) { public static TaskExecution createSampleTaskExecution(long executionId) {
Date startTime = new Date();
String taskName = UUID.randomUUID().toString(); String taskName = UUID.randomUUID().toString();
String externalExecutionId = UUID.randomUUID().toString(); String externalExecutionId = UUID.randomUUID().toString();
List<String> args = new ArrayList<>(ARG_SIZE); List<String> args = new ArrayList<>(ARG_SIZE);
for (int i = 0; i < ARG_SIZE; i++) { for (int i = 0; i < ARG_SIZE; i++) {
args.add(UUID.randomUUID().toString()); args.add(UUID.randomUUID().toString());
} }
return new TaskExecution(executionId, null, taskName, startTime, null, null, args, null, externalExecutionId); return new TaskExecution(executionId, null, taskName, LocalDateTime.now(), null, null, args, null,
externalExecutionId);
} }
/** /**
@@ -135,12 +133,12 @@ public final class TestVerifierUtils {
assertThat(actualTaskExecution.getExecutionId()).as("taskExecutionId must be equal") assertThat(actualTaskExecution.getExecutionId()).as("taskExecutionId must be equal")
.isEqualTo(expectedTaskExecution.getExecutionId()); .isEqualTo(expectedTaskExecution.getExecutionId());
if (actualTaskExecution.getStartTime() != null) { if (actualTaskExecution.getStartTime() != null) {
assertThat(actualTaskExecution.getStartTime()).as("startTime must be equal") assertThat(actualTaskExecution.getStartTime().isEqual(expectedTaskExecution.getStartTime()))
.hasSameTimeAs(expectedTaskExecution.getStartTime()); .as("startTime must be equal").isTrue();
} }
if (actualTaskExecution.getEndTime() != null) { if (actualTaskExecution.getEndTime() != null) {
assertThat(actualTaskExecution.getEndTime()).as("endTime must be equal") assertThat(actualTaskExecution.getEndTime().isEqual(expectedTaskExecution.getEndTime()))
.hasSameTimeAs(expectedTaskExecution.getEndTime()); .as("endTime must be equal").isTrue();
} }
assertThat(actualTaskExecution.getExitCode()).as("exitCode must be equal") assertThat(actualTaskExecution.getExitCode()).as("exitCode must be equal")
.isEqualTo(expectedTaskExecution.getExitCode()); .isEqualTo(expectedTaskExecution.getExitCode());

View File

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

View File

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

View File

@@ -59,7 +59,7 @@ public class TaskApplication {
private TimestampTaskProperties config; private TimestampTaskProperties config;
@Override @Override
public void run(String... strings) throws Exception { public void run(String... strings) {
DateFormat dateFormat = new SimpleDateFormat(this.config.getFormat()); DateFormat dateFormat = new SimpleDateFormat(this.config.getFormat());
logger.info(dateFormat.format(new Date())); logger.info(dateFormat.format(new Date()));
} }

View File

@@ -41,18 +41,7 @@ public class JobParametersEvent {
public JobParametersEvent(Map<String, JobParameter<?>> jobParameters) { public JobParametersEvent(Map<String, JobParameter<?>> jobParameters) {
this.parameters = new LinkedHashMap<>(); this.parameters = new LinkedHashMap<>();
for (Map.Entry<String, JobParameter<?>> entry : jobParameters.entrySet()) { for (Map.Entry<String, JobParameter<?>> entry : jobParameters.entrySet()) {
if (entry.getValue().getValue() instanceof String) { this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
}
else if (entry.getValue().getValue() instanceof Long) {
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
}
else if (entry.getValue().getValue() instanceof Date) {
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
}
else if (entry.getValue().getValue() instanceof Double) {
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
}
} }
} }
@@ -61,6 +50,7 @@ public class JobParametersEvent {
* @param key The key to get a value for * @param key The key to get a value for
* @return The <code>Long</code> value * @return The <code>Long</code> value
*/ */
@Deprecated(since = "3.0")
public Long getLong(String key) { public Long getLong(String key) {
if (!this.parameters.containsKey(key)) { if (!this.parameters.containsKey(key)) {
return 0L; return 0L;
@@ -76,6 +66,7 @@ public class JobParametersEvent {
* @param defaultValue to return if the value doesn't exist * @param defaultValue to return if the value doesn't exist
* @return the parameter represented by the provided key, defaultValue otherwise. * @return the parameter represented by the provided key, defaultValue otherwise.
*/ */
@Deprecated(since = "3.0")
public Long getLong(String key, long defaultValue) { public Long getLong(String key, long defaultValue) {
if (this.parameters.containsKey(key)) { if (this.parameters.containsKey(key)) {
return getLong(key); return getLong(key);
@@ -90,6 +81,7 @@ public class JobParametersEvent {
* @param key The key to get a value for * @param key The key to get a value for
* @return The <code>String</code> value * @return The <code>String</code> value
*/ */
@Deprecated(since = "3.0")
public String getString(String key) { public String getString(String key) {
JobParameterEvent value = this.parameters.get(key); JobParameterEvent value = this.parameters.get(key);
return value == null ? null : value.toString(); return value == null ? null : value.toString();
@@ -102,6 +94,7 @@ public class JobParametersEvent {
* @param defaultValue to return if the value doesn't exist * @param defaultValue to return if the value doesn't exist
* @return the parameter represented by the provided key, defaultValue otherwise. * @return the parameter represented by the provided key, defaultValue otherwise.
*/ */
@Deprecated(since = "3.0")
public String getString(String key, String defaultValue) { public String getString(String key, String defaultValue) {
if (this.parameters.containsKey(key)) { if (this.parameters.containsKey(key)) {
return getString(key); return getString(key);
@@ -116,6 +109,7 @@ public class JobParametersEvent {
* @param key The key to get a value for * @param key The key to get a value for
* @return The <code>Double</code> value * @return The <code>Double</code> value
*/ */
@Deprecated(since = "3.0")
public Double getDouble(String key) { public Double getDouble(String key) {
if (!this.parameters.containsKey(key)) { if (!this.parameters.containsKey(key)) {
return 0.0; return 0.0;
@@ -131,6 +125,7 @@ public class JobParametersEvent {
* @param defaultValue to return if the value doesn't exist * @param defaultValue to return if the value doesn't exist
* @return the parameter represented by the provided key, defaultValue otherwise. * @return the parameter represented by the provided key, defaultValue otherwise.
*/ */
@Deprecated(since = "3.0")
public Double getDouble(String key, double defaultValue) { public Double getDouble(String key, double defaultValue) {
if (this.parameters.containsKey(key)) { if (this.parameters.containsKey(key)) {
return getDouble(key); return getDouble(key);
@@ -145,6 +140,7 @@ public class JobParametersEvent {
* @param key The key to get a value for * @param key The key to get a value for
* @return The <code>java.util.Date</code> value * @return The <code>java.util.Date</code> value
*/ */
@Deprecated(since = "3.0")
public Date getDate(String key) { public Date getDate(String key) {
return this.getDate(key, null); return this.getDate(key, null);
} }
@@ -156,6 +152,7 @@ public class JobParametersEvent {
* @param defaultValue to return if the value doesn't exist * @param defaultValue to return if the value doesn't exist
* @return the parameter represented by the provided key, defaultValue otherwise. * @return the parameter represented by the provided key, defaultValue otherwise.
*/ */
@Deprecated(since = "3.0")
public Date getDate(String key, Date defaultValue) { public Date getDate(String key, Date defaultValue) {
if (this.parameters.containsKey(key)) { if (this.parameters.containsKey(key)) {
return (Date) this.parameters.get(key).getValue(); return (Date) this.parameters.get(key).getValue();

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.task.batch.listener; package org.springframework.cloud.task.batch.listener;
import java.util.Date; import java.time.LocalDateTime;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@@ -41,13 +41,13 @@ public class JobParameterEventTests {
@Test @Test
public void testConstructor() { public void testConstructor() {
final String EXPECTED_VALUE = "FOO"; final String EXPECTED_VALUE = "FOO";
final Date EXPECTED_DATE_VALUE = new Date(); final LocalDateTime EXPECTED_DATE_VALUE = LocalDateTime.now();
JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, String.class); JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, String.class);
JobParameterEvent jobParameterEvent = new JobParameterEvent(jobParameter); JobParameterEvent jobParameterEvent = new JobParameterEvent(jobParameter);
assertThat(jobParameterEvent.getValue()).isEqualTo(EXPECTED_VALUE); assertThat(jobParameterEvent.getValue()).isEqualTo(EXPECTED_VALUE);
assertThat(jobParameterEvent.isIdentifying()).isTrue(); assertThat(jobParameterEvent.isIdentifying()).isTrue();
jobParameter = new JobParameter(EXPECTED_DATE_VALUE, Date.class); jobParameter = new JobParameter(EXPECTED_DATE_VALUE, LocalDateTime.class);
jobParameterEvent = new JobParameterEvent(jobParameter); jobParameterEvent = new JobParameterEvent(jobParameter);
assertThat(jobParameterEvent.getValue()).isEqualTo(EXPECTED_DATE_VALUE); assertThat(jobParameterEvent.getValue()).isEqualTo(EXPECTED_DATE_VALUE);
assertThat(jobParameterEvent.isIdentifying()).isTrue(); assertThat(jobParameterEvent.isIdentifying()).isTrue();