Skip to content

Commit f7e4089

Browse files
committed
Use Instant for Session creation and last accessed times
Closes gh-10976
1 parent 67e5897 commit f7e4089

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/session/SessionsEndpoint.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.actuate.session;
1818

19+
import java.time.Instant;
1920
import java.util.List;
2021
import java.util.Map;
2122
import java.util.Set;
@@ -101,9 +102,9 @@ public static final class SessionDescriptor {
101102

102103
private final Set<String> attributeNames;
103104

104-
private final long creationTime;
105+
private final Instant creationTime;
105106

106-
private final long lastAccessedTime;
107+
private final Instant lastAccessedTime;
107108

108109
private final long maxInactiveInterval;
109110

@@ -112,8 +113,8 @@ public static final class SessionDescriptor {
112113
public SessionDescriptor(Session session) {
113114
this.id = session.getId();
114115
this.attributeNames = session.getAttributeNames();
115-
this.creationTime = session.getCreationTime().toEpochMilli();
116-
this.lastAccessedTime = session.getLastAccessedTime().toEpochMilli();
116+
this.creationTime = session.getCreationTime();
117+
this.lastAccessedTime = session.getLastAccessedTime();
117118
this.maxInactiveInterval = session.getMaxInactiveInterval().getSeconds();
118119
this.expired = session.isExpired();
119120
}
@@ -126,11 +127,11 @@ public Set<String> getAttributeNames() {
126127
return this.attributeNames;
127128
}
128129

129-
public long getCreationTime() {
130+
public Instant getCreationTime() {
130131
return this.creationTime;
131132
}
132133

133-
public long getLastAccessedTime() {
134+
public Instant getLastAccessedTime() {
134135
return this.lastAccessedTime;
135136
}
136137

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/SessionsEndpointTests.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -57,10 +57,9 @@ public void sessionsForUsername() {
5757
assertThat(result.get(0).getId()).isEqualTo(session.getId());
5858
assertThat(result.get(0).getAttributeNames())
5959
.isEqualTo(session.getAttributeNames());
60-
assertThat(result.get(0).getCreationTime())
61-
.isEqualTo(session.getCreationTime().toEpochMilli());
60+
assertThat(result.get(0).getCreationTime()).isEqualTo(session.getCreationTime());
6261
assertThat(result.get(0).getLastAccessedTime())
63-
.isEqualTo(session.getLastAccessedTime().toEpochMilli());
62+
.isEqualTo(session.getLastAccessedTime());
6463
assertThat(result.get(0).getMaxInactiveInterval())
6564
.isEqualTo(session.getMaxInactiveInterval().getSeconds());
6665
assertThat(result.get(0).isExpired()).isEqualTo(session.isExpired());
@@ -72,10 +71,8 @@ public void getSession() {
7271
SessionDescriptor result = this.endpoint.getSession(session.getId());
7372
assertThat(result.getId()).isEqualTo(session.getId());
7473
assertThat(result.getAttributeNames()).isEqualTo(session.getAttributeNames());
75-
assertThat(result.getCreationTime())
76-
.isEqualTo(session.getCreationTime().toEpochMilli());
77-
assertThat(result.getLastAccessedTime())
78-
.isEqualTo(session.getLastAccessedTime().toEpochMilli());
74+
assertThat(result.getCreationTime()).isEqualTo(session.getCreationTime());
75+
assertThat(result.getLastAccessedTime()).isEqualTo(session.getLastAccessedTime());
7976
assertThat(result.getMaxInactiveInterval())
8077
.isEqualTo(session.getMaxInactiveInterval().getSeconds());
8178
assertThat(result.isExpired()).isEqualTo(session.isExpired());

0 commit comments

Comments
 (0)