Updated Task to support LocalDateTime from Spring Batch
This commit is contained in:
@@ -81,6 +81,10 @@
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream</artifactId>
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -54,6 +55,7 @@ public class BatchEventsApplicationTests {
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
||||
@@ -102,5 +102,11 @@
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<scope>test</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.task.batch.listener.support;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -49,13 +49,13 @@ public class JobExecutionEvent extends Entity {
|
||||
|
||||
private BatchStatus status = BatchStatus.STARTING;
|
||||
|
||||
private Date startTime = null;
|
||||
private LocalDateTime startTime = null;
|
||||
|
||||
private Date createTime = new Date(System.currentTimeMillis());
|
||||
private LocalDateTime createTime = LocalDateTime.now();
|
||||
|
||||
private Date endTime = null;
|
||||
private LocalDateTime endTime = null;
|
||||
|
||||
private Date lastUpdated = null;
|
||||
private LocalDateTime lastUpdated = null;
|
||||
|
||||
private ExitStatus exitStatus = new ExitStatus(new org.springframework.batch.core.ExitStatus("UNKNOWN"));
|
||||
|
||||
@@ -94,19 +94,19 @@ public class JobExecutionEvent extends Entity {
|
||||
return this.jobParameters;
|
||||
}
|
||||
|
||||
public Date getEndTime() {
|
||||
public LocalDateTime getEndTime() {
|
||||
return this.endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(Date endTime) {
|
||||
public void setEndTime(LocalDateTime endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public Date getStartTime() {
|
||||
public LocalDateTime getStartTime() {
|
||||
return this.startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(Date startTime) {
|
||||
public void setStartTime(LocalDateTime startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
@@ -197,14 +197,14 @@ public class JobExecutionEvent extends Entity {
|
||||
/**
|
||||
* @return the time when this execution was created.
|
||||
*/
|
||||
public Date getCreateTime() {
|
||||
public LocalDateTime getCreateTime() {
|
||||
return this.createTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param createTime creation time of this execution.
|
||||
*/
|
||||
public void setCreateTime(Date createTime) {
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ public class JobExecutionEvent extends Entity {
|
||||
* JobRepository.
|
||||
* @return Date representing the last time this JobExecution was updated.
|
||||
*/
|
||||
public Date getLastUpdated() {
|
||||
public LocalDateTime getLastUpdated() {
|
||||
return this.lastUpdated;
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ public class JobExecutionEvent extends Entity {
|
||||
* Set the last time this {@link JobExecution} was updated.
|
||||
* @param lastUpdated The date the {@link JobExecution} was updated.
|
||||
*/
|
||||
public void setLastUpdated(Date lastUpdated) {
|
||||
public void setLastUpdated(LocalDateTime lastUpdated) {
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.task.batch.listener.support;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@@ -55,11 +55,11 @@ public class StepExecutionEvent extends Entity {
|
||||
|
||||
private long writeSkipCount = 0;
|
||||
|
||||
private Date startTime = new Date(System.currentTimeMillis());
|
||||
private LocalDateTime startTime = LocalDateTime.now();
|
||||
|
||||
private Date endTime = null;
|
||||
private LocalDateTime endTime = null;
|
||||
|
||||
private Date lastUpdated = null;
|
||||
private LocalDateTime lastUpdated = null;
|
||||
|
||||
private ExecutionContext executionContext = new ExecutionContext();
|
||||
|
||||
@@ -147,7 +147,7 @@ public class StepExecutionEvent extends Entity {
|
||||
* Returns the time that this execution ended.
|
||||
* @return the time that this execution ended
|
||||
*/
|
||||
public Date getEndTime() {
|
||||
public LocalDateTime getEndTime() {
|
||||
return this.endTime;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public class StepExecutionEvent extends Entity {
|
||||
* Sets the time that this execution ended.
|
||||
* @param endTime the time that this execution ended
|
||||
*/
|
||||
public void setEndTime(Date endTime) {
|
||||
public void setEndTime(LocalDateTime endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ public class StepExecutionEvent extends Entity {
|
||||
* Gets the time this execution started.
|
||||
* @return the time this execution started
|
||||
*/
|
||||
public Date getStartTime() {
|
||||
public LocalDateTime getStartTime() {
|
||||
return this.startTime;
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public class StepExecutionEvent extends Entity {
|
||||
* Sets the time this execution started.
|
||||
* @param startTime the time this execution started
|
||||
*/
|
||||
public void setStartTime(Date startTime) {
|
||||
public void setStartTime(LocalDateTime startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
@@ -357,15 +357,15 @@ public class StepExecutionEvent extends Entity {
|
||||
/**
|
||||
* @return the Date representing the last time this execution was persisted.
|
||||
*/
|
||||
public Date getLastUpdated() {
|
||||
public LocalDateTime getLastUpdated() {
|
||||
return this.lastUpdated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the time when the StepExecution was last updated before persisting.
|
||||
* @param lastUpdated the {@link Date} the StepExecution was last updated.
|
||||
* @param lastUpdated the {@link LocalDateTime} the StepExecution was last updated.
|
||||
*/
|
||||
public void setLastUpdated(Date lastUpdated) {
|
||||
public void setLastUpdated(LocalDateTime lastUpdated) {
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.UUID;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -78,6 +79,8 @@ public class EventListenerTests {
|
||||
|
||||
@BeforeEach
|
||||
public void beforeTests() {
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
|
||||
this.applicationContext = new SpringApplicationBuilder()
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(BatchEventsApplication.class))
|
||||
.web(WebApplicationType.NONE).build().run();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.task.batch.listener;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
@@ -217,7 +218,7 @@ public class JobExecutionEventTests {
|
||||
|
||||
@Test
|
||||
public void testGetterSetters() {
|
||||
Date date = new Date();
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
jobExecutionEvent.setLastUpdated(date);
|
||||
assertThat(jobExecutionEvent.getLastUpdated()).isEqualTo(date);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.task.batch.listener;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -124,7 +124,7 @@ public class StepExecutionEventTests {
|
||||
@Test
|
||||
public void testSettersGetters() {
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(getBasicStepExecution());
|
||||
Date date = new Date();
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
stepExecutionEvent.setLastUpdated(date);
|
||||
assertThat(stepExecutionEvent.getLastUpdated()).isEqualTo(date);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user